Prevent replicated spawn of a replicated Actor

Hi,

I have some replicated C++ Actors and I want them to load with the level on server and client. so far, so simple.

Then during runtime, I spawn more of these Actors which I don’t want to replicated to clients because the client spawns it’s own version which is then decoupled of the server’s counterpart.

I tried this by using deferred Actor spawn like so:

AMyActor* MyActor = World->SpawnActor< AMyActor >(Params);
MyActor ->DisableReplication();
MyActor ->SetSomeOtherAttributes();
MyActor ->FinishSpawning(SpawnTransform, true);

But the Actor spawn is replicated nonetheless. This results in the client having two versions of the actor: The one it spawned for itself and the replicated spawn.

Is it possible at all to prevent the spawn replication of a replicated Actor or do I need to think of something different here?

Best

Dominik

Hi,

I’m not sure what handling is being done in your DisableReplication function, but you should be able to spawn an actor and then call AActor::SetReplicates(false) on it in order to prevent it from being replicated to clients.

Thanks,

Alex

Hi,

sorry I left that bit out.

The function was just setting bReplicats = false. Because calling SetReplicates(false) inside the deferred construction was giving me a warning.

It appears that calling SetReplicates(false) even after the FinishSpawning() still prevents replicating the spawn.

So thank you for this very helpful hint.

Hi,

Great, I’m glad that’s working for you! If you have any more questions or run into any other problems, please don’t hesitate to reach out.

Thanks,

Alex