Choosing Random Material

How can I (If I can) choose a random material to assign to my Actor Blueprint?

I am making a space game and I want to create a “planet class” that randomly selects a material from several planet textures when I drop it in the level (or eventually automatically spawn it in the level)

I (right now) have a public material variable that I set when I drop it in the level, so I already have a Material Instance set up that’s working - so the last thing to do would be to

“Get all instances of my planet material” and randomly select one :slight_smile:

Any ideas?

I figured it out! I’ll post the solution here in case anyone else reads this :slight_smile:

In my Planet Blueprint I created a variable of type Material and set it to be an array, then I loaded all of my planet materials in the array, then in the construction stript I get a random integer and use that to get an item from the material array, then assing that using a Create Dynamic MaterialInstance node

Piece of cake :slight_smile:

2 Likes

Hi, I am trying to do very similar thing for my game and I can’t seem to find working solution. You mentioned that you figured it out. Are your “planets” made out of landscape and choosing material from array worked for you? I am trying to do same thing with landscape and it doesn’t work for me :frowning:

Sorry it was not a Landscape material - but I don’t see why the idea wouldn’t work for it. I’ll try to play around with Landscape materials and see if I can figure out something

1 Like