Description
Description
AnticipatedNetworkTransform breaks InLocalSpace configuration.
Reproduce Steps
- Add AnticipatedNetworkTransform component to any GameObject with NetworkObject.
- Enable InLocalSpace in inspector inside AnticipatedNetworkTransform component.
- Start a NetworkManager in Host mode.
- Spawn this NetworkObject by any method.
- Check inspector, you can find InLocalSpace in inspector become unchecked.
Actual Outcome
InLocalSpace of AnticipatedNetworkTransform is reset to false and transform is synced in world space.
Expected Outcome
InLocalSpace should keep checked in inspector and transform should be synced by local space not the world space.
Screenshots
No need.
Environment
- OS: Windows 11
- Unity Version: 2022.3.10f1
- Netcode Version: 1.9.1
- Netcode Commit: 7d27c51
Additional Context
Here is the source code of how AnticipatedNetworkTransform override the OnNetworkSpawn:
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
m_OutstandingAuthorityChange = true;
ApplyAuthoritativeState();
ResetAnticipatedState();
m_AnticipatedObject = new AnticipatedObject { Transform = this };
NetworkManager.AnticipationSystem.RegisterForAnticipationEvents(m_AnticipatedObject);
NetworkManager.AnticipationSystem.AllAnticipatedObjects.Add(m_AnticipatedObject);
}
The line call ApplyAuthoritativeState()
will use the initial data of m_LocalAuthoritativeNetworkState
to override the local configuration like InLocalSpace
, which is false by default. Please check whether it's reasonable to call ApplyAuthoritativeState in OnNetworkSpawn.
Also found those code doesn't check InLocalSpace
and directly set the world space position:
public void AnticipateMove(Vector3 newPosition)
{
......
transform.position = newPosition;
......
}
public void AnticipateState(TransformState newState)
{
......
var transform_ = transform;
transform_.position = newState.Position;
transform_.rotation = newState.Rotation;
transform_.localScale = newState.Scale;
......
}
Rotation has the same problem, please review the code of whole class, there are many other places has the same issue.