Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sydan · Jun 17, 2010 at 07:48 PM · multiplayernetworkserverclientonserializenetworkview

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

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
    }

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Matthew A · Jan 01, 2011 at 03:06 PM 0
Share

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

avatar image YeOldeSnake 1 · Jan 01, 2011 at 07:04 PM 0
Share

cant he use it in the OnSerializeNetworkView()?

avatar image Matthew A · Jan 03, 2011 at 12:28 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges