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"

Changing the Materials using UMG Buttons

Hi,

I am new to game development and Unreal Engine 4. I am using version 4.6.1

I am trying to change the materials using UMG for some days but still I couldnt find proper tutorials or blueprints.

So I just created a Widget with Buttons like shown in the image. (I created 5 buttons namely Color1, Color2, Color3, Color4 and Color5). If I OnClick any button, the material should change accordingly.

I have also shown Level Blueprint to show the Widget.

Can somebody please help me to find the solution for this issue.

Any blueprint or tutorial might help.

Thanks in advance!

Widget Design

Level Blueprint

When Playing

Product Version: Not Selected
Tags:
widget.png (148.6 kB)
level blueprint.png (225.5 kB)
when playing.png (439.8 kB)
more ▼

asked Feb 08 '15 at 02:32 PM in Using UE4

avatar image

purmo037
30 10 13 20

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

3 answers: sort voted first

The Shape_Cone is a StaticMeshActor, I would create a StaticMeshActor variable in the UMG widget, and pass the Shape_Cone as a reference.

Then you can bind each button's OnClick event to change the material on that Shape_Cone reference to the appropriate Material using the Set Material node.

Hope it helps :)

more ▼

answered Feb 09 '15 at 11:31 PM

avatar image

Justin.Dooley
2.1k 104 74 163

avatar image purmo037 Feb 10 '15 at 02:12 PM

Hi, Can you check whether I have done is right or wrong?

Widget Blueprint I have created StaticMeshActor variable and named it as Shape_cone. I passed that as an object to Actor blueprint and called an event "Update Material".

Actor Blueprint When "Update Material" event is called, change the staticmeshactor (i.e Cone_Shape) to the respective material.

But still I didnt get output. Just for clarification. Thanks!

Widget blueprint for 1st button onclicked

Actor blueprint

avatar image Justin.Dooley Feb 10 '15 at 06:00 PM

You're on the right track!

I've created a simple widget to demonstrate the concept I was mentioning, this widget has 2 simple buttons, I labeled them M1 and M2. M1 will set the material banana bark to the cone, M2 will set banana leaf to the cone. As well as a variable that holds my cone reference.

Step 1

When I add the widget to the viewport, I pass it my cone reference.

Step 2

In my widget I will add the onClicked event for my buttons, each button will be responsible for another material.

Action

As you can see, when I click the cone, it brings up the widget, then clicking the buttons will change the material accordingly!

Hope it helps! :)

step1.png (138.6 kB)
step2.png (181.9 kB)
example.gif (1.7 MB)
avatar image dpham81 Mar 13 '15 at 08:47 PM

Thank you so much for this Justin. I've been trying to figure this out for the longest time. It still took me some time to learn about how you even got some of those things on the blue print like the widget variable, but eventually I figured it out and set it up the way you demonstrated.

avatar image Excalith Apr 23 '15 at 04:50 PM

Hello Justin, Thank you so much for your time! I am having trouble implementing your BP to my project where I want a similar interaction. Shortly, when I fire 'E' key, UMG menu pops up and there are several color buttons for material changing. As you did above, I set my Static Mesh Actor to a public variable called My Wall, and 'GET' it in UMG. In UMG, My Wall variable comes with an empty Target node slot, and converts it to Static Mesh Component before plugging into Set Material Target, therefore gives an error while compiling, telling me Target must have a connection. What am I doing wrong? Any ideas?

avatar image Justin.Dooley Apr 24 '15 at 03:50 PM

You can't SetMaterial on nothing, that's why it's asking for a Target. Provide it your Static Mesh Actor as the target and it will be fine.

avatar image Excalith Apr 24 '15 at 03:53 PM

Thanks Justin! I figured out I was getting the wrong variable (testing different logics made it confusing heheh) that is why it didn't recognize it. It works perfect now, thanks to you :)

avatar image purmo037 Feb 10 '15 at 07:42 PM

Hi,

Thank you so much. It works!

avatar image purmo037 Feb 20 '15 at 03:12 PM

Hi,

How would I do the same thing for more than 3 Actors? For example

Case1: With 3 Cones

Case2: 1 Cone, 1 Cylinder and 1 pipe

I have to do the same thing for more than 7 objects. So if I copy the same blueprint for the rest, it would be more messy. I know very well that I need to do it using forloop or using switch statement. But I am not sure how? Can someone please help me to solve this issue?

Thanks in advance!

avatar image Justin.Dooley Feb 20 '15 at 04:33 PM

If you don't know how to use a blueprint for loop then I suggest you take a quick look at the flow control documentation.

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html#forloop

Use it with the Get all actors of class method.

https://docs.unrealengine.com/latest/INT/BlueprintAPI/Utilities/GetAllActorsOfClass/index.html

avatar image purmo037 Feb 25 '15 at 03:12 PM

Hi,

I am trying to do the same thing using Actor blueprint (not level blueprint) but I am not getting the material changed. I dont know where I am wrong.

Actor blueprint

Widget blueprint

avatar image Justin.Dooley Feb 25 '15 at 10:38 PM

The problem is ... you are not setting the cone to anything. You're grabbing the cone of the widget and setting it to itself. When you do "Set Cone", the cone has to be a reference to the object.

avatar image purmo037 Feb 26 '15 at 12:37 PM

Okay. I understood the problem now. But one more problem is that, the StaticMesh1 (Shape_Cone) is the StaticMeshComponent in which I set its category as an Actor. When I tried to give as an object reference to Cone, its not accepting. Hence its displaying "The type of StaticMesh1 is not compatible with Cone".

avatar image purmo037 Feb 26 '15 at 12:59 PM

Since I think Cone is a "StaticMeshActor", I tried by creating a new variable type "StaticMeshActor" and given as an object reference to Cone, but its not working.

avatar image Justin.Dooley Feb 26 '15 at 05:06 PM

I don't really understand where you got confused.

It's pretty straight forward, you need to pass it the static mesh actor as a reference when you're making the widget.

I made a blueprint out of a static mesh actor and used the shape_cone as the static mesh. In the blueprint I am using the event for the OnClick in order to add my widget to the screen.

Graph

As you can see, this is pretty much identical to the previous answer I gave you for the level script, because it's the same script, the only thing that would need modification is ... what you're passing to the widget as your static mesh actor.

Adjustment

I made a slight adjustment to the widget function so that it gets removed whenever I choose a material (that way if I have multiple cones I don't keep popping widgets on top of widgets).

Cones

I can drag out as many of my cone blueprints as I want.

Change

Each one is responsible for his own material change.

As you can see, the answer I provided originally is the same answer I'm giving you now, the only thing I changed was the reference that goes into "Cone". Which is what I suggested you should do.

I'm sorry if my explanation was not clear enough.

step4.png (136.9 kB)
step5.png (173.2 kB)
step3.png (552.9 kB)
step6.png (555.9 kB)
avatar image purmo037 Feb 26 '15 at 05:35 PM

No worries :) I can mostly understand your way that you explain.

Can I know what is that self in step4.png? How you have passed that to cone (Static Mesh Actor) Reference?

avatar image Justin.Dooley Feb 26 '15 at 05:49 PM

Create a blueprint, when it asks what class, choose Static Mesh Actor, the blueprint is now a child of Static Mesh Actor.

So you can pass it "self" because it is a Static Mesh Actor.

avatar image purmo037 Feb 26 '15 at 06:12 PM

Thank you so much once again!

avatar image Unakain Nov 10 '15 at 02:01 PM

alt text

who can help me about that? i can not connect them :((((

avatar image Teapot Creation Jan 18 '16 at 03:33 PM

Hi Justin,

I'm actually trying to use the same system you described. However I'm stuck : I use a blueprint made out of a static mesh actor (cube). Here I made my blueprint with a Widget variable, create the widget, set the Static Mesh Component as an Object variable (named cucube), then add the widget to viewport. However I'm working on the 4.10.2 version, and I can't find why your Set Cone node has a target slot (mine doesn't). Is that due to the older version used ?

Also despite all your explanations, I didn't understand how you linked your "Cone" variable on the widget with the one set on the Static Mesh Component Widget ? When I try to link "cucube" in the target slot of the Set Material node, it asks for another Target for this variable.

alt text alt text

In my complete setup, I'm using a HUD. Is the widget creation useful in my case ?

Thanks a lot !

avatar image Justin.Dooley Jan 18 '16 at 03:48 PM

Hi Teapot.

The cone variable is in the spawned widget not in the cube blueprint. Drag a pin out from the create widget pin and use the set cube function. the target will be your spawned blueprint and the cone (or in your case cube) will be self (since the blueprint is made from the cube)

avatar image Teapot Creation Jan 18 '16 at 07:23 PM

Damn', I think I've missed something.

By now, tell me if I'm right : in the cube blueprint, I create the widget and define the widget variable to work with. Here I have to set the static mesh as an object reference, since I can't make a reference in another blueprint for this cube (only the level blueprint but I don't use here). But in the spawned widget, I have to use the variable (object reference)...

Where am I wrong ? I'm lost x) Thanks !

avatar image Teapot Creation Jan 19 '16 at 08:57 AM

Hi, it's finally OK. The last hours of the day weren't the best to try this :) This morning I succeeded fast in making it work. Thanks again !

avatar image purmo037 Feb 27 '15 at 02:04 PM

I am getting the error message like below: Can I know how to avoid this error? because I am doing the same process in 3 levels. After changing the materials in one level and when I tried to change the level, the editor crashes.

Error Message

Crash Report

Cone Blueprint

Level Changing Widget

avatar image Justin.Dooley Feb 27 '15 at 04:27 PM

seems like a completely different problem. I suggest you start a new topic for it.

avatar image purmo037 Mar 02 '15 at 01:55 PM

I have posted a new topic about this and got an answer. The problem is that this solution works in Unreal editor 4.7 but not in 4.6. But anyways thanks.

avatar image Justin.Dooley Mar 02 '15 at 07:19 PM

The concept I've given you above works in 4.7 the same as in 4.6. I went into a blank 4.6 project and re-created it using the steps I mentioned, still works.

cone

widget

result

The technique works in 4.6 the same as in 4.7

foursix1.png (143.3 kB)
foursix2.png (170.3 kB)
foursix3.png (268.3 kB)
avatar image purmo037 Mar 03 '15 at 02:38 PM

Sorry that I didnt explain you fully in detail. It works in editor 4.6 but the problem is that I have 3 level buttons (Level1, Level2 and Level3) and 3 cones which will display when the game begins (i.e when EventBeginPlay). In all the 3 levels, I am doing the same thing. If I am in Level1, I have 3 cones. If I click on any cone, the M1 and M2 button will display to change the material for the cones. After changing the materials in Level1, when I click the button Level2, it should go to another level. But instead it crashes and closes the editor.

But this problem is not there in editor 4.7

I have attached an output window here to understand: output window

output window.png (943.2 kB)
avatar image purmo037 Mar 06 '15 at 01:02 PM

This blueprint solved the issue. Anyways thanks!

Levelling Widget

levellingwidget.png (194.7 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Fake Widget Button:

alt text

"Bind" in the bottom right> This is how I would set a variable in BP from Bind:

alt text

So you could set a texture in the Mesh via this method.

Narg

capture.jpg (68.2 kB)
capture.jpg (44.8 kB)
more ▼

answered Feb 10 '15 at 02:24 PM

avatar image

Narghile
1.7k 74 38 110

avatar image purmo037 Feb 10 '15 at 03:07 PM

When I bind for a button, the buttton is not working during runtime.

You have shown binding for Text Block?

avatar image ederoliveira20 Jun 10 '15 at 09:01 AM

Hi there, I'm with a related problem, but I'm not using UMG, I'm trying to do this: I created an actor that when I click on it, it changes it's color, but what I want to do and I'm having problem is, when this happens, I want to set a material for another class that spawns at my will. Please help, I'm new to unreal

avatar image Unakain Nov 10 '15 at 02:07 PM

alt text

who can help me about that? i can not connect them.. :(((

mesh.png (297.0 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

please video tutorial

more ▼

answered Mar 25 '16 at 11:55 AM

avatar image

guvenguner
1

(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