Ok, I’m making a networked multiplayer game. I made a simple test project replicating the problem I am experiencing and you can download it on the link below, it is 85 mb. Mainly take a look at the script TestOnSerializeNetworkView, and the Player prefab. Look how I have it set up, and please tell me WHY OnSerializeNetworkView in the script I just mentioned is definitely not recieving data, and probably not even sending it.
I really think everything is setup correctly, and all the reference material I’ve read indicates that. But yet it doesn’t work. I’ve tried everything I can think of for many hours, no results.
Thanks for any help. All I want to happen is for the variable I’m sending in OnSerializeNetworkView to be recieved by all the “clone” objects of itself across the network, but it’s not working.
http://www.mediafire.com/?6o3feckk225aqrf
Only the client / server that owns the view can write to the bitstream, writes from all other sides is ignored.
so ensure that whoever instantiates the prefab with the view etc is also the one that writes
Yea I’m aware of that and that is how it works. So there is another problem. The download link will be edited in soon as it’s done uploading.
Btw to test what I’m talking about you will have to open 2 instances of the game. A server and a client.
the only other problem is that there is no matching counterpart on the other end (ie same network view).
ok its one of two things. the other things is if you use onserializenetworkview, ensure to always write the same amount of data. you can not send more or less depending on your need cause the buffer length is set once and never again changed for this view
There is a matching counterpart (or “clone” as I call it). It was made with Network.Instantiate and I’ve seen it in action. So it’s not that…
I don’t understand the second potential problem you mentioned, take a look at my script called TestOnSerializeNetworkView if you can, and then tell me if I am indeed doing what you mentioned about the “writing the same amount of data” thing.
[Direct link to script]–> http://www.mediafire.com/?x73b1k4u9rdjhft
Its your code that is causing it.
You set the network sync state to off, if you do that the only networking happening any further on this view is RPC, OnSerialize… is not even called anymore
You need to use one of the syncing sync states, be it delta or reliable.
Just to be clear, having a NetworkView already attached to the Player isn’t enough to send data from the Player’s scripts using OnSerializeNetworkView right? I need to make a new network view in every script that is to be observed (as is currently the case in the TestOnSerializeNetworkView script I showed you, it observes the script it is created in, not the Player game object)? (Meaning by the time this game is complete the player would have dozens of NetworkViews on them, which seems ridiculous)
Either way it still doesn’t work, here is the script now: http://www.mediafire.com/?3bl8y3l117q5b7r
The state synch is now on reliable delta compressed.
I might be wrong on that given that the setup etc outside of the script is unknown but remove the “AddNetworkView” and add it to the prefab itself. there is a good chance that this is actually really unlinking them from each other on the various ends as each client and the server adds it themself this way.
you could make the various nodes output the viewid and see if they are the same to be sure there before removing the line.
or add a debug.log to the write case and see if all clients and server fire the log write.
also you mentioned that oyu use network instantiate: normally if the view were attached, then only the client / server that calls the Network.Instantiate will write afterwards - but given this script is present like this on all end, at least one end will write
the might be wrong here comes from the fact that I never added it like this, I always have it on the prefab and then handle the view id allocation as needed
There is already a NetworkView attached to the Player prefab, and it works because I can run two instances of the game and see both player’s movement on either side. After the Player is instantiated, it ends up having 2 NetworkViews, the one on the prefab and the on that script I showed you adds. The NWV on the Prefab is set to observe the Player game object, but the NWV created in the script is set to observe that same script (I was told I had to do this to send data from that script using OnSerialize, and that just having a NetworkView on the actual Game Object was not good enough to do so). But even if I don’t bother adding the second NetworkView, OnSerializeNetworkView still doesn’t work.
I’ve tested it and it is sending the messages, but the other instances of itself are not recieving it.
The NetworkView IDs must already be the same because movement is synchronized across all instances.
I attached a script that displays the NWV IDs of all gameObjects and they all match across all instances of the game, as suspected.
If you download my project files maybe you’ll see what I’m talking about better.