How to set Material on Instanced mesh through code?

I have an actor class with an array of UStaticMesh*, and UMaterial*. Then I have an actor class that I spawn and I grab the needed static mesh from this UStaticMesh array, and setStaticMesh of that actor. This works, I can see the correct static mesh spawn. However, if I try to use the array UMaterial and grab the needed material and setMaterial(0, Master->materials.mMs[0]) the material doesn’t show in the editor when this instance spawns. I can see if I select the actor and with it’s HISMC component and look in, that the material is listed correctly, but it only shows default grey material in the viewport. This material is greyed out (I’m guessing because it’s a HIMSC) so I cannot select the material drop down and try others, but I would imagine that setting this material in code and seeing it list correctly in its component that it would display correctly with it in the viewport.

Any ideas?

1 Like

Generally when I apply materials in code it’s done with SetMaterial(mat ID, refMaterial.Object);

However I’m noticing that I’m not able to call the “.object” of a UMaterial when setting from this array. Why is this and do I need to call it that way?

Figured it out. I forgot that I had to set “Use with Instanced static Meshes” in the material setup.

3 Likes