How can I destroy an Object from Root Set?

Hello,

I would like to ask how to destroy objects from Root Set (explicitly marked with RF_RootSet), as calling MarkPendingKill() throws an exception at assert: check(!IsRooted()). It seems that those objects cannot be deleted that way and I would like to know if removing RF_RootSet flag and then calling MarkPendingKill() is safe.

Thank in advance,
cloud

It seems that removing RF_RootSet is working but it’s important to remember that “Outer” has to be set to default value as changing that will cause the chain of references to point to our object and will throw an exception during GC.

#UPROPERTY()

why are you using root set ?to prevent GC?

I’d recommend just using UPROPERTY() for GC protection and not using the Root set

when I restart levels or change levels with actors I made part of the root set the game frequently crashed

Rama

I have class OrderQueue which is an array of instances of class derived from UObject in every unit in game (array of orders for units).

  1. If I change OrderQueue to: UCLASS() UOrderQueue : public TArray {…} and use UPROPERTY() to mark that variable in unit, my orders will be properly GC (that is they will not be destroyed as long as they are in the array)?

  2. If I mark TArray variable with UPROPERTY(), orders will be correctly GC (is UPROPERTY() on TArray enough and I don’t have to worry about using UPROPERTY() on UOrder)?

Hey @Rama, does this work for UPackage? Because Im using LoadPackageAsync as a form of caching the new level to be opened (I cant use streaming levels because i want to change the game mode, player controller and such).