Hi, We are making a multiplayer VR game with Netcode for GameObjects where the host is always a computer. This means that the host does not need a NetworkPlayerPrefab to be spawned for him.
I tried fixing this by adding a script to the NetworkPlayer that detects if its the host and disables the gameobject in case it is.
public class DisableHost: NetworkBehaviour
{
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
ulong hostId = NetworkManager.Singleton.LocalClientId;
// Note that owner always spawns network objects
ulong networkObjOwner = NetworkObject.OwnerClientId;
if (hostId == networkObjOwner)
{
// Default is true
gameObject.SetActive(false);
}
}
}
However, in doing so I have created the following error for my clients (VR headsets)
[Netcode] NetworkHead threw an exception during synchronization serialization, this NetworkBehaviour is being skipped and will not be synchronized! (same for NetworkLeftHand and NetworkRightHand)
Strangely enough when I remove the script everything works as expected (Besides the host having a NetworkPlayer ofcourse…), I have a hacky solution to this problem already, but I am more Curious as to why this is happening in the first place.
When I change my script to the following:
public class DisableHost: NetworkBehaviour
{
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
// Nothing to see here
}
}
It actually gives the error again! And at this point I am lost as to what is actually happening here. It only works when the script is not attached to it!