UserWidget AddToViewport always crash

Hi. I’m making a simple game in C++.

I’m trying to display a widget when the player’s health reaches 0. But it always crashes in the AddToVierport part.

Can someone help me?

When I checked whether the widget works with less player’s health, it worked fine.

Have not already been AddToViewport,

widget != nullptr,

use UPROPERTY,

I confirmed the above.

thank you.

Hi, have you solved your problem? I met this too, if you have solved your problem or any surggestions here, please, share your solution, thank you so much!!!

As a result.

I solved it by doing CreateWidget before AddToViewport.

I don’t know if this is the correct consideration.

In my case, I first created CreateWidget on the GameInstance,

After that, I never operated the widget until I finally called AddToViewport.

For the reason, the widget pointer may have disappeared (?) or replaced with another one (?).

Please let me know if there is any document that seems to be related to this.

Hi I solved this. If you still have problems, think together!

Yes, thanks a lot for your reply, I do create widget before add to viewport, I finally found that I created a static object pointer but forgot to initialize it to null which caused the editor crash.

https://answers.unrealengine.com/questions/938055/view.html

Because I didn’t write UPROPERTY ()