Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text

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.

alt text

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.

alt text

alt text

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?

alt text

Product Version: UE 4.19
more ▼

asked Nov 15 '18 at 10:43 PM in Blueprint Scripting

avatar image

21 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Nov 16 '18 at 08:40 AM

avatar image

1.8k 12 7 8

avatar image BlackMagic89 Nov 16 '18 at 04:12 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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:

alt text

But this is maybe just a workaround?

6.png (71.9 kB)
more ▼

answered Nov 16 '18 at 12:39 PM

avatar image

86 3 5 15

avatar image Tuerer Nov 16 '18 at 12:59 PM

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.

avatar image SebaSopp Nov 16 '18 at 01:39 PM

Good to know, thx for the clear up.

avatar image BlackMagic89 Nov 16 '18 at 04:11 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question