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 SirMacJefferson · Jul 22, 2013 at 08:52 PM · networkviewonserializenetworkviewbitstream

Mysterious OnSerializeNetworkView calls with an invalid NetworkMessageInfo.sender

Hey guys,

I'm making an online game with a client-server relationship (clients must reach each other through the server).

I have a NetworkView on each client, observing their Player scripts. I'm pretty darn sure they're set up properly, with all the ID's and owners as they should be. The clients allocate view IDs for their own NetworkViews, and thus they are the 'owner' of the NetworkView.

However, my server's OnSerializeNetworkView method is getting called constantly, and the BitStream has 'isWriting' set to true. As far as I know, the server should never have to write to the stream, because the only NetworkView it has that it actually 'owns' is one that has State Synchronization off and the Observed property set to None (because it's used for RPCs only).

The strange thing is, when the clients are supposed to be sending data over their network views, the server's stream has 'isReading' set to true. The only time 'isWriting' is set to true is when I get these weird calls that I can't explain.

I used Debug.Log to find the NetworkPlayer of the players sending these calls. I run tests with the server and 2 clients; the server's NetworkPlayer is 0, the clients are 1 and 2.

When I use Debug.Log on the NetworkMessageInfo.sender of these strange calls that have 'isWriting' set to true, I get -1.

I don't understand how I'm getting these OnSerializeNetworkView() calls with a NetworkPlayer that doesn't even exist sending them.

For example, if I ran this simple code on my server:

 void OnSerializeNetworkView(BitStream stream,NetworkMessageInfo info)
 {
     if (stream.isReading)
     {
         Debug.Log("Reading with a sender of " + info.sender);
     }
     if (stream.isWriting)
     {
         Debug.Log("Writing with a sender of " + info.sender);
     }
 }

...then the only time the info.sender value is -1 would be when the stream is writing. The value would always be 1 or 2 when it's reading.

I just don't understand why I'm getting these calls. My server should never be writing to any of the streams, right? I've read multiple times while searching around that only the owner of the NetworkView can write to the stream, and all the others read from it. I'm sure, from many tests and Debug.Log() calls, that the clients own the NetworkViews and their ID's, not the server. So how come the server is writing to these strange, mystery calls?

Any help would be greatly appreciated, and if you need more information, please let me know.

Thank you!

Comment
Add comment · Show 8
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 bety · Jul 24, 2013 at 02:52 AM 0
Share

I have a same problem... if you solve that probem, Would you Help me? Thank...!

avatar image Benproductions1 · Jul 24, 2013 at 05:25 AM 0
Share
  • reffers to self. If you want to for instance check wether the sender of an RPC is yourself, you can check for wether the the sender.ToString() == "-1"

avatar image SirMacJefferson · Jul 24, 2013 at 03:39 PM 0
Share

That's odd...why would the server be receiving calls from itself? Also, why not just use the NetworkPlayer of the server (which is 0 in my case), ins$$anonymous$$d of -1?

avatar image Benproductions1 · Jul 24, 2013 at 10:43 PM 0
Share

On any local mashine (`Network.player`) the "id" is always = -1. The server, on the server is -1. The server on the clients is always 0. Other clients on each singular client don't exist.

 Network.connections

On the server contains all the client,
On the clients contains only the server.

The server could be recieving calls from itself, by using RPC$$anonymous$$ode.All, which includes the local client.

avatar image SirMacJefferson · Jul 25, 2013 at 12:10 AM 0
Share

Ah, I see. Thank you for the explanation :) How could RPCs from itself trigger the OnSerializeNetworkView() method?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jamora · Jul 25, 2013 at 04:47 PM

When a NetworkView observes a Component, the OnSerializeNetworkView of the Component is called Network.sendRate (default: 15) times per second. Conversely, if a networkView does not observe a Component, its OnSerializeNetworkView is not called.

Only the owner of the object can have isWriting true. The reason sender == -1 when isWriting == true, is because you don't have a sender when writing something, because technically you can't be writing and sending at the same time. Consider this question, "I'm writing this letter, who is its sender?"

Back to the ownership issue... You can check who the owner of the networkview is by DebugLogging networkView.owner. If inside if(stream.isWriting) netviewView.isMine debugs as false, you need to submit a bug report.

Comment
Add comment · Show 2 · 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 Benproductions1 · Jul 25, 2013 at 10:39 PM 0
Share

Good answer +1

avatar image ngocgiang · Jul 09, 2014 at 04:59 AM 0
Share

Network.sendRate => you save my life today :D

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

18 People are following this question.

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

Related Questions

How does BitStream work? 1 Answer

Virtual Whiteboard stream writing problem 1 Answer

OnSerializeNetworkView to only one recipient 2 Answers

State Synchronization question regarding OnSerializeNetworkView 2 Answers

Problem with networkview script - A gameobject who doesn't own the networkview is writing in the stream? 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