So my ideal setup is to have a factory object that creates a UActorComponent and this factory is passed as part of an initialization step when creating an actor.
So far I have the following. My issue is that there is so much ambiguity when it comes to the order of operations, spawning, and replication.
Factory.cpp
UChunkModel* UChunkModelFactory::CreateChunkModel(AActor* outer, const ChunkId& chunkId) const
{
UChunkModel* chunkModel = NewObject<UChunkModel>(outer, TEXT("ChunkModel"));
chunkModel->Initialize(chunkId);
// do non-engine stuff with chunkModel
return chunkModel;
}
AChunk.cpp
void AChunk::Initialize(UChunkModelFactory* chunkModelFactory, const ChunkId& chunkId)
{
if (Role == ROLE_Authority)
{
chunkModel = chunkModelFactory->CreateChunkModel(this, chunkId);
chunkModel->CreationMethod = EComponentCreationMethod::SimpleConstructionScript;
chunkModel->RegisterComponent();
chunkModel->SetNetAddressable();
chunkModel->SetIsReplicated(true);
chunkModel->OnUpdate().AddUObject(this, &AChunk::OnModelUpdate);
}
}
So my questions:
-
Do I need to set CreationMethod, and should I set it before or after RegisterComponent?
-
Do I need to call SetNetAddressable, and should I set it before or after RegisterComponent?
-
Should I call SetIsReplicated before or after RegisterComponent?
-
Actor replication works by creating a default subobject on the client and later replicating any tagged properties. How does AActorComponent handle dynamic replication? Does I need to manually create the component on the client or will a NewObject created and registered component on the server be automatically created on the client? Are the flagged properties sent at a later time or part of the initial replication?
-
At what point does the AActorComponent begin replicating (ie: after NewObject, after RegisterComponent, after SetIsReplicated?)