- Home /
Can you tell OnSerializeNetworkView who the owner is?
I need a GameObject with a NetworkView to perform OnSerializeNetworkView for both the client and the server. Currently the server instantiates the object when it spawns, the code is authoritive to the server but I want rotation to be non authoritive so I need to send it from the Client... except I cant have two Owners of a network view... I could use two networkviews but surely this will increase bandwidth usage. I need to syncronise many variables...
TL:DR How can I define the owner of a networkview? Or make OnSerializeNetworkView work for a client and server however I wish.
Answer by PrimeDerektive · Feb 03, 2011 at 01:34 AM
I'm not exactly sure what your issue is, but when using OnSerializeNetworkView, the person doing the stream.isWriting is always the person who owns the object on the network.
So you need to plan your Network.Instantiates accordingly, to make sure the ownership is set up correctly. Whoever calls Network.Instantiate will by default be the owner of the networkView of the instantiated object.
For instance, make sure the server is the only instance of the game that runs the code on an enemy spawner, then the server will own the enemy objects that the spawner Network.Instantiates. Then, in the enemy AI code on the enemy object, when you use OnSerializeNetworkView, whatever you put in if(stream.isWriting){} will be the data that the server sends, and whatever is in the else{} clause will be what the clients receive.
Answer by Matthew A · Jan 01, 2011 at 03:05 PM
I don't believe it's possible to change the owner of a network view.
EDIT - correction:
From this post, I believe that the owner of the network view is the one that allocates the view id. If you wish to make the client the owner, you may be able to instantiate on the server, then on the client allocate it a new view id (Network.AllocateViewID()) and pass that back to the server. This would be much the same as calling Network.Instantiate on the client though...
Answer by YeOldeSnake 1 · Jan 01, 2011 at 02:44 PM
use something like
var players:NetworkPlayer[];
if(NetworkPlayer==players[0]){//if we are the server
//do server specific stuff
}
else {//else we must be a client
//do client specific stuff
}
A more concise way would be to use Network.isServer. (But this won't help with OnSerializeNetworkView).
Well yes, but it's not really relevant who the server is in OnSerializeNetworkView, but whether your writing or reading to the stream, which can be found in Bitstream.isWriting.
Your answer
Follow this Question
Related Questions
Multiplayer server-client setup 1 Answer
Unity networking tutorial? 6 Answers
Seperate server - client 2 Answers
Networking RPC calls never sent to other clients 1 Answer
Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers