public static void WriteGameObject(this NetworkWriter writer, GameObject value) { if (value == null) { writer.WriteUInt(0); return; } // warn if the GameObject doesn't have a NetworkIdentity, NetworkIdentity identity = value.GetComponent <NetworkIdentity>(); if (identity == null) { Debug.LogWarning($"NetworkWriter {value} has no NetworkIdentity"); } // serialize the correct amount of data in any case to make sure // that the other end can read the expected amount of data too. writer.WriteNetworkIdentity(identity); }