How to link static mesh into widget blueprint?

I’ve been trying to use the UMG to change the material of my object via the widget blueprint.
How do i bring my static mesh into it?

Thanks in advance.

You have to include it from somewhere.

My personal recommendation would be to pass it along from your player character or controller when you create the widget.

You have three real options here.

  1. You change the material of an object you’re looking at. For this do a single line trace from your camera forward and check if it hits something of which you want to change the material. If so open the widget and provide the mesh variable when creating it. (For this to work just tick the checkbox “Expose on spawn” after you made the variable editable. The node “Create Widget” will then have a new pin when you select this widget class and you can just plug it in there so it will have the variable on construction).
  2. You change the material of an object near you. For this add a sphere collision to the object or your character and check on begin overlap if it’s the overlap you’re looking for. If so spawn your widget and add this as your variable.
  3. You only have a single object of this in the level and it should always be the same. In this case you can either spawn it from your character and just save a reference to it and provide this when you spawn your widget. or do a “Get All Actors Of Class” and use that.

I hope this helps. If you have any questions feel free to ask them!

Cheers!

Thanks for your reply Erasio. But i think either you misunderstood my question or it’s unclear.
I have setup a widget via UMG so that when i click on the object, a menu will pop up and options will be available for the player to choose from. (in this case, the material)

I have successfully setup the widget and it works perfectly fine but i am unable to select the option to change the material because i am unable to link the object to the blueprint as a reference.

The widget is setup in a different level via widget blueprint. And the object itself has it’s own blueprint and added with a collision box with a on click event. (This works fine.)

The problem lies where I am unable to make a reference of the object (in this case the box that changes color via selection) into the widget blueprint. Therefore the “Unknown” variable in the screenshot.

Eg. (a variable or an option) that states that i want this box to be the object that the color change is applied to.

Wait so your actor has a 3D widget? If it has one as component you should be able to get it via “Get Owner” and cast that to your desired type.

If this is still not what you need I will require more information about what exactly you’re trying to do. Your initial explanation is rather sparse.

Sunny, have you fixed that? Same problem here…

Did you take a look at my answer?

Does that help? Otherwise you might have to explain your specific issue a little more.

(First of all, im new here : ) and im learning hard yet… )

Read your words but my case seems to be more simple:

I have to change materials on a static mesh with a button pressed on viewport “programed” on my widget blueprint.

The Statich Mesh is a blueprintClass, so has its trigger box wich calls the Widget when player collides, All this works ok.

But…

In the widget blueprint;
“EventOnClickedButton” conected to "Set Material Function " Target connect…
i Can`t get the ClassBlueprintStatichMesh variable to connect to.

I guess i didnt enable "expose on spawn" option on the variable Im at work now, i will try that when i get home.

I tried enable “expose on spawn” but did not work.
Nodes since "Onclicked(testcolor_changer) do not work at all.
“Set Material” has no action on the static mesh.

This situation is very simple and i can`t understand what im doing wrong.
Please need some light on this, thanks!

Did you manage to solve this? im trying to do the same thing, with the same problem, that i cant reference to an actor inside the widget blueprint.

Did this ever get resolved? Im having the exact same problem…

Convert the actor to a blueprint class first. Then you create a new variable and search for the blueprint via typing the name.

Sunnyseah,

Im sorry but could you show a sample of this. Im new to Blue Print. I understand what you are saying and have been trying different ways to do this but I cant seem to make it work.

The solution i Found was this. I hope it helps.

Lord Pol,
Thank you for your help. I am unable to connect the Array Element node to the Target of Set material. Here is a picture of my set up, I’m sure there is a better way to do this (noob problems). Is it that my color cycle blueprint is a bit janky? Or should the color cycle logic be in the same blueprint that also has the trigger box that triggers the widget to show up?

If you notice on my blue print that cycles through my material I start it with a “On Clicked” event, because Its the event that starts on the menu widget.

Give the actor a Tag.