- Home /
OnSerializeNetworkView not doing anything
My code can be found here. Everything works fine except when I am trying to Network my game, the two Objects can see eachother but whenever you move your GameObject it only moves on your screen, not the other person's screen which, as far as I am aware, is what OnSerializeNetworkView handles.
But it seems that the function in my code does not even get called. At no point in time during the playing of my game do I see any of the Debug messages in the console, which is the weird thing about it. It seems the entire OnSerializeNetworkView function is not even being called. Am I supposed to call it manually, in the Update() function or something? I was under the impression is was called automatically by Unity.
Answer by Kryptos · Jan 28, 2012 at 12:45 AM
According to the documentation (http://unity3d.com/support/documentation/Components/class-NetworkView.html) you need to set observed to the script containing OnSerializeNetworkView().
This is the most important thing you need to do, to make OnSerializeNetworkView to be called.
Also keep in $$anonymous$$d that only the owner of the NetworkView's NetworkViewID does send information. All other peers just receives data. The owner is the peer that created the NetworkViewID. If you used Network.Instantiate to create the object, the client that called that function is the owner and the only one that can send updates to the others.
That worked! I have an empty GameObject that holds the object that moves, so I changed the observed and it worked perfectly. Thank you $$anonymous$$ryptos!
Answer by senad · Jan 27, 2012 at 10:48 AM
Did you attach a NetworkView component to your gameobjects? Did you set it up correctly?
If you set it up to synch your transform, it will synch the position without you writing the serialization code yourself, too.
This tutorial helped me a lot to understand the unity multiplayer mechanics: http://download.unity3d.com/support/resources/files/MultiplayerTutorial.pdf
I have the State Synchronization set to "Reliable Delta Compressed", which is what I assume it is supposed to be.
Your answer
Follow this Question
Related Questions
Unity3d Network - Cant See Connected Players 3 Answers
Can you tell OnSerializeNetworkView who the owner is? 3 Answers
texture in networked game 2 Answers
character controller problem on network 0 Answers
zombie network spawn! help" 0 Answers