TSubclassOf cause access violation crash in shipping package


I don’t know if my problem is really an Unreal bug but the behavior is quite strange and may be unexpected, so I share it with you in bug reports section in cas of.

I use TSubclassOf<> in a TArray for an inventory. It works in editor but often crash in shipping package when I try to access default object where it should not (all checks are here).

  // Array definition
  TArray<TSubclassOf<AMETA_Seed>> m_SeedSubclassArray;


   TSubclassOf<AMETA_Seed> seedSubclass;

    for (int32 i = 0; i < m_SeedSubclassArray.Num(); i++)
		seedSubclass = m_SeedSubclassArray[i];

		if (seedSubclass != nullptr && seedSubclass->IsValidLowLevel())
                    // Crash here
			seedDefaultObject = seedSubclass->GetDefaultObject<AMETA_Seed>();

I’m just thinking about UPROPERTY on TArray, it may be a garbage collector problem, as is seems pointers are behind TSubclassOf. In this case, I don’t know if this beavior is unexpected or if it’s just not evident. I will search in this way and post I’m finding any clue.

Someone has any idea of what can be wrong with this ?

Seems it is a garbage collection problem, for the moment I stop crashing in my shipping package. So TArrayof UObject derived class needs UPROPERTY macro to avoid undesirable behaviors like this.

The garbage collection overview doc may not be clear on this point:

The only container that is safe to have UObject or UObject-derived pointers in is a TArray