The UNetStaticUpdate method inside the NetworkIdentity class is marked as internal and static. It seems to be the “network tick” functionality (you can decompile the UnityEngine.Networking.dll engine to see how the networking classes work). So what exactly is calling this method? Is it some sort of native thread or just an object in native code? I was under the impression that all HLAPI classes were built on top of the low level API network functions?
Here’s UNetStaticUpdate in case you want to see it.
So if the comments in the code are correct this function seems to be called every frame. And given the lack of synchronisation primitives in NetworkIdentity when it loops over NetworkBehaviours, I think it is called from the same thread that calls every update functions.
Here is the comment that suggests it is called every frame. Here is the code in case the link becomes broken in the future:
void UpdateServerObjects()
{
foreach (var uv in objects.Values)
{
try
{
uv.UNetUpdate();
}
catch (NullReferenceException)
{
//ignore nulls here.. they will be cleaned up by CheckForNullObjects below
}
catch (MissingReferenceException)
{
//ignore missing ref here.. they will be cleaned up by CheckForNullObjects below
}
}
// check for nulls in this list every N updates. doing it every frame is expensive and unneccessary
if (m_RemoveListCount++ % k_RemoveListInterval == 0)
CheckForNullObjects();
}
This function is in NetworkServer, it’s called from NetworkServer.InternalUpdate which itself is called from NetworkServer.Update. The interesting comment is the one above the if for CheckForNullObjects.
I’d really be interested in finding out more on how this works, as it’s currently responsible for a very annoying timeout in my otherwise fully functional project. When the GearVR is not worn my UNET PC / Android system consistently times out because of it:
ServerDisconnected due to error: Timeout
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
Unfortunately, there seems to be absolutely no way of ensuring that the Android / GearVR stays connected to the UNET for more than 7 to 8 minutes when not worn - and I need it to just hold on for 20 mins. Very, very frustrating…