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 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)
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
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.
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.
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:
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.
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.
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
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.
A pawn is not a controller, youâre casting to the wrong class:
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.
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?
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.
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.
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 .
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.
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?
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.
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.
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.