UUserWidget pointer is filled with garbage value on runtime, c++
I created UUserWidget and stored it's pointer into TMap. I didn't use AddtoViewport right after the pointer is created at first because I want to use AddtoViewport when I want on runtime. However, the pointer is filled with garbage value when I access it to use AddtoViewport(). Do I have to use AddtoViewport() right after creating UUserWidget? Is there any solution about this situation? Thanks.
asked Nov 21 '17 at 06:37 PM in C++ Programming
The documentation on garbage collection states that:
"The only container that is safe to have UObject or UObject-derived pointers in is a TArray"
I'd guess that your widget got garbage collected between the time you created it and the time when you tried to call AddtoViewport() for it.
I would suggest replacing the map with an TArray or find some way to store the widget pointer in a class member marked with UPROPERTY to prevent garbage collection.
answered Nov 21 '17 at 08:03 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here