x

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"

Change materials to all the elements from an array

alt textHello I’m trying to get some help about this problem: I want to apply different materials to different mesh actors according to which button I click on a screen widget. Finally and thanks to many tutorials I achieved my goal, except for a little inconvenience, in order to change the material I must click many times the same button so the material change takes effect one by one on each of the mesh actors. I think this is because I plugged (widget blueprint) a “random integer in range node” into the get node which in turn is located between the “array variable reference” and the “static mesh target”, so I suppose that this “random integer node” gives a random index number per click, and this number decides to which of the “make array node” (in level blueprint) elements is going to change the material. Could somebody please help me to make the material changes to all elements from the “make array node”?, please, I’m really new to this.

Thanks in advance

Product Version: UE 4.9
Tags:
more ▼

asked Oct 06 '15 at 05:46 PM in Blueprint Scripting

avatar image

Chanito
1 1 2 3

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

1 answer: sort voted first

Hello Chanito,

Have you tried using a ForEach Loop? This would allow you to perform the material change for each element in the array. Have a look at the documentation for the ForEach node and see if it's what you're looking for: https://wiki.unrealengine.com/Blueprint_Essentials_-_12_-_For_Each_Loop

more ▼

answered Oct 06 '15 at 06:00 PM

avatar image

Sean L ♦♦ STAFF
43.5k 485 152 442

avatar image Chanito Oct 06 '15 at 06:24 PM

Thanks for the quick answer.

Yes, I have tried the “for each loop” option before with no good results. Since I’m new to game development may be is because I don`t know how to use the node properly in order to get what I want, but even so I tried an approach like this (attached picture), and the material only changes for the first item in the list of the “make array node”

I`m not using the “get all actors of class” node since the material change is intended to affect to different actors of different classes, because of that I used an array. alt text

avatar image Sean L ♦♦ STAFF Oct 06 '15 at 07:04 PM

The gate and the initial foreach loop are unnecessary. Try adding a foreach loop after each on clicked event, like I have done in the picture below. I was able to get this to work without issue. Let me know how it works out.

alt text

colorchangebp.png (249.3 kB)
avatar image Chanito Oct 06 '15 at 08:27 PM

Is working, thanks so much!

My last doubt is, when compiling the blueprint there are warnings, I think that is because of the “cast to static mesh” node that used, since no “cast to colorchange” seems to be available, so my questions are:

  • Which kind of “cast to” node should I use in order to avoid these warnings?, there are many of them, I used “cast to static mesh” in a sort of a 50/50 shot

  • List item

  • How do I discern between the use of any of the different nodes?, I mean, even when I checked the documentation couldn’t understand at all the use of this node

Thanks again, is working!alt text

avatar image Sean L ♦♦ STAFF Oct 06 '15 at 08:34 PM

Glad to hear that you've got it working now.

  • ColorChange was the name of my actor blueprint (i.e. the actors that I was changing the materials of), so you'll need to cast it to whatever your actor blueprint was called.

  • Assuming you're asking about the use of the casting node, it is just used to check if the object that you are attempting to cast is of the same type as the object that you are casting to. So in my situation, casting the array element to ColorChange was ensuring that that particular element was an instance of my ColorChange blueprint. You can find additional documentation on performing casts here: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CastNodes/index.html

avatar image Chanito Oct 06 '15 at 08:49 PM

Ok sir, I almost got it, but I won't ask about it since I think that experience will be the one that clarifies to me how to get to the same result as yours.

Thanks again

(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