Hi there! When I create an actor based on a template I get an error: Error: UActorChannel::ReadContentBlockHeader: Sub-object not in parent actor. SubObj: DataObject /Game/UEDPIE_1_Current.Current:PersistentLevel.MyActorBP_C_0.DataObject_0, Actor: MyActorBP_C /Game/UEDPIE_1_Current.Current:PersistentLevel.MyActorBP_C_1.
I have a replicated UObject inside an actor. Replication works correctly, but the error confuses. The code is very simple:
AMyActor* Template = GetWorld()->SpawnActorDeferred<AMyActor>(ActorClass, FTransform(FRotator(), FVector(0.f, 0.f, 30.f)), this, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
Template->Constructor(GameMode->GetDataAsset()->DataObject);
Template->FinishSpawning(FTransform(FRotator(), FVector(0.f, 0.f, 30.f)));
Actors.Add(Template);
if (Template)
{
FActorSpawnParameters param;
param.Template = Template;
param.Owner = this;
AMyActor* OtherActor = GetWorld()->SpawnActor<AMyActor>(ActorClass, FVector(0.f, 200.f, 40.f), FRotator(), param);
Actors.Add(OtherActor);
}
This call: Template->Constructor(GameMode->GetDataAsset()->DataObject); contains one line:
DataObject = NewObject<UDataObject>(this);
This is just creating a replicated object.