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 pyjamads · Aug 28, 2014 at 05:35 PM · networknetworkviewonserializenetworkview

OnSerializeNetworkView with multiple clients, doesn't work when syncing a float?

I'm using network views to communicate between multiple clients and a server, and I've come across an issue.

The problem is that OnSerializeNetworkView only receives a value when sending from one client and receiving it on the server, other clients don't receive the value, when sending a Float. However if I change the OnSerializeNetworkView to send a Vector3, every client and the server receives updates from everyone else.

I'm using Network.Instantiate to instantiate a prefab, containing this script below and a networkView, that has the script as Observed and I've tested both using Reliable and Unreliable.

I'm not really sure what the problem is, but I've found a few others asking about problems like mine, and I'm wondering if anyone has any idea how to fix it.

I've boiled it down to this code snippet right here:

 // Update is called once per frame
     void Update () 
     {
         if (networkView.isMine)
         {
             Value += Time.deltaTime;
             transform.position = new Vector3(Mathf.Sin(Value), transform.position.y, transform.position.z);
         }
     }
 
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
         //float data = 0f;
         Vector3 data = Vector3.zero;
         if (stream.isWriting)
         {            
             //data = Value;
             data = transform.position;
             stream.Serialize(ref data);
         }
         else
         {
             if (networkView.isMine == false)
             {
                 stream.Serialize(ref data);
 
                 //transform.position = new Vector3(Mathf.Sin(data), Mathf.Cos(data), 0);
                 transform.position = data;
             }
         }
     }

This example works when I use the current code, but when I use the code in the //comments then it doesn't work.

Comment
Add comment · Show 2
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 ExtremePowers · Aug 28, 2014 at 07:04 PM 0
Share

It might be because you are declaring an float and a gameobject with the same name. So you should get some type issues. Hope this helps :)

PS. Do you get any errors?

avatar image pyjamads · Aug 28, 2014 at 08:48 PM 0
Share

nope, that's not it, and no, I don't get any errors, neither on the server nor on the client...

And as I stated, it works using the same variable names, but sending a Vector3 ins$$anonymous$$d of a Float.

1 Reply

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

Answer by pyjamads · Aug 29, 2014 at 11:55 AM

I figured out my problem, the reason it behaved so differently between Vector3 and Float, was that the incoming value was never "stored" on the server, and apparently the was OnSerializeNetworkView works, is that all clients send their updates to the server, then the server deserializes, and then it writes out to all other clients.

problem and solution explained better here: client-to-client-serialization problem

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What is Send rate? 1 Answer

Client to client Serialization 1 Answer

Can OnSerializeNetworkView Call in the client by Writing mode? 0 Answers

Can you tell OnSerializeNetworkView who the owner is? 3 Answers

texture in networked game 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