Instanced Static Meshes render with default material
Hey I have a problem with InstancedStaticMesh, the mesh instances are rendered with default material and I can't figure out why
what I did is:
opened a new c++ project just basic code, I've created:
c++ Actor class "Tile", declared UStaticMesh in it, I've created A blueprint from this class and set the static mesh and material, the material is created by me and it has the "Used with Instanced Static Meshes" flag set
c++ Actor class "MyLevel", declared UInstancedStaticMeshComponent, and a TSubclassOf in it, the "TSubclassOf" member is UPROPERTY that can be edited anywhere and it is set to Tile Blueprint that I've created.
In "MyLevel"constructor I create instancedStaticMeshComponent, in BeginPlay() I check if TSubclassOf is set and if I set the InstancedStaticMesh->SetStaticMesh() and just to test I also add instance of that mesh, and now the mesh is rendered but with default material and I have no idea why. Can any one help solving this problem ?
code from MyLevel class
code from Tile class
MyLevel class Settings in Editor https://onedrive.live.com/redir?resid=89D22DBC98E39077!1190&authkey=!ADm8M5Fi8XWCdBg&v=3&ithint=photo%2cpng
and the result on left instanced static mesh with Tile_BP blueprint, on right Tile_BP blueprint dragged and dropped in editor https://onedrive.live.com/redir?resid=89D22DBC98E39077!1189&authkey=!ADUj0WUnAZ328qM&v=3&ithint=photo%2cpng
Can any one tell me why this is happening ?
asked Jun 02 '16 at 08:16 PM in C++ Programming
I've sorted the problem by adding a UMaterialInterface into my Tile class and loading my material in construction script than when I call AddInstance on InstancedStaticMeshComponent and get its index I call SetMaterial() passing in the instance index and the appropriate material
Update: Right now I only have a StaticMeshComponent in my tile class I have made a blueprint from it I set things as shown on pictures in my question but I call SetMaterial() on instancedMeshComponent passing in instance index and material of appropriate index that I get from tile class StaticMeshComponent
Follow this question
Once you sign in you will be able to subscribe for any updates here