How to create menu programmatically at runtime?

I want to create a VR menu at runtime using a program.

Take a look at this quick mock-up:
menu

I put a folder puzzles in my project’s Content directory.
Each puzzle is in a sub-folder organized size.

I need to build the menu from the available sizes.
I also need to fill in the solved count by the saved game data.

I have found plenty of guides on how to create a menu by hand, but nothing to show how to do it from a program.

I think I have a handle on using saved game data and I figured out the FPlatformFileManager so I think I have the back-end pieces I will need.

Can someone point me in the right direction for creating the user interface piece?

The easiest way to do this is to create a base menu widget, add scroll boxes for the layout you want, and have a separate class to handle the actual display (ie the 3x3x4 Puzzles [Solved 7/50]).

What you do at runtime is construct however many of that separate class you want, give them the data they need or at least a way to get that data, and populate your scroll boxes with those constructed widgets (you do this by adding the widget as a child to the scroll box- make sure the scroll boxes have “Is a variable” checked).

1 Like

Thank you for pointing me in the right direction. I am new to Unreal Engine so I will start investigating it. Thank you!

1 Like

I assume this means I need to create a C++ class which extends Button.

Next, I have a class that extends UGameInstanceSubsystem so I can override the Initialize function. That is where I will create all the instances and populate the menu.

Not necessarily. I’d highly recommend avoiding C++ when it comes to UI.
UI is extremely visual- having to recompile every time you want to make a slight change is bound to be a pain.

I recommend just creating a new widget that HAS a button, rather than is one.
Extending from button isn’t supported in blueprint.

I’d suggest the menu populates itself- no need to get external objects involved. You’ll want to create the puzzles outside the UI, but the UI itself should be made by the UI.
To get a visual representation in the editor, you can use the pre-construct event to create the UI using placeholder data.

Agreed. I am finding the edit/compile/test/repeat cycle is taking a bit of time when doing things in C++.

Got it, I will try that.

I like that suggestion, will work on it.

Thanks again for your help on this!

1 Like

I created a Widget called MainMenuButton which has a Canvas Panel, then a button, and then a text box. I checked the Is Variable box on the button and the text.

Next, I created a Scroll Box widget called MainMenuScrollBox and check the Is Variable checkbox.

Now, when I go to the Blueprint for my Main Menu, I can create the MainMenuButton instance, but I don’t see a way to add them to the scroll box. I found founctions to add a child to a vertical box or horizontal box, but nothing to add it directly. I added a Vertical Box inside the scroll box and I can add the buttons to it using this:


The Unique Categories array is an array of Strings that should each be on a button.

I can’t see how to set the text on the buttons I am creating. I did not find a break function or see a variable for them.

Also, when I try to package my project for VR, I get this error:

UATHelper: Packaging (Android (ETC2)): Unable to instantiate module 'UnrealEd': Unable to instantiate UnrealEd module for non-editor targets.
UATHelper: Packaging (Android (ETC2)): (referenced via Target -> Slitherlink3D.Build.cs)

Any idea what is going on here?

Here is a follow-up in case anyone finds it helpful:

  1. Based on a recommendation from @rokenrock, ScrollBox is a child of Panel so I was able to use the add function for that to add the buttons to it.
  2. For the button text, I has to first make it a parameter and then check the instance editable and expose on spawn checkboxes.
  3. As far as the packaging error, I did not figure it out. I created a new project.

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