Swap Characters

Imagine that i have two characters in my game. One controlled by the server player(A) and one by the client player(B). At some point i want to swap control of these characters so that now the server is in control of B and the client is in control of A.

What would be involved in doing this?
Is it just a matter of swapping their viewID on the networkViews?
Do i need a instance of both characters for both players, that i swap?

What about having one controlled by AI until the client joins. Would the client then request a new viewID and then take control of the AI character?

I’m pretty new to how unity handles its networking, so any help is welcomed.

Who N.Instantiate -ed those gameObject with Network Views ? The server, or each client ?

Some way to transfer the “true” ownership (the owner of a Network View can be seen by writing networkView.owner) is to make the future owner execute Network.AllocateViewID. The server will give a free Network View ID. It contains a NetworkPlayert value : the player having called the allocate… which replaces the current value in networkView.owner when you define the new NVID (networkView.viewID = the allocated NVID).

If you use RPCs, you don’t need to do that since you don’t need to be the owner to send RPCs. You can make instead a variable called owner of type Network.player, and change it by RPCs. Whether you are the one in this variable results or not in controlling the object (if owner == Network.player).

Well, if you SWAP something, there must be at least TWO objects !

You can manage to achieve that. The connection player (not the server) requests a NVID (since the connection player is the one who must become the owner), and every user (server and all clients) must apply that NVID to the right Network View, so they are synchronized.

Thanks for that… I think i have a much clearer understanding how unity determines who owns what.

Right now the scene is prebuilt. All devices will open the same scene but since its prebuilt all views will be owned by the server. Ill have the client then make a request to take over a view. Sound right?

Yes, it sounds right. :wink: