Skip to content

AnticipatedNetworkTransform breaks InLocalSpace configuration. #2972

Open
@leozzyzheng

Description

@leozzyzheng

Description

AnticipatedNetworkTransform breaks InLocalSpace configuration.

Reproduce Steps

  1. Add AnticipatedNetworkTransform component to any GameObject with NetworkObject.
  2. Enable InLocalSpace in inspector inside AnticipatedNetworkTransform component.
  3. Start a NetworkManager in Host mode.
  4. Spawn this NetworkObject by any method.
  5. 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.

Metadata

Metadata

Labels

priority:mediumThis issue has medium priority and may take some time to be resolvedstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions