Make all other floating widget minimize when one widget is activated/expanded

UE 5.0.3 - Built on VRTemplate

I have many floating/3D widget and I want the following interaction to happen.
Widgets are either minimized or expanded. Both are visible to the player.

With one widget already expanded,
When I expand another collapsed widget,
Then the currently expanded widget will collapse and the newly selected will expand.
This cannot be a one-to-one relationship as there are many widgets (around 20 widgets) that I can interact with the same way.

I attempted this using event dispatchers. I was unsuccessful as…I dont know how Casting works :confused: all the examples and tutorials ive seen always cast to BP_First or ThirdPerson. This is made more confusing since I’m working in VRTemplate.

Here’s what I’ve rigged up so far:
Call from Widget #1 FlareTip (is an Actor Blueprint that consists of mostly Widget Components/UI elements)

Bind to Widget #2 Drone_Main (is an Actor Blueprint very similar to Widget #1)

At the moment I can’t even make the event dispatcher work/trigger to print text.

Additionally, it seems like even dispatchers are tedious to expand to many widgets.
Are there alternatives to this method?

  • how many widgets can be expanded at the same time?
  • are all those widgets of the same class
  • by expanded do you mean Visible
  • what is the actual difference between expanded and not expanded, part of the hierarchy is collapsed, that’s it?
  • Only ONE can be expanded
  • Im not sure what is meant by class. The floating widget (which have already made) is simply made of a few UserWidget Blueprint (up to 3, one is to represent the content, another that is always visible which is the ExpandButton, and an additional miscellaneous depending on what the widget is showing) represented in an Actor Blueprint that is placed in the world.
  • Yes by expanded I mean visible.
  • So the expand button within a widget is always visible, and it simply sets the content of the widget to visible

Hope that clarifies things!

Cheers; not 100% sure how the internal bits of your widgets work so I had to improvise a wee bit:

  • the widget:

image

  • clicking a button collapses the Vertical Box with the content:

While we do not really need an event dispatcher for this, we might as well use it because it’s great practice. I am dispatching the expansion of the widget to the Player Controller - we need an actor that oversees the process and can recall which widget was expanded last.

  • in the Player Controller:

Hopefully you can adapt the logic to your needs.


There is always a Widget Switcher which, kind of, does the same thing - but I was under the impression you needed something more elaborate or controllable.

Good luck!

1 Like

And finally, here something somewhat related, where only a single element out of many is kept active:

Thank you so much! Im giving this a try now.
Conceptually I think this is on track with what I’ve described so that’s great!
I initially gave this a shot thinking I understood it but as I was adapting this I got more and more confused.

I think I understand the code within wExpandable. Ill be adapting that into a Widget But I’m still confused on the implementation.
Since I have many individual floating widgets that is an Actor Blueprint (that has a Widget Class=Widget Blueprint I made), do I create only one ED in any one of the widgets I make…and…bind/call to and fro other widgets? or a unique ED for each widget?

For MyPlayerController, Im not sure how MyPlayerController plays a role in this. Is it somehow related to the VRPawn for the VRTemplate?

  • What BP is MyPlayerController? Is it also a Widget Blueprint? or Actor Blueprint that the is a parent of one of the Widget Blueprints?
  • Is “Currently Expanded Widget” a…Variable-Actor Object Reference?
  • How did you create WidgetHasBeenExpanded Custom Event with a Blue Variable as the output (Currently Expanded Widget for this example)?

A Player Controller is an actor that is created automatically and acts as the will of the user. It’s responsible for processing input and controlling pawns (and much more). There’s the entire concept of framework which you can read about here:

As mentioned above, we need an overseeing actor to remember which widget was clicked last last so we can collapse it when a new one opens. I replaced the default PC with my own to act as that overseeing actor. You do not need to use a Player Controller, you could utilise Game Mode, a Pawn (you do have a VR pawn, right?) or even a regular actor instead but then, in the last case, the communication will be a tad more difficult.

Is “Currently Expanded Widget” a…Variable-Actor Object Reference?

It’s a variable referencing a widget, yes. When a widget is created or interacted with we can store a reference, so we can talk to that widget later. Imagine you have a dozen widgets but only want to talk to a very specific one. If we specify which one we mean by setting the value of such reference variable and that widget still exists, we can.

How did you create WidgetHasBeenExpanded Custom Event with a Blue Variable as the output (Currently Expanded Widget for this example)?

The same way you did here:

image

Right click in the graph, add a Custom Event and add any data pins you may need:

When you call this event later on, you get the chance to pipe in the data of the desired type. That’s one way to propagate information between actors / widgets. In the example I posted earlier on, I send the reference variable of the widget that was clicked to the Player Controller.

In short: the widget tells the player controller - I've been clicked on and expanded with the blue pin being the who. It’s done through an Event Dispatcher.

1 Like

Hello. Thank you for the advice thus far. I’ve given this a few go and am still unsuccessful.

Here’s a list of questions I have:

  • In MyPlayerController, how are CurrentlyExpandedWidget and NewExpanded variables being communicated to the Widgets? I don’t see how it is referenced to all the widgets.
    You mentioned the following:

How do I set the value of such reference?
I see a Default Value option below but its greyed out and Im unsure how this can be expanded to multiple Widgets.

  • Inside wExpandable→CreateEvent Node, I am unable to search for “WidgetHasBeenExpanded(NewWidgetExpanded)”.


    I created the custom event WidgetHasBeenExpanded inside of VRPawn and hit Compile with no errors.
    I’ve never done this before and Im assuming that is how you trigger the WidgetHasBeenExpanded event in MyPlayerController from any Widget? Is that correct? I hope im getting the idea right, I havent gotten the code working so Im not entirely sure but it seems really cool hahaha

  • What is the difference between Event On Initialized and Event BeginPlay? I couldn’t find any reading material on this - Events | Unreal Engine Documentation

Hope to hear from you soon, thanks!

It’s not all widgets, we do not care about all of them since only one can be expanded at a time. The controller holds a reference to the last widget that was expanded, no need to bother them all.

How do I set the value of such reference?

Right here:

VRPawn and hit Compile with no errors:

A pawn is not a controller, you’re casting to the wrong class:

image

If you want to use a Pawn instead of the Player Controller, Get Player Pawn → Cast to VRPawn

What is the difference between Event On Initialized and Event BeginPlay?

Begin Play is for Actors, Event On Initialised is for widgets - they do not have Begin Play. There’s more to it, actually - when widgets come to play, their construction can (and often will) trigger multiple times as they are being laid out. Event On Initialised assures a single execution only. This becomes important when widgets are moved from a container to a container. Not really important here but we want to bind only once.

The tooltips can be quite descriptive:

And, oftentimes, save you a trip to the docs.

1 Like

Hola! Thanks for the quick reply!

I tried swapping Get Player Controller with Get Player Pawn but I’m receiving the error below.


Ill be honest I think I’ve been confused on the fundamentals of VR Pawn and Controllers VS FPS and Third-Person Pawns and Controllers. What is the default equivalent of Player Controller for VR?..or was I suppose to make my own Player Controller Blueprint for VR? :sweat_smile:

I think I’m beginning to understand the flow you’ve made. Thanks for that and the tip regarding the tooltip.

It’s probably signature mismatch. You could create a matching event / function from the dropdown and hook the logic there. Then all the necessary pins are created automatically and with correct type to boot.

This looks like a wrong variable type:

And should be type the widget is of - so probably this:

image

Also the reason why you couldn’t connect the nodes and tried a sneaky cast here:

Which is not necessary once things are set up correctly.


Essentially, the widget is dispatching a self reference to the Pawn, so the Pawn’s event and reference variables must match that variable type. And the entire signature of the event / function must be identical.

1 Like

Hey hey, I have changed the Actor to

Editor Utility Widget - Object Reference, still the same issue for the Create Event node signature. When I first tried it I remember seeing more options in the dropdown for Create Event like…TeleportTrace if I remember correctly. But I haven’t been able to see any options since. Not sure what I did.

When I use [Create a matching event]), a Custom Event node is created within the Widget Blueprint. After hitting compile, the error “Create Event Signature Error: Unable to find the selected function/event: ‘CustomEvent_0’ - has it been deleted?” still appears.
Using [None] shows the same error but with “…selected function/event: ‘None’ - has it…” instead.

Is there any sort of troubling shooting I can do? Perhaps a surefire way to test that Create Event should work? I looked for tutorials and resources for Create Event node but…I couldn’t find any at all :frowning: .
Let me know if you need other information. I’m still trying to experiment with other methods but don’t seem to get it working either.

I feel you’re not following the steps carefully enough:

  • in the VR Pawn:

image

Make sure you have the correct Variable Type (please post the screenshot of this on your end)

  • in the widget:

Again, ensure you’re using the same type and:

1 Like

Hey mate! I was on a hiatus working on other parts as I couldnt get this working but I’m giving it another go now.

I followed the instructions in your previous post and I got that bit alright now. Thanks!!

  1. For this part here, how did you connect Currently Expanded Widget to the Collapse function?
    Yours:

    Mine:

    VRPawn is a Pawn, WA_Solar01 is an Actor.
    Ive set Currently Expanded Widget and New Expanded Widget as Actors


    What is the input for Collapse expecting?

For further clarity, I have my Collapse function within the Actor (aka Floating Widget)


And my Collapse function in a library that is used by ALL the Floating Widget Actors

  1. On the same note, within the VRPawn, the Collapse function seems to activate Collapse function for 1 BP (in your case its W Expandable), but how would this work if there are many different unique BPs?

Ive set Currently Expanded Widget and New Expanded Widget as Actors

It yet again boils down to the very same thing as last time. You should not be using Actor as type but use the widget type.

Above, all of this is of the same type - the type of the widget you’re using, yet your variable is still set to Actor:

Same here:


Avoid plopping nodes down unless you’re 100% certain it will work, use the context sensitive nature of blueprint wires to:

Also, if you’re unsure how to create variables of the correct type, promote - any data pin can be right click and promoted:

image

Thanks for the advice,
Sorry that I’m not getting it right, I suppose Im getting some fundamentals wrong…

I created a new Actor+Widget, this time with all the widget stuff in one User Widget BP instead of one User Widget BP for the content, one for the Expand Button, etc.

In VRPawn
Ive changed New Expanded Widget and Currently Expanded Widget back to User Widget Variable Type, but dragging from Branch node or Currently Expanded Widget still does not show Collapse event in the context menu.



Any idea what’s wrong?
FloatingWidgets_CollapseExpand.rar (171.3 KB)

The variables and pins have incorrect type. If you’re going to roll with user widget then you’ll need to cast.

What is the class of the widget? The widget that expands? Set the pins and variables and the dispatcher to that type. Everything will connect and there will be no need to cast.

Have a look at my original exmaple:

You want to use that. On the pins and for the variables.


Why is there even a function library - do you need it for something else?

I created a new Actor+Widget

?

1 Like

Oh I see now! Got it! I still have to build and test the remaining logic but at least this part doesn’t give me an error for the time being. Thank you so so much!

I started dabbling function library late last week and used it to clean up my code. A lot of the other unique Widgets use the same collapse logic so I used them there.

And as for the new Actor+Widget, previously I had a few separate User Widgets(one just for the expand button, one for just the content, etc) inside 1 Actor BP for each Floating Widget that I created. But now the new Floating Widget would have only 1 User Widget inside of 1 Actor BP that I would place inside the world.

I will work on the rest of the logic now, thanks!

1 Like