I have a server/client setup where the server spawns some NPC's with Code (CSharp): NetworkServer.Spawn(obj); In the enemy controller script I have Code (CSharp): public override bool OnSerialize(NetworkWriter writer, bool initialState) { //Debug.Log("Send enemy update"); writer.Write(transform.position); writer.Write(transform.rotation); return true; } public override void OnDeserialize(NetworkReader reader, bool initialState) { //Debug.Log("Receive enemy update"); enemyNewPos = reader.ReadVector3(); enemyNewRot = reader.ReadQuaternion(); } to sync some positions, this all works fine if I have SetDirtyBit(1u); in the Update function (Dunno if this is correct). Problem is now I want to sync the name of the NPC. The name of the NPC works on the server, but it won't sync to the clients with: Code (CSharp): [SyncVar] public string enemyName; The string stays empty when I look at the NPC on the client... Does anyone know whats the problem here?
You can not use SyncVar and overridden Serialize function simultaneously (see the 'Custom Serialization Functions' section) . Either add the serialization code for the name to the functions, or split the code in multiple components (which, to be honest, seems like a good idea anyway judging from the information you provided)