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
1
Question by lvictorino · Aug 27, 2012 at 01:26 PM · networkingnetworkview

Client can't serialize to client

Hi,

I'm completely lost with this one.

I have a GameObject A who does have a NetworkView component. On Start A calls Network.Instantiate in order to instantiate a GameObject B in every other networked clients.

Then I use OnSerializeNetworkView on A to modify some properties of B. The NetworkView Component is set with the script in charge of OnSerializeNetworkView.

The problem is that only the host receive informations. When I only have two players (a host and a client) everything is fine, every players can see modification on each other's object. But when I have more than two players (say a host and two clients) every clients can see host's object modifications (and viceversa) but a client can't see another client's object modification.

Example of my code (very basic) :

 private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
   if ( stream.isWriting )
   {
     int color = my_color;
     stream.Serialize(ref color);
   }
   else
   {
     int color = 0;
     stream.Serialize(ref color);
     Debug.Log("receiving: " + networkView.viewID + " -- " + color); 
     // will log in client<->host but not in client<->client
   }
 }

Is there a trick to know?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by asafsitner · Aug 28, 2012 at 09:57 AM

What happens is that your ObjectA has a different viewID than the instances of ObjectB that are created on everyone's machines (including the machine that called the Network.Instantiate).

Network.Instantiate allocates a new ViewID and sets the player who called it as the owner of that viewID. Now, serialization goes from one NetworkView to another based on the NetworkViewID of that NetworkView.

So if you try to serialize data from ObjectA who has, say, viewID of 2, the network will try to send that data to all other objects with the same viewID (2), but not to ObjectB who has a newly-allocated viewID of 3 (courtesy of Network.Instantiate).

To remedy this problem you'll have to serialize the changes from your copy of ObjectB, which you are the network owner of, to the other clients. Or make sure that the viewID of all the copies of ObjectB match the viewID of ObjectA by implementing your custom Instantiate RPC.

Don't hesitate to tell me if the answer is not clear enough. :)

Comment
Add comment · Show 5 · 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 lvictorino · Aug 28, 2012 at 10:02 AM 0
Share

Hey thank you for that answer. It's pretty clear... but my question seems not :) In fact only ObjectA has a NetworkView... ObjectA checks ObjectB state to send it over network via Serialize. ViewID numbers are the same for the same object on every clients. I'm lost. Feel like I will cry :)

avatar image asafsitner · Aug 28, 2012 at 01:48 PM 0
Share

I see. Who owns ObjectA?

The BitStream will only return true to isWriting on the object that belongs to the owner of the viewID.

avatar image asafsitner · Aug 28, 2012 at 09:19 PM 0
Share

You can just post your solution as answer and accept it, there's no need to delete the thread. Someone in the future might run into a similar problem.

avatar image lvictorino · Aug 31, 2012 at 05:32 PM 0
Share

@asafsitner I have re-opened it here : http://answers.unity3d.com/questions/311184/client-to-client-serialization.html because I thought it was working but apparently not. I want to cry :/

avatar image asafsitner · Aug 31, 2012 at 05:36 PM 0
Share

Cheer up! Synchronizing stuff over the network correctly is what kept me busy in the last year or so, and I still mess it up occasionally. :)

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

game objects and meshes not appearing 1 Answer

Get NetworkPlayer from ViewID 1 Answer

Photon - How to name a player? 0 Answers

networkview.RPC not accessible in unity 5.4 1 Answer

Username not showing on other players head?? 0 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