How to make widget affect last clicked actor?

I’m making a configurator where you can place different kinds of furniture, and if you click the furniture a widget pops up with buttons to change material and color of that actors static mesh. Right now it can only get the first clicked actor though, because I’m using “Get all actors of class” and then I left the index at 0.

So I need something that sets the last clicked actor or mesh and gets that when the buttons are pressed. I just don’t know how to do it because I don’t understand how variables work in relation to actors.

Can you show that part - the way you are clicking on it, how is this done atm?

Sure. I’ve tried two different solutions here, but in both cases only the first clicked actor has its material changed. The variable LastClicked is a mesh that is set after clicking a mesh.

This is not set up right. Do you have a player controller or a pawn that you move around?

A player controller, I think:

PlayerController

  • try this in the furniture actors:

Each Furniture BP has its own widget that sends it a button click making each Furniture BP independent.

  • in the player controller:

The player controller keeps track of who was clicked last so it can ask that Furniture BP to either show / hide their widgets.

This is by no means the ultimate implementation but should get you closer.


Avoid using Get All Actor of Class - this leads nowhere unless you really want to do something to all actors or filter some of them.

Nice. So does the first blueprint create a new widget by itself, or should I make a unique widget for each Furniture BP?

It’s up to you if you want to make it unique. I guess a sofa and a wardrobe may need different widget.

Only you know what you need.

I tried doing this but there are a few things I don’t get.

  1. How do you make a custom event with the variable “show” attached?

  2. What is “New widget blueprint” in this case?

  3. What is button 42 in this case? I mean, the buttons are called from the widget blueprint. I don’t see why you need to do anything with them here, except for the left mouse button that is used to show the widget.

  4. When I try to attach the “OnClickedEvent_0” to the BindEvent node it tells me that "Delegate is not compatible with delegate(by ref).

You can create Custom Events by right clicking anywhere in the graph and searching for it:

image

Once the node is selected, it can be renamed and new inputs added:

image

What is “New widget blueprint” in this case?

It’s the class of the widget that we are showing. You probably have a better name for this. Configuration Widget I presume. It’s the widget that shows how this piece of furniture can be modified.

What is button 42 in this case? I mean, the buttons are called from the widget blueprint. I don’t see why you need to do anything with them here, except for the left mouse button that is used to show the widget.

Button 42 is an example of pressing a button in widget and triggering an execution in the actor that owns it. You were doing this:

Which will never work if you have more than 1 object. In my example, each furniture BP has its own widget and pressing its button tells the furniture BP that something was clicked. So we can easily change the material directly in the actor:

Whenever button 42 is pressed in the widget, the custom event executes in the actor. Here you have access to all the meshes.

When I try to attach the “OnClickedEvent_0” to the BindEvent node it tells me that "Delegate is not compatible with delegate(by ref).

Signatures must match. You can automate this process by using assign:

1 Like