Description
Describe the bug
Prefab handlers are never called on the server. The HandleNetworkPrefabDestroy
method is never being run. This is the case because the INetworkPrefabInstanceHandler
expects that HandleNetworkPrefabSpawn
was called on the object which is not the case on the server where the object has to be created manually.
This just silently fails and does not throw an exception.
To Reproduce
Steps to reproduce the behavior:
- Run any scene which uses a prefab handler such as a pooling script as a server
- Set a breakpoint on
HandleNetworkPrefabDestroy
. - Breakpoint gets never hit. When the object gets despawned it doesn't run destroy or the prefab handler just nothing happens
Actual outcome
Silent fail.
Expected outcome
Prefab handlers work on the server.
Environment (please complete the following information):
- OS: [e.g. Windows 10]
- Unity Version: [e.g. 2019.1]
- MLAPI Version: develop
- MLAPI Commit: c25821d
Additional context
The problem is the following on NetworkPrefabHandler
:
The m_PrefabInstanceToPrefabAsset
gets propagated in HandleNetworkPrefabSpawn
. On the server when I manually take an object from the pool and call spawn on it this function is never run.
I think to avoid this in the future this should be:
if (m_PrefabInstanceToPrefabAsset.ContainsKey(networkObjectInstanceHash))
{
// whatever
}
else
{
throw new InvalidOperationException("PrefabHandler: Failed to despawn NetworkObject, this should never happen.")
}