How to stop actions of other blueprints and widgets when another blueprint is activated?

Hello, I have been going crazy trying to figure this out, but I can’t seem to get it to work the way I want it to. I hope someone can help me.

I have a set of beds in my level. When I click on a bed, a pillow and a widget appear above the bed. When I click on the same bed again, the pillow and widget disappear. Or if I’m clicked on a bed, then click on one of the other beds, the first pillow and widget disappear, and then another pillow and widget appear on the bed that I just clicked on.

I’ve managed to get everything to work except for when I click on bed 1, then I click on bed 2, the first pillow and widget stay. So I’m left with both beds showing a widget and a pillow. The pillow and widget only disappear when I click on their corresponding beds a second time.

Please, please, please, can someone help? I am still learning Unreal Engine and there are still things I can’t figure out even after googling.

Thank you.

If I understood correctly, when you click on a bed you want the ui of the other beds to close. This really depends on how you’ve set up this system. But the very simple way (not the most optimized) is when you click on a bed → loop over all of the beds in your scene and close their UI -make sure to skip the one you are clicking on. Hope this gave you some sort of a lead.

Thanks for the response. Is there a way to do it within the above blueprint?

In case it’s not clear from the above screenshot:

I have a blueprint that includes the two static meshes, a bed and a pillow. The pillow’s visibility is unchecked. This blueprint is within my level.

In the event graph, I have it set so when I click on the bed, the visibility of the pillow is toggled on, and a widget is also turned on. When I click on the bed again, the pillow and the widget disappear.

So I am planning to make copies of that blueprint and swapping out the static meshes for the other beds and other pillows and each bed will have its own widget.

Here is something I quickly made by your Blueprint.
I called my Actor Blueprint “BP_Bed” and created a custom event “Remove Bed Widget” that simply removes the bed widget if it’s up. In the For Loop I do a “!= to self” to make sure that when you click on a bed it only closes the UI of the other beds.

If you want an alternative: Have a separate class handle the state of the pillow / widget. Have this class bound to OnClicked of each bed so that it can handle the state of the pillow / widget. On Clicked returns a pointer of the clicked actor.

This way you can have one actor with the pillow / widget per bed group and move it around rather than spawning new ones. You can also have groups of beds handled by different managers and even change the # of active beds you can have at a time.

I thank both of you for taking the time to respond to my post. As I mentioned, I’m quite new to all of this so I am trying my best to follow along, but unfortunately I feel like I’m getting lost.

@Sntfon100 I feel like I followed along as best as I could but now I my widget no longer turns off when I click, and the “pillow” meshes are only become invisible again once I click on their respective beds like as I first mentioned. I’ve attached a screenshot:

@pezzott1 I’m afraid I am unable to follow along with what you’re saying. Not because you weren’t clear, but because of my limit Blueprint experience. :frowning:

Also if it’s easier, I could put all of the beds in one Blueprint. They don’t need to have their own blueprint.

The “Get All Actros Of Class” output “Out Actors” needs to be connected to the “For Each Loop” input “Array”. This will basically loop over all of the beds in your scene.

It seems I forgot about the pillow part so my apologies. Try creating another custom event, name it “Set Pillow Visibility” with a Boolean input. Call this event after you add the widget to your viewport and between the “Get All Actors Of Class” and set the input to true (this will show the pillow of the bed you are clicking on).
Call this aswell in the for loop right after “Remove Widget” and set the input to false (this will hide the pillow of the other beds).
Lastly call this event on “Flip Flop B” or “Branch True” right after “Remove Widget” and set the input to false (this will hide the pillow of the bed you click on the second time).

I would also suggest not using a FlipFlop but rather a boolean and a branch to check whether the clicked bed is active, FlipFlops can be a bit annoying to work with in certain cases.
Screenshot_21

Thanks for the reply @Sntfon100 I am unable to get the remove widget and set pillow visibility targets to connect to the array element of the For Each Loop. It says “Self Object Reference is not compatible with…”

I also noticed that the arrow for your For Each Loop icon is going in the opposite direction as mine. Could this be the reason? Is there a different For Each Loop node or a something in details that i need to tick?

Made this sample project to illustrate my suggestion:
ToggleClick_UE5_2_1.zip (71.6 KB)

We do use the same For Each Loop, its just that the code I created is in UE4 so I guess the icons have changed from 4 to 5. Anyways don’t worry about that.

About the connecting issue you are having, you simply need to drag a line from the For Each Loop “Array Element” and then call those events.

I have to head to the store right now, I’m sure I did drag a line from the array element, but I will check that when I get I get back.

I just made this really quick, I hope this will better illustrate what I want to accomplish.

the meshes don’t need to be in separate BPs if that makes less sense than having them together in the same BP.

I assumed you only have 1 Bedroom/Bed Blueprint, but I see you have “Bedroom 01 Nightstand 3”, “Bedroom 01 Nightstand 1” and possibly more. There are alot of details missing here so I won’t be able to help any further, you should try my approach with only 1 Bedroom Blueprint and then try to modify it to your needs (I would also suggest looking into inheritance). Best of luck.

No worries, I understand. Thanks for trying :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.