Download

Setting materials

I am trying to randomly set the material on multiple instances of the same mesh. I have a grid of squares. When I play the level they are blue and red (the two colors I’m using to start) but very quickly change to either all blue or all red. All of the square meshes are loaded into an array and then I am looping through the array and randomly setting the material to either a red one or a blue one. That part seems to be working. Then they just all change to red or to blue. :\

Here’s the blueprint that is setting the material:
https://dl.dropboxusercontent.com/u/103822960/Untitled-2.png

you miss capture the part that actually fired the event that eventually goes to this part you posted.

I’d suspect that something else sets material somewhere else.

The rest of the graph looks almost exactly like the BP for Tappy Chicken (setting up the camera, the save game stuff and the inputs). There is a custom event ‘StartBasicGame’ that’s firing to start off the chain shown in the pic. It hides the menu and then sets the starting X and Y values for the boxes (far left in the pic). This is where I am spawning the actors in the world, setting their location, and their material. It is literally the only place in the project that they are referenced right now. The box mesh itself does not have a material assigned to it (just a slot for one). I have a parameterized box material (white) and two instances of it (a red and a blue) and am assigning the instances.

since it should only be run once on game start, try this and see if it worked as is.
After your forloop on the left end of your cap, insert a print string and print the index(int to string), and after branch on right end of your cap (or after set Material), print string to print red or blue.
This way you know how many of BP_Box actually got spawned, and how many times set material is called.
if the loop doesn’t end, or the sequence of numebrs are wrong, something is off. in console or on screen, it should look like
0
Red
1
Red
2
Blue
…continue…
44
Red

Note that is should just continue roll off screen without new print happening after 44, if it does loop is wrong.
If it doesn’t but material still continue to change to either blue or red, without printing at all, you probably need to check either the box’s event graph or somewhere else.

Thanks for that tip. It stopped at 44 and was going between blue and red like it should, but it looked like it was being called multiple times. So, I looked back at what was calling the event and saw this:

https://dl.dropboxusercontent.com/u/103822960/Untitled-3.png

oops! StartBasicGame was getting called every time the animation on the play button updated. Its working great now.

good old print never fails.