Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Accessing client objects from host

Discussion in 'Netcode for GameObjects' started by anyamit, Mar 29, 2024.

  1. anyamit


    Nov 13, 2023
    Screenshot 2024-03-29 155103.png I'm making a multiplayer Unity network game in which both players, the host and the client, have barrier objects. I want to make it so that when the host moves their player, it also moves the client's barriers, and when the client moves their player, it moves the host's barriers as well. Essentially, I'm struggling with accessing the client objects from the host side and vice versa. I'm unsure exactly how to get this to work; the code that I have so far (see image) isn't working. Could I have some help? Thanks.

    View attachment 1392934
    Last edited: Mar 29, 2024
  2. CodeSmile


    Apr 10, 2014
    Please post code as text and put it in code tags.

    All barrier move operations must be done by the owner of the barrier network object. By default, this is the server (host).
    Your update calls both a Server and Client RPC which I'm surprised even works. A client should not be able to send a ClientRpc but perhaps this restriction has been lifted.

    In the ServerRpc you are not assigning the position after changing it, you only change the local Vector3 variables left/rightObjPos.

    I doubt that this "barrier" will have the expected effect due to time delays. Assuming both players try to move forward simultaneously, the other player will be blocked until the RPC is received. This means this won't be fair game, and likely leads to players stuttering because they're constantly being blocked and unblocked. If they can move at all, since the barrier won't move until the other player moves but that player can't move until the other player moves etc.