Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question New to multiplayer: Clientside / Serverside

Discussion in 'Multiplayer' started by Pineapplesy, Oct 30, 2022.

  1. Pineapplesy


    Jun 21, 2022
    I am currently attempting to make a multiplayer 2d top down rts, but I am quite new to unity and very confused by the way multiplayer works. My choice of movement for the player would be using the A* movement, not sure what to call it. I have a "flag" which you can place anywhere on the map, and the player will start running towards it. The problem is that I'm not exactly sure how to stop both players from running towards the same flag. I was thinking that the flag should not be included in the player prefab (so that it would remain clientside?), but I have no idea where to put the IsOwner check so that only the desired player goes after that flag. I'm not sure I explained my situation very well, but any wisdom will be appreciated, I also don't care about security or anti-cheat measures.

    Thank you for your patience.
  2. CodeSmile


    Apr 10, 2014
    The flag shouldn't be part of the player prefab. It isn't the player, it's a visual representation of a "goto" action the players should perform. Each player has its own target and depending on your game, other clients don't even need to see each other's target flags.

    That flag represents a client's intent to move towards that flag. So what you do when it is (re)positioned is to send a MoveToTargetServerRpc and the server performs pathfinding and issues a "goto" command for only that client's player instance. Every ServerRpc gets the sending client's clientId in the ServerRpcParams and Netcode manual has instructions on how to find a player instance.

    If you want to have client-authoritative movement then you can have the IsOwner perform pathfinding and move to the target, the NetworkTransform will sync the position among clients. The local (owner) client will see instant movement but other clients will see a larger delay in movement of other players compared to server authoritative movement due to the roundtrip time from client to server, then server to clients. All of that and the potential for clients to cheat should be okay for non-competitive games.

    In any case, your issue is because you treat the flag as a single object somehow, rather than it being a per-client object.