Menu system - return/back button, how to travel to current panels outer?

Suppose you have a menu system something like this:

I made a universal back button, but it works by getting reference to the current UMG widget when traveling to a new widget. This is the “previous menu.”

But this only works for a one-layer menu. If we go two layers deep, then its going to only jump back and forth between layer 1 and 2.

So, without hard coding each menu widgets “outer” (e.g. one layer up in the hierarchy), how can we know which menu to go back to when we press the back button?

I guess the generic way to ask question is this:

How to procedurally determine hierarchy of a modular system?

Here is two methods. It might sound inefficient to store the owner, but it’s potentially a better solution, because it may turn out the the outer is not the original outer, because it may have been reassigned to a different object out from under you. Less likely with widgets but still possible.

You can also specify the type if you set the owner on spawn like shown below, which could potentially avoid a cast if you only need one type of class.

Note: I’m just using UUserWidget because its easy, it could be any widget class. For the first method you should use either a base class all your widgets extend from so they can all call some “GoBack” method.

2 Likes

thanks @Rumzie

your idea makes sense to me, though my final implementation is slightly different (just due to project specifics).

Although I said that I don’t want to hard code, because of the way I set things up there is a pretty easy and efficient way to hard code that I think is a lot less work than setting up a completely modular system.

On the parent menu class I already have an enumerator to ID the widget, which I use for menu navigation. I just added a duplicate and call it “RootMenu”. For most widgets it is the same, and for layer 2 it is jus the options menu root.

The added workload is just that I set a variable on spawn - something I was already doing so its neglible.

I looked a little further into a completely programmatic solution but it’s a ton more work and kind of complicated. In interest of time, I think this simpler method will suffice.

1 Like