I keep hitting this weird scenario where my child BP actor breaks if I make any changes to its CDO (or its parent).
Here’s my basic setup:
- I have a custom plugin with a C++ USceneComponent.
- I then created a Blueprint base class actor, and added that component to the actor.
- I then created a child of the Blueprint class.
The base BP class is supposed to execute some code on the C++ component plugin, which needs to call GetWorld()
.
It works fine for the base class. However if I modify either of the Blueprint default objects (base or child). The instance of the child class in the game will return nullptr
from the GetWorld()
call inside the plugin Scene component.
I added some logging inside the component class, and it appears the code is getting executed from the component archetype, so it doesn’t have any reference to the world:
LogTemp: Error: <DJBeatSubscriberComponent> isCDO=0, isArchetype=1, GetWorld()=nullptr
LogTemp: Error: GetOuter() = <BlueprintGeneratedClass> isCDO=0, isArchetype=0 ->GetWorld()=0
LogTemp: Error: GetOwner() = nullptr
Here’s the logging code:
inline void testPrintObjectInfo(const char* name, UObject* object)
{
if (object) {
bool isCDO = object->HasAnyFlags(RF_ClassDefaultObject);
bool isArchetype = object->HasAnyFlags(RF_ArchetypeObject);
UE_LOG(LogTemp, Error, TEXT("%hs = <%s> isCDO=%d, isArchetype=%d ->GetWorld()=%d"), name, *object->GetClass()->GetName(), isCDO, isArchetype, (object->GetWorld() != nullptr));
}
else
{
UE_LOG(LogTemp, Error, TEXT("%hs = nullptr"), name);
}
}
// ... Gets called here:
auto World = GetWorld();
if (World == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("<%s> isCDO=%d, isArchetype=%d, GetWorld()=nullptr"), *GetClass()->GetName(), HasAnyFlags(RF_ClassDefaultObject), HasAnyFlags(RF_ArchetypeObject));
auto componentOuter = GetOuter();
testPrintObjectInfo("GetOuter()", componentOuter);
auto owner = GetOwner();
testPrintObjectInfo("GetOwner()", owner);
}
Ultimately if I close and reopen the editor, the problem fixes itself. But any changes made to either defaults of the Blueprint objects break the child class.
Is there something I’m missing? Is this some limitation, of having child blueprints? Or is this a bug?