Search Unity

Third Party [Photon] Change ownership to sync dynamic scene object

Discussion in 'Multiplayer' started by carking1996, Mar 3, 2014.

  1. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Hello all,

    In my game, players have the ability to pick up objects in multiplayer. But the problem is, the objects don't sync to other players, even with a photonView component added. I've had people tell me I would need to change ownership of the object. Can someone explain to me the issue and how I could go about fixing it?
     
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    Ownership defines which player is able to tell the others where an object is. This avoids conflicting messages about where an object is, if more than one user could send position updates...

    That's why there is ownership.
    The problem is, that with random delays due to lag, it's not trivial to transfer ownership. PUN does not support this at the moment.

    The best solution depends a bit on what you really want to achieve. You could send an RPC "i pick up item X", then everyone can hide the object. If it's still visible, they could attach it to your character and even the owner can skip sending position updates (because everyone assumes the object is attached to you)...

    We're preparing a tutorial that shows how to do item-pickup. I'm not entirely sure though, when it's going to be public.
     
  4. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    I appreciate the answer.

    What I was thinking of doing was once a player picked up the object, destroy the current version, then network instantiate it at the position that the player holds it at.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    Maybe you don't need to network instantiate it when it's picked up. It's no longer an individual object but becomes part of the player who holds it.
    It could become a property of the player. Those are handy for character properties, weapon in use and on back, etc.
    Every client knows it should be there and can display the item on character - no matter what the character does, atm.
     
  6. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Could you provide some example code? I haven't done much with properties.
     
  7. garrettstrobel

    garrettstrobel

    Joined:
    Dec 25, 2013
    Posts:
    9
    Hello , I am trying to do a similar thing as well for item pick ups for a networked mario-kart style game.

    I have followed the PUN item pick-up tutorial but my issue is that I want the picked-up item to be displayed by the user who picked it up.

    I do not want to use change ownership because of the lag and potential delays and issues that arise if two players collide with a pick-up very close in time.

    Instead what I have decided to do is have the player hold an empty gameobject for the pick-up item with a mesh renderer disabled. I then copy the mesh from the collided pick-up item to the player and enable it for display, while setting the scene owned pickup item to inactive.

    The issue is when I enable the player owned pickup item "proxy" for display none of the other clients see this change.

    How do I enable other clients to see that a player has newly visible mesh?

    Thank you!
     
  8. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You need to send an RPC telling the others to do the same locally.

    Another tip for this problem: " the lag and potential delays and issues that arise if two players collide with a pick-up very close in time. "

    Let the master client decide in cases like this.

    Code (csharp):
    1.  
    2.  
    3. void OnCollisionEnter(Collision collision)
    4. {
    5.          if(PhotonNetwork.isMasterClient)
    6.          {
    7.                   //SEND RPC TO OTHERS
    8.          }      
    9.  
    10. }
    11.  
     
  9. Baumkuchen

    Baumkuchen

    Joined:
    Feb 14, 2016
    Posts:
    8
    tobiass likes this.
  10. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    Last edited: Aug 11, 2020
  11. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    tobiass likes this.