UE5.1 Custom UserWidget call Initialize() infinitely

Hi !

We have a C++ custom UserWidget class which just add 2 BlueprintImplementableEvent. It worked perfectly in 5.0.3. We just updated to 5.1.1 and now OnInitialized() is called infinitely until infinite loop detection…

I put some print in Initialize() and NativeOnInitialized() function, both are spammed too.

I only found one reddit post with the same problem, but no solution : https://www.reddit.com/r/unrealengine/comments/zhes1g/getting_an_error_infinite_loop_detected_i_cant/

Do anyone have any idea ?

Edit 1 : I continue to look for the cause. If I don’t put the OnInitialized event in Blueprint, there is no spam, not even the C++ functions Initialize() and NativeOnInitialized().

Edit 2 : The bug only appear if I put the node Add to Viewport on OnInitialized event.

Edit 3 : Add to viewport does not work

I already checked and I call correctly Super::Init() in my GI… Researches continue…

Okay I found the problem. It’s an 5.1 engine bug. On UUserWidget C++ subclasses, the variable “MyWidget” of the widget is not set when the OnInitialized event is triggered. AddToViewport call “RebuildWidget” if this variable is not valid, which call another OnInitialized, etc… Infinite loop.

I reported the bug.

Workaround : I put another event on timer, 0.1s after the event OnInitialized. It works.