Spawn one actor on both the client and the server

How would I spawn the SAME actor on the client and the server? Right now I have:

MyItemReference = GetWorld()->SpawnActor<AItem>(MyItemClass, FVector(0, 0, 0), FRotator(0, 0, 0)); // MyItemReference is a replicated pointer.

If I call this only on the server, nothing happens on the client; no actor is spawned, and MyItemReference is NULL. If I call this on both client and server, MyItemReference returns NULL on the client (probably because it’s replicated, so the reference to the client-spawned version gets overwritten with the client-unaccessable server version).

SO, how can I properly replicate a spawned actor, so that the client can access it? Is there some “ReplicateActor” variable I have to set or something? I checked the FActorSpawnParameters, but I didn’t see anything there.

Thanks in advance :slight_smile:

your custom actor needs this in its constructor:


	//Replication
	SetRemoteRoleForBackwardsCompat(ROLE_SimulatedProxy);
	bReplicates = true;
	bReplicateMovement = true;

Awesome, thanks Rama! I figured it would be something like that, but I just couldn’t find it. Thanks again! :slight_smile: