I’d like to ask a question regarding events and where/how they should be bound.
Currently, I am binding my UI events under virtual void NativeConstruct(). However, the NativeConstruct method is called every time the widget is pushed onto the viewport. I am wondering if there is a more suitable place for me to initialize my bindings and I found out about virtual bool Initialize() and virtual void NativeOnInitialized.
Could anyone shed some light on this and help me figure out how to best organize the initialization flow.
NativeConstruct is called everytime the widget is rebuilt, so that would include adding it to the viewport, adding it to another widget etc. NativeDestruct is the same, called everytime it’s removed from a parent. These events are linked to the state of the underlying slate widget.
NativeInitialize is called once immeditally after the widget is spawned/created ans has had it’s player context set. It is never called again. You can use that for one-time initialization.
Note that this is always before you add it to any parent widget etc. There are comments on the Blueprint-equivalent events in source code.