I am making an Editor Utility Widget to allow for designers to override some aspects of the level generation. However, what I’d like to do is have a scrollable column in the middle of the widget with a “+” button at the bottom. When users push the “+” button, it instantiates a new instance of a sub-widget within the scroll view and allows data to be entered within that sub-widget. This second widget is contained in a different blueprint. We have done similar things elsewhere for in-game UI widgets, however when calling CreateWidget to try to add to the Editor Utility Widget, it simply returns null. I think this makes sense, as CreateWidget is looking for a player controller, a world context object, etc, and none of these exist when we’re just in-editor with the game paused. However, I’m unsure how or if you can create a new child widget within a parent widget when you’re dealing with Editor Utility Widgets. Has anyone done this before?
Dealing with an Editor Utility Widget can be a bit different than creating widgets in-game.
One way to accomplish this is to use the Create Widget node in the Blueprint editor to create a new instance of the sub-widget. However, instead of passing in a player controller or a world context object, you will need to pass in the parent widget as the owner.
Here is how you can set it up:
In your Editor Utility Widget Blueprint, create a variable to store a reference to the parent widget.
Drag out a “Create Widget” node and connect it to the “OnClicked” event of the “+” button.
In the “Create Widget” node, select the sub-widget Blueprint that you want to instantiate.
In the “Owner” field of the “Create Widget” node, drag the parent widget variable into the field.
Drag out an “Add to Viewport” node and connect it to the “Create Widget” node.
Drag out a “Cast To” node and connect it to the “Create Widget” node. Use this node to cast the created widget to the specific class of the sub-widget.
Drag out a “Set Visibility” node and connect it to the “Cast To” node. Use this node to set the visibility of the sub-widget to true.
This way, you are creating the widget with the parent widget as its owner, so it should be able to add the sub-widget to the viewport and be visible.
I hope this makes sense! Let me know if there are any issues.
Interesting, I had tried to do something similar in c++ and it was not working (the widget created was returned as null). I’ll give it a shot using blueprints instead.
I am somewhat trying to do the same thing, but not quite as straight forward.
I have a custom Text Button widget that I am using for runtime UI, and I would like to reuse this button in an anchor menu on a button in an Editor Utility Widget.
The Text Button widget dynamically creates a text widget o that it can add the text widget as child to a specific widget on the button.
When I use the button in the Anchor Menu in the Utility Widget, the Text is not created.
I was trying to add a branch to the button using the “is Design Time” Boolean, so that if it was True, it would do what is mentioned here, instead of using the player controller.
However, I am super confused. I am a visual person, and trying to follow your text directions and cannot figure it out.
This would be tremendously helpful to me, and would save me a lot of time re-coding duplicate wisgets just to be able to use them in Editor Utility Widgets