Getting reference to a widget created by the Menu Anchor.

a widget created by the menu anchor?

Not sure what that means but storing references to created widgets will allow you to access and manipulate their data. Getting child/parent is fine but requires casting and can be a tad fiddly since you need to know the expected class.

I want to have multiple menus open at
once so I have no way of telling them
which one is which.

If you are instantiating dynamically, instead of storing widget references in an array (just an index) you can store them in a Map with proper names:

In this case, I’ve created 10 widgets, gave them unique names and pushed them into a Map. I then access the one at index 6 and change its slider value.

You can, of course, make do with just an array but then you’ll need to remember indexes. I still use an index here because it’s a silly example. Assigning unique names as map keys can really help you identify and fetch objects faster. Again, depends on the project’s scope.

Spawning my own widgets is not a problem.
I was using “Menu Anchor” element - it is specifically designed to spawn a widget of a given class when triggered (it has some options to make it easier to specify a relative location of the new widget). So I don’t create a widget by hand - I call “Open” on the Menu Anchor and it spawns its “menu class” widget. There is however no way that I can see to access that new widget.

Hello

Is there a way to access a widget created by the menu anchor?
For example, I want to be able to pass some additional data to it after creation.
I can access the class, but not the actual created widget.

Getting child / content / parent doesn’t work.
I know I could use a construct event in the menu blueprint to get the data from a player controller for example, but I want to have multiple menus open at once so I have no way of telling them which one is which.

Thanks.

Forgot that thing existed. Set MenuClass to None and create a widget in the anchor’s binding:

Save it in a reference. This will allow you to access it for as long as it’s valid. The anchor will destroy it when it disappears, though and create a new instance next time.

Variables have an Expose on Spawn flag which will allow you to customise it on creation while the reference can be used to access it afterwards.

1 Like

That worked. Thanks.

In 5.1, is this response still relevant?

Looking in the source code “OnGetUserMenuContentEvent” is not set to BlueprintAssignable, dragging a pin out from an anchor reveals no option to override this delegate:

From Engine/Source/Runtime/UMG/Public/Components/MenuAnchor.h :

	/** Deprecated. Called when the menu content is requested to allow a more customized handling over what to display */
	UE_DEPRECATED(4.26, "Use OnGetUserMenuContentEvent instead, you may need to make the previous binding return an User Widget.")
	UPROPERTY(EditAnywhere, Category = "Events", meta = (DeprecationMessage = "4.26. Use OnGetUserMenuContentEvent instead, you may need to make the previous binding return an User Widget."))
	FGetWidget OnGetMenuContentEvent;

	/** Called when the menu content is requested to allow a more customized handling over what to display */
	UPROPERTY(EditAnywhere, Category="Events")
	FGetUserWidget OnGetUserMenuContentEvent;

image

ooo, thank you!

Actually, I dont have that

This is in a UUserWidget with a UMenuAnchor component:

This is in a UMenuAnchor child blueprint (sorry about the edit, my first screenshot was incorrect):

You need to be in the Widget Designer:

1 Like

Ah, okay. Sorry for the confusion, it works now :slight_smile:

1 Like