[Photon] Change ownership to sync dynamic scene object

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?

Bump.

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.

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.

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.

Could you provide some example code? I haven’t done much with properties.

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!

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.

void OnCollisionEnter(Collision collision)
{
         if(PhotonNetwork.isMasterClient)
         {
                  //SEND RPC TO OTHERS
         }      

}

now there is a solution:
https://doc.photonengine.com/en/pun/current/tutorials/ownership-transfer

Or you simply call “photonView.RequestOwnership();” on that object witch owner should be changed

1 Like

@carking1996 : Have a look at this page:

You can also find the tutorials on those pages. I think we use “Custom Properties” in a few cases.
You can also search our demos (in the PUN package) for related methods like “SetCustmProperties”, if you want to have a look at code.

Since the link is no longer working, I found the content here:

1 Like