FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.32k stars 139 forks source link

Network animator not working properly #342

Closed starliner-admin closed 1 year ago

starliner-admin commented 1 year ago

Unity version:2022.2.8f1 Fish-Networking version:3.6.5hf0.Pro

Describe the bug Network animator with client authoritative turned on not syncing with other clients. Only updates state on local client and server.

To Reproduce Steps to reproduce the behavior: 1) set up fishnet 2) set up an animated object with an animator and controller with parameters and triggers 3) add network animator to the object 4) add a script to set trigger in network animator on input and add it to the prefab 5) set the prefab as player object 6) build 7) run three instances of the build 8) set one as both server and client 9) set others as clients 10) CASE 1:trigger animation on one of the clients with input CASE 2:trigger animation on the server client with input

Expected behavior CASE 1: Animation plays on the instance the trigger was set on and, on the server, not the third instance. CASE 2: Animation plays only on the server instance.

Demonstration Video https://user-images.githubusercontent.com/124756258/234179855-1e207266-6ee6-49ba-9460-fd4642a69466.mp4

FirstGearGames commented 1 year ago

Please try version 3.6.6 just release and let me know if problem persist.

starliner-admin commented 1 year ago

its still there

ymkim50 commented 1 year ago

I have the same problem, too. The animation looks fine on the server and host, but not on the clients.

Sonicboomcolt commented 1 year ago

Please try version 3.6.6 just release and let me know if problem persist.

Still happens in 3.6.7 Pro.

starliner-admin commented 1 year ago

Please try version 3.6.6 just release and let me know if problem persist.

Still happens in 3.6.7 Pro.

can confirm

Luzifix commented 1 year ago

Please try version 3.6.6 just release and let me know if problem persist.

Still happens in 3.6.7 Pro.

can confirm

can also confirm with 3.6.7 Pro

FirstGearGames commented 1 year ago

Here's a NetworkAnimator update to try. Note that the pro features are not in this bundle. NetworkAnimator_Update.zip

starliner-admin commented 1 year ago

Here's a NetworkAnimator update to try. Note that the pro features are not in this bundle. NetworkAnimator_Update.zip

It works. Thank you very much.

Luzifix commented 1 year ago

Now it works a litte bit but still buggy.

Standalone Client -> Host/Client is sync Horizontal and Jump. Forward is jump for 1 sec to 1 and after it drop to 0. Host/Client -> Client: Is completly not synced.

Here are my files to help investigation. Both are based on the FPS Land demo CharacterController.zip AnimatorController.cs.zip

        [Client(Logging = LoggingType.Off)]
        private void CheckInput(out MovementReplicateData movementReplicateData)
        {
            Vector2 movement = _gameplayActions.Movement.ReadValue<Vector2>();
            bool crouch = _gameplayActions.Crouch.triggered;

            Vector3 localDirection = new Vector3(movement.x, 0f, movement.y);
            Vector3 worldDirection = transform.TransformDirection(localDirection.normalized);

            // Update animator with movement direction.
            _animatorController.SetMovementDirection(movement);

            // Default to move action code.
            ActionCodes actionCodes = ActionCodes.None;

            // Jump action code.
            if (_inputJump)
                actionCodes |= ActionCodes.Jump;

            if (crouch)
                actionCodes |= ActionCodes.Crouch;

            float rotY = transform.eulerAngles.y;

            if (localDirection != Vector3.zero || rotY != _lastOwnerRotation)
                actionCodes |= ActionCodes.Move;

            _lastOwnerRotation = rotY;

            movementReplicateData = new MovementReplicateData(
                worldDirection,
                localDirection,
                rotY,
                actionCodes
            );
        }

image

FirstGearGames commented 1 year ago

Now it works a litte bit but still buggy.

Standalone Client -> Host/Client is sync Horizontal and Jump. Forward is jump for 1 sec to 1 and after it drop to 0. Host/Client -> Client: Is completly not synced.

Here are my files to help investigation. Both are based on the FPS Land demo CharacterController.zip AnimatorController.cs.zip

        [Client(Logging = LoggingType.Off)]
        private void CheckInput(out MovementReplicateData movementReplicateData)
        {
            Vector2 movement = _gameplayActions.Movement.ReadValue<Vector2>();
            bool crouch = _gameplayActions.Crouch.triggered;

            Vector3 localDirection = new Vector3(movement.x, 0f, movement.y);
            Vector3 worldDirection = transform.TransformDirection(localDirection.normalized);

            // Update animator with movement direction.
            _animatorController.SetMovementDirection(movement);

            // Default to move action code.
            ActionCodes actionCodes = ActionCodes.None;

            // Jump action code.
            if (_inputJump)
                actionCodes |= ActionCodes.Jump;

            if (crouch)
                actionCodes |= ActionCodes.Crouch;

            float rotY = transform.eulerAngles.y;

            if (localDirection != Vector3.zero || rotY != _lastOwnerRotation)
                actionCodes |= ActionCodes.Move;

            _lastOwnerRotation = rotY;

            movementReplicateData = new MovementReplicateData(
                worldDirection,
                localDirection,
                rotY,
                actionCodes
            );
        }

image

What types aren't working? Eg trigger float int. And to which side are they not working? Eg server to client, clientHost to clients, client to server to clients. Given you have client auth checked is owner making changes?

Luzifix commented 1 year ago

What types aren't working? Eg trigger float int.

Floats and trigger

And to which side are they not working? Eg server to client, clientHost to clients, client to server to clients.

  • Standalone Client to Host+Client sync Horizontal Movement (float) and Jump (trigger) Vertical Movement (also float) only sync for one tick and after it drop to 0

Its like in this Video from @starliner-admin: https://user-images.githubusercontent.com/124756258/234179855-1e207266-6ee6-49ba-9460-fd4642a69466.mp4

Given you have client auth checked is owner making changes?

The NetworkAnimator is Client Authoritative. The Network Transform is Server Authoritative

starliner-admin commented 1 year ago

https://user-images.githubusercontent.com/124756258/235552883-f9b9082a-6d64-42b6-8996-e183b929da63.mp4

it works fine for me. All the characters are client authoritative. Syncs everything bool, trigger and floats.

Luzifix commented 1 year ago

it works fine for me. All the characters are client authoritative. Syncs everything bool, trigger and floats.

@starliner-admin can you maybe share some example how you Implement it?

FirstGearGames commented 1 year ago

What types aren't working? Eg trigger float int.

Floats and trigger

And to which side are they not working? Eg server to client, clientHost to clients, client to server to clients.

* Standalone Client to Host+Client sync Horizontal Movement (float) and Jump (trigger) Vertical Movement (also float) only sync for one tick and after it drop to 0

* Host+Client to Client: Is completly not synced

Its like in this Video from @starliner-admin: https://user-images.githubusercontent.com/124756258/234179855-1e207266-6ee6-49ba-9460-fd4642a69466.mp4

Given you have client auth checked is owner making changes?

The NetworkAnimator is Client Authoritative. The Network Transform is Server Authoritative

I tested all value types + trigger. two clients + server, two clients + clientHost. Client auth, server auth, and server auth + send to owner. All tests passed.

If the value is synchronizing but then resetting you're probably changing the value locally by mistake.

I'll be closing this out upon release of 3.6.8. If you find there is a bug via help channel please feel free to re-open.

Luzifix commented 1 year ago

Can you maybe add a example in 3.6.8 how to use the NetworkAnimator correctly?

starliner-admin commented 1 year ago

it works fine for me. All the characters are client authoritative. Syncs everything bool, trigger and floats.

@starliner-admin can you maybe share some example how you Implement it?

My scripts are NetworkBehaviour instead of monobehaviour and I destroy my script on other clients so that the animator modifications I make only happen from the owner client

public override void OnStartClient()
    {
        base.OnStartClient();
        if(!IsOwner)
        {           
            Destroy(this);
            return;
        }
     }

Alternatively, u can check IsOwner flag before setting animator values.

private void Update()
        {
            if(IsOwner){
            _animator.SetFloat(HORIZONTAL_HASH, _movementDirection.x);
            _animator.SetFloat(FORWARD_HASH, _movementDirection.z);
            _animator.SetFloat(PITCH_HASH, _pitch);
           }
        }
starliner-admin commented 1 year ago

oops sorry I misclicked.

ymkim50 commented 1 year ago

In my case Fish-Net 3.6.9 fixed this issue. I was using CSP.

starliner-admin commented 1 year ago

this is fixed so im closing this