x


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.

more ▼

asked Jun 17 '10 at 07:48 PM

Sydan gravatar image

Sydan
241 13 14 19

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Feb 03 '11 at 01:34 AM

PrimeDerektive gravatar image

PrimeDerektive
3.1k 57 64 84

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Jan 01 '11 at 03:05 PM

Matthew A gravatar image

Matthew A
517 7 9 20

(comments are locked)
10|3000 characters needed characters left

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
    }
more ▼

answered Jan 01 '11 at 02:44 PM

YeOldeSnake 1 gravatar image

YeOldeSnake 1
205 11 12 19

A more concise way would be to use Network.isServer. (But this won't help with OnSerializeNetworkView).

Jan 01 '11 at 03:06 PM Matthew A

cant he use it in the OnSerializeNetworkView()?

Jan 01 '11 at 07:04 PM YeOldeSnake 1

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.

Jan 03 '11 at 12:28 PM Matthew A
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x733
x713
x426
x130
x28

asked: Jun 17 '10 at 07:48 PM

Seen: 2391 times

Last Updated: Jun 17 '10 at 07:48 PM