Duplicated Objects getting cleaned

Heres example of code.



DraggingItem = DuplicateObject<UItem>(HoveredItem->GetItemReference(), this, MakeUniqueObjectName(this, HoveredItem->GetItemReference()->GetClass()));


Im trying to Duplicate Item Object that was created in ItemWorldActor that is a visualisation of my Item Object in the world, duplicated object’s outer is my PlayerController, DraggingItem is UItem* in my PlayerController, when i start dragging item, im destroying ItemWorldActor and duplicating item object inside my controller, when im dropping item to the world again, im creating new ItemWorldActor and setting ItemReference in ItemWorldActor as Duplicated Object from my DraggingItem, but by some reason DraggingItem is getting cleaned, whut im doing wrong?

GetItemReference() returns UItem*

if im dropping dragged item fast everything works just fine, but if im holding dragging item for like 30 seconds and then drop engine crashes.

since i dont understand how to Duplicate objects i tried NewNamedObject to create object from teamplate, i added #include “UObjectGlobals.h” checked that CoreUObject module is on, but Visual Studio and UE says that NewNamedObject is undefined.

Imgur

I still don’t understand how to change object’s outer, or duplicate it, or do something to keep it after their outer is getting cleaned.
mb I should create all items with World as outer? is that ok? or create some actor to create all item objects in the world inside it?

i dont get it, even if i create NewObject from template


ItemReference = NewObject<UItem>(this, itemref->GetClass(), MakeUniqueObjectName(this, itemref->GetClass()), RF_NoFlags, itemref, false, nullptr);

ItemReference is still crashes engine if im trying to access it in a 10-30 seconds after i created new object. But if i do it fast it works well.

outer is my PC.

Have you declared the ItemReference pointer with UPROPERTY? Otherwise the GC will remove it after some time.

no i didnt, thanks alot man.