You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A network spawned object as sync var, triggers a hook call when changed, but is not found or ready to use in hook code.
Start player host, spawn network object, have a sync var hook set this sync var object in player code.
Join via a second player, you can see the hooks called, but it is not usable in hooks code.
This only happens if object is network spawned (not set in scene), and with a late joining player. -
print("OnPickupChangedHook 1"); is called, but print("OnPickupChangedHook 2"); is not.
Adding a 1 frame delay works, example:
[SyncVar(hook = nameof(OnPickupChangedHook))]
public NetworkIdentity pickedUpNetworkObject;
void OnPickupChangedHook(NetworkIdentity _old, NetworkIdentity _new)
{
StartCoroutine(WaitForResult());
}
private IEnumerator WaitForResult()
{
// we use a delay, as network spawned objects may not be spawned in and ready, hooks get called very early
yield return new WaitForEndOfFrame();
print("OnPickupChangedHook 1" + pickedUpNetworkObject);
if (pickedUpNetworkObject)
{
print("OnPickupChangedHook 2" + pickedUpNetworkObject);
PickupResult();
}
else
{
print("OnPickupChangedHook 3");
DropResult();
}
}
The text was updated successfully, but these errors were encountered:
Describe the bug
A network spawned object as sync var, triggers a hook call when changed, but is not found or ready to use in hook code.
Start player host, spawn network object, have a sync var hook set this sync var object in player code.
Join via a second player, you can see the hooks called, but it is not usable in hooks code.
print("OnPickupChangedHook 1"); is called, but print("OnPickupChangedHook 2"); is not.
Adding a 1 frame delay works, example:
The text was updated successfully, but these errors were encountered: