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.
3) 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?
asked Nov 15 '18 at 10:43 PM in Blueprint Scripting
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.
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?
Follow this question
Once you sign in you will be able to subscribe for any updates here