Spawning from a client but not from character controller

Thank you for this great course. I have a question about spawning an actor, but not from the character controller. The question is: how can I spawn an actor from a client in a scenario where the character is not replicated? So, in an RTS game where the pawn, which has the camera component, has no reason to be replicated, what should I do to spawn a building into the game world? I tried to do it from a replicated object, but I think that, as the owner of the object was not the client, the Server RPC does not get called. However, when I do it from the server, the spawning works. Thus, I am sure that the spawning logic is working fine.

In the case of multiplayer, either the map has everything or when you spawn an actor it should be handled from the server. How else would all clients know this asset needs to be present? The server is responsible for World state.

If it is something unique to an individual player, then spawning would make on the client.

I hope this makes sense.

Thank you for responding,
Well that is correct and my problem was because I was trying to save every bit of bandwidth. And then I realized that is not possible. So I made PlayerControllers to be replicated. And then I use them for Spawning ServerRPCs.

The problem you have then is the server is not the source of truth. Spawning on a client and having that ability means players can introduce cheats. This is why these things are done on the server and replicated.

The main issue, and difference from a map is that a map is a fixed asset and all clients load that asset. Spawning a new actor during play means you have to tell all other clients to do the same. You certainly don’t need player controllers to handle this and it definitely can be done by using server RPCs but the server also needs to know about actors and, they replicate as default.

So, what is probably happening is the server sees a new actor has been spawned by clients and sends a message back saying ‘nope, nuhu, stop, delete’ and the actor is then removed.

Given movement is happening on the server effectively, it needs to be aware of all objects to be able to prevent collisions, stop movement and so on. Even the client hosting the server sends its data to the server first.

Thank you for your response.
What I have done is using server RPCs on Player controllers for spawning any objects in the game.
Is this the standard approach? Or should I do something else. And of course in the future I will use RPCs with validation for ensuring that the Player has the necessary resources for creating a new unit or constructing a new building.

Privacy & Terms