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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

What is the best way to have a network object that can be moved by host and client?

Discussion in 'Multiplayer' started by MParkerP, Jun 30, 2023.

  1. MParkerP


    Dec 8, 2022
    Right now I have a very simple 2D settup where the player can press a button to create a host or client and join or create the session accordingly. The two players work perfectly, but I wanted to try spawning an object that both players can interact with.

    I have a method that the host calls to spawn a circle that they are able to push around. The client can see the ball properly and the ball stops if it runs into them so they touch, but the client cannot push the ball.

    I understand that this is because the host/server controls the position of the network objects, but I am not sure of the best way to allow the client to get around that issue. I thought I could maybe have an object "owned by no one" but that doesnt seem to fit what I understand about Netcode.

    Some possible solutions I have cosidered:
    • Give the ball to the client and give it a ClientNetworkTransform (just reversed the issue)
    • Attempted to change the bool for CanCommitToTransform on the ball (could not figure that out)
    • Changing ownership whenever a player touches the ball (works, but if both players are touching I imagine it would break)
    • Send a ServerRpc from the client asking for the ball to move when touching it (I imagine this is maybe the way to go about it, if so I would need a lot of explanation on it like what info am I sending to the server and how do I then apply it to the ball in an accurate manner as if it had just been touched)
    (Also even though this setup is for testing, the fuller version is only 2 player and uses Relay for P2P so the Host/Client setup is about the same)

    If you have any suggestions or answers I would really appreciate a simple prgrammed example written out even if its just how a method is formatted or something, or direction to documentation is always helpful!

    Thanks! <3