Is there a way to know when a widget is constructed?

I have a widget which gets dynamic content. I’m spawning the widget and then immediately trying to insert dynamic content into various slots. However, this is causing it to crash because it seems the widget hasn’t been (fully) constructed, so there’s issues with invalid slot pointers. Is there a flag or some function to ask if the widget has been constructed? (I guess I could check to see if the slot pointers are valid. But it would be nice if you could just ask if the widget was ready to receive dynamic content.)

1 Like

You’ll need to use the Construct event from within your widget and enable a boolean variable and then whatever you want to do after the construction make it run when that boolean is true.
I think that’s what you’re getting at.

Actually, I had a silly mistake in there. I used a ptr that had a similar name to the one I wanted which was causing the crash. But I also did end end adding a boolean, then checking for it in the Tick function.

Sounds like you’re using UMG, in which case you can manually call Construct() as needed to initialize the managed properties of your UUserWidgets. This is not recursive, however, if you have more UserWidgets nested in your hierarchy, you’ll then have to call Construct() on those too.

Note that calling Construct does not construct the underlying Slate native hierarchy. If your widget hierarchy is fully wrapped in UMG, this doesn’t matter as the properties will be synchronized whenever the Slate hierarchy is created (normally, when added to the viewport). If you make direct use of Slate widgets, then you need to either manually force construction of the native hierarchy, or defer those calls until a point where the native hierarchy is visible.

Actually, not using UMG in this case. But I did another menu which was a mix of UMG and c++ and had a similar issue with the RebuildWidget code.