Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

When exactly does UMG Widget OnInitialized get called?

I'm struggling to find this information in the documentation.

I have the following code:

 widgetInstance = CreateWidget<UMyWidget>(this, wMyWidgetType);

I want to be able to ensure that SetCustomProperty runs before OnInitialized runs in the blueprint layer. I have tested that this works currently, and it can be verified with log statements, but is it actually a safe expectation to hold? I'm not seeing where the specific behavior is documented.


Product Version: Not Selected
more ▼

asked Feb 12 '19 at 08:07 PM in C++ Programming

avatar image

1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

In 4.21, the static method CreateWidget<>() in UserWidget.h calls the BlueprintImplementableEvent OnInitialized() by calling UUserWidget::Initialize().

The exact "call chain" is (everything in UUserWidget):

CreateWidget() -> CreateWidgetInstance() -> CreateInstanceInternal() -> Initialize() -> NativeOnInitialized() -> OnInitialized()

So no, OnInitialized() should be executed "at the same time" than CreateWidget<>() is called. So the behavior you see seems kind of strange. However, I'm not an expert and just looked through the code, I may not understand everything correctly (for instance I don't know if the BlueprintImplementableEvents are delayed for next frame, which should explain the behavior you got).

Keep in mind, however, that the call to OnInitialized() in Initialize() is guarded by this line:

 if (!IsDesignTime() && PlayerContext.IsValid())

So depending of the context surrounding your code, it may or may not be called. The Initialize() method is also called by: UUserWidget::PostDuplicate() && UUserWidget::RebuildWidget()

more ▼

answered Feb 12 '19 at 10:04 PM

avatar image

96 2 8 10

avatar image sykaeh Feb 12 '19 at 10:30 PM

Hey, thanks for the response. I'm seeing the same call chain as you. I agree that it doesn't make sense. I was hoping that one of those actions had something going on I didn't realize...perhaps, actually just being queued up for after the current execution context or something along those lines.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question