I’m working on a multiplayer fps game where I have AI enemies that drop gold coins on death that the players can pick up. The problem is I only want these gold coins to spawn in and exist for the relevant client as not all players can pick up all the coins, every coin is connected to a player that is able to pick it up. The best solution I’ve gotten so far is that all the coins spawn in for both the server and all the clients but they are only rendering for the player that is able to pick them up.
I am new to networking, so maybe it’s bad practice to try and remove stuff from the server. I still would like to know if this is possible, if so how, and why it’s a bad/good idea.
When you’re making an authoritative game and there is something that needs to be unique to a player, you have no choice but to spawn it from the server. If the player is in charge of spawning the item, that opens the door to a lot of cheating (i.e: a player generating infinite coins).
So, your current way of handling it, if it’s crucial to the player’s experience for this item to be “unhackable”, then spawning it from the server is the right way to go.
Only spawn them on the client, and have the client let the server know they picked them up. This works if your server is a dedicated server, as listen server hosts (players that host a server), will have the actor replicate to other clients.
Possibly the better option, spawn the coin on the server, and override AActor::IsNetRelevantFor() to only make it relevant to said player. You can do this by checking that the RealViewer, which is generally the player controller, is the one of the player that should pick them up. This will ensure that only one player will see the coins.
The second option assumes you use C++, I don’t think Blueprints have access to that.
In a Blueprint Actor you can check “Only Relevant to Owner” and when the Server spawns the Actor it sets the Owner which ensures that it will only spawn on the selected Owner.