How to randomly assign individual new materials to items in an array, within an InstancedStaticMesh

All of my hexes are assigned in an array and I cant figure out how to assign new materials to individual array elements/hexes, The end goal is to make each hex a random material each time you start the game. I’ll post some pictures of the blueprints and what the hexes look like below:

Hexes, these are adjustable, adding and removing items from the array and from the screen

This is the construction script of the hexes, second picture below

I assume I cant do what I’m wanting to do in the construction script, I have tried many things and tried to look it up, but there is very little information on this.

Thanks for any help you can give!

I found some pictures of per instance material (it was done for debugging Instanced meshes, so it changes color only):

Beginning (left side):

Middle of material (ie mixing colors):

End of material (setting up result node):

And property you need to set for instanced meshes, in this case just single Float:

Material mixes colors of based on if statement, or something like case of in C++, all based on float parameter from data channel of meshes. IF you feed/fill that numbers with random values you will get random colors (or materials/textures).

1 Like

I may have worded my problem wrong, I’m sorry if I have.

I’m wanting to access individual hexes to be able to give them ‘values?’ for example I want to be able to have them have a chance to be a resource like forest or wheat field, or no resource.

For the time being I’m wanting to simply be able to change the material of the individual hexes so I can do the resources later.

If there is an easier way to do this, instead of doing the InstancedStaticMesh + array, I’m all ears.

Watch this:

For your map generation i would do this:

  • place all tile changing logic inside blueprint actor.
  • expose some kind of tile id (like [x,y] coordinates (hex is just grid with every other column shifted by 1/2.
  • when you have actor with that index system, you can create array in place like game mode or game instance that keeps type of tiles terrain
  • now each tile reads that array, and sets its own material according to that.

This way you have game logic separated from how tiles should look.

ps. do not bother with instanced static meshes yet (or never) first make prototype of map, then you know what you really need.

1 Like

Thanks for the help! I will try to follow what you’ve said here