[replication] My C++ Actor Won't Replicate

Hi All,

So I’ve been working on this for days now, probably spent a combined 50 hours just trying to get my actor to replicate, including research, learning and testing.

I can, quite easily, get an actor to replicate if it’s a blueprint actor, but my C++ actor won’t.

For reference, I’m trying to build an online multiplayer procedural generated world and I’m spawning each chunk of that world as an actor. This all works wonderfully on the server/listen server. My approach has been to spawn the actor on the server and replicate it to the clients.

For testing, I have an empty map. The map blueprint OnBeginPlay spawns a single Chunk actor.

Edit 1: I’ve also just found that if I add my c++ actor as a child to a blueprint actor that does replicate correctly, that entire actor now ceases to replicate.

Any assistance would be very much appreciated!

I have the following in my .cpp file OnConstruction to try to force replication:

void AChunk::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	
	DOREPLIFETIME( AChunk , ChunkSaveData);
		
}
void AChunk::OnConstruction(const FTransform & Transform)
    {
    	//Set Up Replication
    	bReplicates = true;
    	bTearOff = false;
    	bNetLoadOnClient = true;
    
    	//create root procedural mesh component
    	FString strName = "Chunk_" + FString::FromInt(chunkIndexX) + "_" + FString::FromInt(chunkIndexY);
    	FName chunkName = FName(*strName);
    	proceduralComponent = NewObject<UProceduralMeshComponent>(this, chunkName);
    	proceduralComponent->RegisterComponent();
    	proceduralComponent->bUseAsyncCooking = true;
    
    	//set root component to new procedural mesh component
    	RootComponent = proceduralComponent;
    	RootComponent->SetWorldTransform(Transform);
    	RootComponent->SetIsReplicated(true);
    }

I have the following in my .h file:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Meta = (ExposeOnSpawn = true))
	FChunkSaveData ChunkSaveData;

	virtual bool IsSupportedForNetworking() const override
	{
		return true;
	}

Screenshot of the Listen Server on the left and Client on the right. Client sees the blueprint actor with Plane component only.

I had a break for a day and looked again and I’ve found my answer.

I found the answer in a thread on the forums.


To summarise:

UProceduralMeshComponent does not have built in replication and, even if you force it, the mesh sections within that won’t replicate.

So that means the answer is:

To replicate a UProceduralMeshComponent, you will need to replicate the instructions used to generate this mesh component rather than the component itself.