Array to change materials

So I am currently trying to prototype a project and decided to use an array for my needs. I have never used arrays too much so alot of what i am doing is trial and error. Basically I want to press a key (such as F) and then change the material on a cube, but I might want this to also affect multiple cubes.

So what I did was:

  1. Make a cube BP actor

  2. In that BP I created a function to make the current material instance on the cube, a dynamic material. I turned that dynamic material into a variable.

  1. I then made an array with the variable type set to vector parameter value. It has 4 elements inside of it, they are the colors white, red, yellow, and blue. They are in that order in the array from 0-3. So when the F key is pressed the cubes material will change to the selected value, based on the array index. The “color index” is an editable variable, that way if i put 3 cubes in a area i can change the index to any number i need it to be.

The problem is that when there are multiple cubes in the level, only the recently added cube will change its material. Here are screenshots of a single cube in the level working fine no matter which color index is set.

Now here is a screenshot of the same cube along with a new cube. The left one should turn blue like it did, but the right one should be yellow. However, it wont change the material. Any ideas why this is happening?

I believe it happens because you have your F function in the cube BP’s, so only one cube reacts to the key press and “consumes” it. If you want to affect all the cubes, you should create the key press function in your level BP or maybe character BP with references to the cubes.


I hope you get what I’m trying to say.

Good to know, thx for the clear up.

This is really a strange problem…
First I thought the “Enable Input” node would help in the cube BP’s… but no.
Working with Input Actions isn’t also helping…

You can create a custom event in your cube BP’s like “changecolor”.
Then in your Level BP you can search for Actors of your Class type and do something like this:

But this is maybe just a workaround?

No, you don’t use input in actors as a rule, since there may be lots of them in one level. Having input in level bp or character bp is normal practice.

Custom functions are what you need. Even better, you can use interfaces to avoid casting whenever possible.

Thank you SebaSopp for you response. I didn’t try it the exact way that you did, but when I started having the problem, I thought a foreach would help.

Thank you for the response Tuerer. I am going to give this a try and let you know what happens. I understood what you meant, I actually didn’t know that inputs should not go into an actors bp.