NetworkBehaviour.OnDeserialize() does not get called on player prefabs

While OnSerialize() is called, I cannot see any calls to OnDeserialize() on my player prefabs. I tried overriding both methods and setting a breakpoint inside them. I tried on both local client and locan server.

What I basically need is a way to create a custom spawning code for my .isLocalPlayer = false objects (I already know how to custom spawn isLocalPlayer = true objects). I thought I can add extra information that i need (it is netId-s of GameObject-s the scripts on my player prefab are referencing) into the writer in OnSerialize() and read it in OnDeserialize() but the latter never gets called on any peer.

Hey man :slight_smile:
As a note, I would imagine that you are running on the unity editor as host.
The thing is that when you spawn as a client, being the spawnER you should ‘know’ what the object looks like, so it gets OnSerialise() such that the server (as one of the spawnEEs) needs to determine its state. As a server you dont actually need to deserialise the object, just store it for when other player connects and need to copy the object so its in the same state as the server, but it woul never return to the spawnER with an OnDeserialise call

Not sure what the design structure is, but as a few ways to help see whats happening

  1. Build the project, and on the built version start as host, and inside the unity editor start as client
  2. Alternatively, run SetDirtyBit(1) in an Update(), this registers the object needs an ‘update’ and triggers OnSerialise(…, false) and see what pulls out with this

Note however that whatever functionality you are trying to pull really shouldnt be handled in an OnDeserialise as the intent is to send the changes moreover implement them (Think how you would for example Foo(bool) {doSomeThing(bool); CmdFoo(bool);} for this exact same reason)

Therefore you could always try and test this by implementing in a function and calling via OnDeserialise AND Awake (for eg)