Why I should call ConditionalBeginDestroy

Hi all,

In one of my classes in .h file I have following setup:

UPROPERTY()
USomeUObject* myPtr;

then In cpp file I create object of this class and assign it to pointer:

myPtr = NewObject<USomeUObject>(this);

everything works perfectly.

Now I want to delete my uobject explicite. Through this answer hub everybody suggest I should do it like this:

myPtr->ConditionalBeginDestroy()
myPtr = nullptr;

if (GetWorld())
    GetWorld()->ForceGarbageCollection(true);

I understand that the most important step here is assignment myPtr = nullptr. This nullifies pointer to object, engine knows that there are are no more valid references to it so it can be garbage collected. Additional call to ForceGarbageCollection() is just there so this will happen as soon as possible. But why oh why I need to call ConditionalBeginDestroy()? I tried this code without it and object is still garbage collected.
So should I call it or not? If garbage collection is not forced (usuall case), is this function called automatically by engine somehow?

cheers :wink: