Materials on instanced meshes not working

Hi there

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.

Am I missing something here?

Cheers,
Michael

Hey IMX -

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.

Thank You

Eric Ketchum

Hi Eric

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.

Cheers,
Michael

Hi Michael -

So My next question is in the construction graph are you setting a dynamic Material Instance for each of the mesh instances you have created?

-Eric Ketchum

Hi Eric

Nope, this is what I did (in the components view of the blueprint):

  1. Create an InstancedStaticMeshComponent
  2. Assign a mesh to it
  3. Create 3 instances of the mesh (in the details panel of the
    InstancedStaticMeshComponent)
  4. 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.

I did not add any nodes in any of the graphs.

Cheers,
Michael

Hey Michael -

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.

Thank You -

Eric Ketchum

Hey Eric

Ah okay, that’s clear now! I should have known that - I’m working with multiple materials slots all the time…

I assume I just assign the materials to the instances in the construction script then.

Thanks!
Michael

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.

Hey Hyperloop -

No, Instanced Static Meshes are always going to have the properties of the parent mesh and its materials.

Thank You

Eric Ketchum

Hello Eric.

The Instanced Static Mesh has the same Material as the parent mesh, but can it have a scalar parameter changed per instance?

Thank you in advance.

Hey Osok -

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.

Thank You

Eric Ketchum