Changing a default subobject name in C++ class leads to UActorComponent being marked as PendingKill immediately after being instantiated when loading from .uasset, and is eventually reset to NULL by GC

I experienced a similar issue in UE5: changing the component SubobjectName of an UObject made with CreateDefaultSubject leads to nullptrs in existing blueprints that still use the previous component name. I found that renaming the variable name of the component fixes the depending blueprints.

For example:

// 1. Define component with a certain SubobjectName. 
URadialForceComponent* RadialForceComponent = CreateDefaultSubobject<URadialForceComponent>(TEXT("I will change this name after creating a blueprint with this Actor"));

// now make a blueprint with it

// 2. Changing SubobjectName breaks downstream blueprints
URadialForceComponent* RadialForceComponent = CreateDefaultSubobject<URadialForceComponent>(TEXT("RenamedComponent breaks blueprint"));

// 3. fix: refactor variable (ignoring SubobjectName)
URadialForceComponent* RadialForceComponentRenamedVar = CreateDefaultSubobject<URadialForceComponent>(TEXT("RenamedComponent breaks blueprint"));```
6 Likes