I was testing out what happens when I destroy actors and mark objects for garbage collection. All the documentation seems to say that one of the benefits of the UPROPERTY system is that it will automatically set references to GC’d objects to null. I am not seeing this happen in my testing? Can someone tell me what I am doing wrong?
Header:
UCLASS()
class MY_API AMainActor : public AActor
{
GeneratedBody()
...
UPROPERTY(EditAnywhere)
ATestActor* TestActor;
UPROPERTY(EditAnywhere)
TArray<UTestObject*> TestObjects;
}
Source:
// Begin play
TestActor = static_cast<ATestActor*>(GetWorld()->SpawnActor(ATestActor::StaticClass()));
TestObjects.Add(TestActor->TestObject);
// Somewhere else in code
// Bound pressing a button to destroy
TestActor->Destroy();
EmptyObjects[0]->MarkPendingKill();
// Somewhere else in code
// Bound pressing a button to check if null'd
if(TestActor == nullptr)
// Not null'd
if(EmptyObjects[0] == nullptr)
// Not null'd
The resource I am going based on:
When an AActor or UActorComponent is destroyed or otherwise removed from play, all references to it that are visible to the reflection system (UProperty pointers and pointers stored in Unreal Engine container classes such as TArray) are automatically nulled.