TArray: Fatal error: UObject\GarbageCollection.cpp [Line: 575] Invalid object in GC

After a running the game for about 1 minute, the fatal error Invalid object in GC occurs in GarbageCollection. The invalid property which is the source for the error is a TArray of an UActorComponent:

UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<class UAnotherActorComponent*> arrayThatCausesError;

Currently the array is never filled, it does not contain any element. What could be the cause? Am I allowed to do forward declaration in an GC’d TArray?

The cause for the crash was that I accidently added pointers that were not assigned and not initialized as nullptr!

Since I checked for nullptr before adding them to the TArray, they were added though they were undefined.

After initializing the pointers with nullptr, the crash disappeared.

2 Likes