How do you set the "Num Custom Data Floats" property when the ISM component has been added dynamically at runtime?

Generally, if you add an ISM component to an actor manually, if you want to use PerInstanceCustomData, you need to set the “Num Custom Data Floats” property from the component’s detail panel in order to use them. i.e. If set to 2, PerInstanceCustomData[0] and PerInstanceCustomData[1] should work, but PerInstanceCustomData[2] would not.

However, how do you set the “Num Custom Data Floats” property when the ISM component has been added dynamically at runtime?

As far as I can tell there is no BP node for setting that. I have tried just assuming/hoping it would just work even without setting it, even though it doesn’t work like that using manually created ISM components.

First, it seemed like I was able to change the custom values just fine using the SetCustomDataValue node. Despite the ISMs being added at runtime with no “Num Custom Data Floats” property set, the material received the values just fine.

Then later, I was making a nearly identical system, but this one was a SceneComponent BP, which added the ISMs to the owner actor and then used them to do pretty much the same thing as the previous actor BP using the same material. Only, now the custom data was no longer working. Everything else seemed to work just fine, but no custom data. The material only receives a 0, always. Just like it does if an ISM component is created manually and the “Num Custom Data Floats” property is not set.

I’m confused as to why the actor BP worked and the component BP did not. I, of course, understand it might be hard to answer that last one unless I go through a longer explanation and share my blueprints, but if anyone can shed light on any of this I’d appreciate it.

May be it’s a bug and the ‘Num custom Data Float’ is not exposed to blueprints, create a C++ class derived from instanced static mesh and create a new variable exposed to BP & Update ‘Num custom Data Float’ with this new variable in constructor. Now use this C++ component instead of instanced static mesh component in your Blueprint logic.

This might also help - Set HISM num custom data floats during runtime - Unreal Engine / Programming & Scripting - Unreal Engine Forums

Without going into C++ I think your best bet is creating a class blueprint (that inherits from the Instanced Static Mesh Component class) and setting the number of custom data floats there. It’s not recommended that you change this number at gameplay time anyway, so that fact that it’s going to be constant should not be a problem.

Also! Don’t forget to use the VertexInterpolator node in your material if you’re planning to use your custom floats in the pixel shader. UE5 seems to not warn you that you’re using bogus nodes in the pixel shader — it just fails silently. Here’s an example.