How to dynamically create a UImage and add it to a VerticalBox container?(runtime, c++)

I use the api:

UImage* NewImage = this->WidgetTree->ConstructWidget(UImage::StaticClass());

VerticalBox->AddChildToVerticalBox(NewImage);

It seem OK, But when I exist the PIE(Play In Editor),Unreal Editor crash.

I try to use API: removeChild to release NewImage ,no change…

can you give me some advise, thanks~

maybe you should use “UImage* NewImage = NewObject(this, UImage::StaticClass());”

I have tried this API(New Oject), but the problem remains the same.。。。


I use this code, no crash

Oh,no,It’s still the same here。。。

你的gameinstance里做了啥,这错误已经不太一样了,看报错应该是GC的时候有问题。不太了解你的逻辑

没啊,GameInstance用的是默认的,只有MyUserWidget是自定义的,

我从UserWidget派生了一个C++ A类(我在这里添加了动态创建UImage,并将它添加进垂直框容器),然后从A类派生了蓝图类MyUserWidget。之后我在一个actor中创建了一个UserWidGet组件,将MyUserWidget设置为了它的控件类。最后,将actor拖入世界场景。。。

运行PIE后,表现正常,退出PIE就报这个错了。。。

最后我发现,注释掉下图红框的代码,就不会报错了。。。不知道为啥。。