I’m working on a blueprint which heavily relies on instances of static meshes. What I’m currently struggling with is that material overrides that I set in the InstancedStaticMeshComponent do not seem to have any effect (only the material originally assignes is shown). I have assigned a specific material (some materials are also instances) for each instanced mesh.
So you are dynamically creating Static Mesh components in a blueprint, are you then setting their materials? If you can post a screenshot of your Blueprint and I can see how we can help you get this sorted out.
No, the instances are created and placed manually in the component editor. I then set different materials per instance but the materials seem to be ignored. I have attached a screenshot to illustrate.
Nope, this is what I did (in the components view of the blueprint):
Create an InstancedStaticMeshComponent
Assign a mesh to it
Create 3 instances of the mesh (in the details panel of the
InstancedStaticMeshComponent)
Under Rendering-> Materials I added 3 elements and assigned the
materials I wanted to it (also in the details panel of the
InstancedStaticMeshComponent)
That’s all.
My assumption is that the materials I assigned as mentioned above are mapped to the according instances of the mesh.
Sorry for the initial confusion but I understand the problem now. The rendering drop down for the Instanced Static Meshes is not so you can set the material for each instance. The Materials 0, 1, 2, etc. are referring to separate material slots for the same mesh. Here is an example for you, I have a cube in which the top and 2 front faces are separate material slots and you can see in rendering I have the 3 materials set up.
Hi eric, just to clarify: is it even possible to apply different material instances to instanced static mesh components as he is trying to do here? In my exploration, this doesn’t seem to work (the material gets set on all the instances). Just wondering what the expected behavior is.
Unfortunately, no. The reason being that by setting a different scalar value per instance the rendering thread would have to treat the instances (draw call wise) as the same as if they were not instances thus defeating the performance gains by using instances over actual meshes.
The engine does have a perInstanceRandom node in the Material editor which allows a random float value to be passed based on instances. This node is somewhat limited in scope (every time you use the node in a single material each use will return the same value) and while it does incur some performance cost in use because of its limited scope it is still allows the engine to utilize the instance rendering pathways.