How do I transfer ownership of an object?

Options
I have a room where players can connect and move around using the default FirsPersonController. I've made a vehicle that can be exited and entered and it's all synchronized, but there is a problem. Only the host of the game can drive the car around. The host can see other players entering the car, but they are only able to drive the car on their own screen(the host sees them in the car standing still).

After some digging, I realised this is due to the Owner property of the PhotonView component being set to fixed. This means that other players were trying to move a car that didn't belong to them. I looked into the documentation for RequestOwnership() and after trying to pass various IDs from PhotonView and PhotonNetwork through it, it didn't work.

My question is, how do I transfer the ownership of my vehicle to the player that enters it?
I am using PUN v2.

Answers

  • Jasper_w
    Options
    You can do it like this: Make the car a scene view, and when someone wants to join it use carObject.photonView.RequestOwnership() and then the master client gets a event in whick you give them the view. Then the client becomes the owner and serialize will be called with IsWriting false and the new owner can Update the position.

    Photon Tutorial about this