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

Resolved Is it possible to let 2 different players control 1 game object?

Discussion in 'Netcode for GameObjects' started by superdracon1, Mar 2, 2024.

  1. superdracon1

    superdracon1

    Joined:
    Oct 16, 2023
    Posts:
    3
    I want to make 2 players control 1 game object using Unity netcode. However, when 1 player connects he claims ownership of that game object, not allowing the second player to control it
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,623
    (ignore the above AI generated spam comment, don't click the link!)

    Still, it's correct that two players can control a single object but ... what does CONTROL mean in your context?

    If you want both players to use input to move the object simultaneously, their input will be in conflict. If on the other hand, the object is a tank and one player is driving and the other is controlling the turret and shooting, then this is possible but technically you'll be operating with two objects: tank and turret.

    You seem to have an ownership conflict - only one client/server can own a single object at any given time. If you want both to work with the same object, the server should own that object and controlling the object should be done by each player sending RPCs to the server who then does the job of moving and rotating the object(s).
     
    superdracon1 likes this.