Editor crashes on startup if uninitialized UPROPERTY object pointer is used in USTRUCT

If inside a USTRUCT an object pointer is declared as a UPROPERTY like this:

USTRUCT(BlueprintType)
struct FCrashingStruct
{
	GENERATED_USTRUCT_BODY()

public:
	FCrashingStruct()
	{
	}

	UPROPERTY()
	AActor* Object;
};

…the editor crashes on startup (assert fails) at the following location:

UE4Editor-CoreUObject.dll!TFastReferenceCollector<FGCReferenceProcessor,FGCCollector,FGCArrayPool,0>::ProcessObjectArray(TArray<UObject *,FDefaultAllocator> & InObjectsToSerializeArray, TRefCountPtr & MyCompletionGraphEvent) Line 293 C++
UE4Editor-CoreUObject.dll!TGraphTask<TFastReferenceCollector<FGCReferenceProcessor,FGCCollector,FGCArrayPool,0>::FCollectorTask>::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 883 C++
UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasks() Line 1277 C++
UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasksUntilQuit(int QueueIndex) Line 1171 C++
UE4Editor-Core.dll!FTaskThreadBase::Run() Line 643 C++
UE4Editor-Core.dll!FRunnableThreadWin::Run() Line 76 C++
UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() Line 25 C++
[External Code]

However, if either the UPROPERTY() is removed, or the pointer is initialized to nullptr inside the struct’s constructor, like this:

FCrashingStruct()
{
	Object = nullptr;
}

…the editor starts up.

The log states:

[2017.02.22-10.00.06:511][
0]LogUObjectBase:Error: Object flags
are invalid or either Class or Outer
is misaligned

This error is probably related to UE-23056 where the developer notes say ‘Improper struct initialization’ (which isn’t being terribly specific).

I see that not initializing the pointer probably IS an improper initialization, and I get that this probably cannot be caught at compile time. However, it is a very obscure error to me that took some time to track down.
Maybe an improved runtime error could be implemented that somehow names the affected struct?

+1, this has happened to me. Very happy to have found this post.

The editor crashes if you call the constructor without initializing the pointer.

FCrashingStruct SomeCrashingStruct; //We created a struct but AActor* Object hasn't been initialized as a nullptr
SomeMethodThatUsesFCrashingStructAsParam(SomeCrashingStruct);

I added a UPROPERTY with this struct to the actor class. That started to crash the editor.

Hi TaurusI76,

I believe you are correct that this is related to UE-23056. I can look into the possibility of a feature request to make the error message a bit more helpful.

How are you referencing the struct, though? I made an Actor class and added that struct to the class’ header file, but opening the project in the Editor did not result in a crash for me.

It still is not crashing for me. I am not sure what I am doing differently from you. This is what I have in my class’ header file:

USTRUCT(BlueprintType)
struct FCrashingStruct
{
	GENERATED_USTRUCT_BODY()

public:
	FCrashingStruct()
	{
	}

	UPROPERTY()
	AActor* Object;
};

UCLASS()
class TESTSTRUCT3_API AMyActor : public AActor
{
	GENERATED_BODY()
	
public:	
	AMyActor();

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = TestCat)
	FCrashingStruct TheStruct;
};

This project opens fine, even if I make a Blueprint of the class and place it in the default level. I also tried creating another local instance of the struct in my class’ constructor, and that didn’t result in a crash either.

You’re not trying to do anything with it. Try passing it as a function parameter. Try broadcasting a delegate with the struct as a parameter. The crash at least for me was on the c++ level, I did nothing in blueprints at that point.

You’re right, I had to actually touch the struct. Passing it into a function wasn’t enough. I’ll have to see if there is anything we can do to clarify what is happening here.

Hi everyone,

I was digging into this some more today, and noticed that the error message that I was getting does already somewhat hint at where the problem lies. This is the error that I am receiving: LogWindows:Error: Invalid object in GC: 0x000007fec7bda848, ReferencingObject: MyActor /Script/TestStruct3.Default__MyActor, ReferencingObjectClass: Class /Script/TestStruct3.MyActor, Property Name: Object, Offset: 1072, TokenIndex: 17

In this case, “Object” may not be the best name for the pointer in the struct. However, the error does indicate that there is a problem with the property named Object. Do you think that needs to be further clarified in this case?

You’re right, I missed that error message. My mistake was that when you stop the MS Visual Studio debugger at the point where it hits the breakpoint (and not click ‘Continue’ (twice), the UED doesn’t finish the log so that line never gets written.
I think the error message you posted is sufficient.

I do confirm I have had twice that error (different projects). It is still unclear exactly why, but it is indeed related to pointers inside a FStruct. In my case not a AActor* but a UStaticMesh*:

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties")
		UStaticMesh* MeshInSpace;

This pointer is not setup at structure creation, but is later setup after an ActorItem is created, containing this FStruct.

So I am guessing either:

  • there is a problem with the structure creation with UE4 engine (memory allocation ?) or
  • the engine somehow is trying to access a value to that pointer (some kind of reflexive analysis ?)

[EDIT]
Strangely, just explicitly setting the variable inside the FStruct to nullptr was sufficient to remove the error & crash…

Bumped into the same issue. A UPROPERTY() with a pointer to an actor declared inside USTRUCT() not being initialized when the struct is allocated on the stack. UE 4.16

I bumped into same issue in 4.20 too (Invalid object in GC). Unitialized UPROPERTY() UObject* in struct which is in struct (all of them marked as UPROPERTY) is causing crash on GC.

I created the struct in begin play with FMyStruct s = FMyStruct(); and then assigned to class variable of same type: StructClassVariable = s;

Actor class which contains StructClassVariable is placed in level and command obj gc is causing crash.

So what can be hapenning is that FMyStruct created as local variable does not have its variable initialized because it is not UPROPERTY() class variable and this variable is then assigned to class variable marked as UPROPERTY(). Next GC iterates over references and actor reference in class variable is not initialized, so it crashes.

Hi guys, I also suffer from this kind of crashing problem on UE4.21. I searched and digged down the codes for this issue, it seems that it is not easy to fix with only some code changes.

This problem rarely occurs on my project, so my team decide to make Linter transformation to ensure the member pointer variables are initialized with nullptr properly.