-
Notifications
You must be signed in to change notification settings - Fork 458
Description
Description
NetworkTransform Teleport() can fail because IsTeleportingNextFrame gets set back to false by CheckForStateChange()
Settings for prefab being teleported:
NetworkObject
SyncOwnerTransformWhenParented = false
AllowOwnerToParent = true
NetworkTransform
Authority Mode = Owner
Switch Transform Space When Parented = true
In Local Space = true
Host Harry with one additional Client Charlie.
Harry spawns the prefab with SpawnWithOwnership() and makes Charlie the owner.
It spawns on Charlie's client and NetworkTransform.OnNetworkSpawn() calls SetState() -> SetStateInternal() -> CheckForStateChange()
CheckForStateChange() sees that InLocalSpace != networkState.InLocalSpace and so it sets IsTeleportingNextFrame=False. But also, networkState.InLocalSpace is set to false rather than true because at the moment of spawning the transform.parent is null:
networkState.InLocalSpace = SwitchTransformSpaceWhenParented ? transform.parent != null : InLocalSpace;
Still on the same frame as OnNetworkSpawn(), Charlie calls Teleport() -> SetStateInternal() which sets IsTeleportingNextFrame = true but then calls CheckForStateChange(). Again, it is still true that InLocalSpace != networkState.InLocalSpace, so it sets IsTeleportingNextFrame=False!
When TryCommitTransform runs, IsTeleportingNextFrame is false. The Teleport does not happen.
Environment
OS: Windows 11
Unity Version: 6000.1.3f1
Netcode Version: 2.4.2
Netcode Topology: Client-Server