We're having this strange problem on Android only (didn't occur on PC/Mac/iOS). I currently don't have the code snippets or call stacks (I'm posting this at home and we're midnight here) but I can paste it tomorrow.
We're doing a racing game multiplayer demo right now. When all players loaded the network level, we instantiate all the cars. This is how we did the instantiation:
1) Suppose the code needs to spawn a car for the player to control. The program allocate a network ID for car driver animation, and another network ID for other car stuff.
2) the program then send the network IDs to all players including itself using RPC.
3) In the RPC, every player instantiates the car prefab (with no network view for either animation and other stuff).
4) Add a network view component to observe the car driver animation, and assign the animation network ID to the network view.
5) Then add a network view component to observe a MonoBehaviour script on the instantiated car, and assign the network ID to the network view.
The problem is that the game will then crash on the Android device after 5). It always crashes after the player's car on the Android device is instantiated, all the components are added, and even after some (I didn't check all of them though, but some definitely) of the Start() methods in the scripts attached to the car is called.
I checked the call stack and the pc crashes at an internal function which looks like this
Which looks like the code is attempting to send some packets to other players.
I remember going up the stack trace and found internal serialization function for animation. So the animation network view becomes very suspect. I then removed the animation network view code. The game still crashes at
but it changed to another overload that accepts Vector3 argument, which is the first variable to be serialized in other stuff. Then I removed it also, and the game can load successfully! (at the cost of being able to play :D)
We can of course use RPC only to do all the synchronization, but it still baffles me why OnSerializeNetworkView would crash. Are we using it the wrong way?
The post is quite long but I still hope someone could answer the question.
OK, the game didn't crash when I add Network View component when creating the prefab in the editor instead of adding it in code.
This must be some undocumented strange behavior... hope someone after me will see this and stop repeating the mistake, or maybe I'll send the bug report to Unity and let them fix it :)