com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

NetworkAnimator trigger on non-base layer ignores transition duration on remote clients

Open GabrielBigardi opened this issue 5 months ago • 2 comments

Description

When using Unity's Owner Network Animator to synchronize a trigger-based animation on a non-base Animator layer, the animation plays instantly on remote clients without respecting the configured transition duration. This occurs despite the transition settings being correctly configured in the Animator Controller. Replacing the trigger with a manual CrossFade() call resolves the issue, suggesting the transition timing is being skipped or ignored on remote clients.

Reproduce Steps

  1. Create an Animator Controller with a second layer (non-base) that contains a transition from an empty state to a animation triggered by a trigger parameter (a "Slash" for example).
  2. Set the transition duration (e.g., 0.1 seconds) and ensure it's not instantaneous.
  3. Attach the Animator to a NetworkObject with Owner Network Animator enabled.
  4. On the owner client, call animator.SetTrigger("Slash") to trigger the animation.
  5. Run 2 clients using Multiplayer Play Mode or similar, observe that even tho locally it respects the transition, on other clients it doesnt.

Actual Outcome

On the owner client, the animation plays smoothly with the expected transition duration. On remote clients, the animation plays instantly without any transition, ignoring the configured duration. This creates a visual inconsistency between the local and remote player.

Expected Outcome

The animation should transition with the same duration and blend settings across all clients, including non-owner clients, maintaining consistency with how it appears on the owner client.

Screenshots

N/A (issue is visual and reproducible with animation watching).

Environment

  • OS: Windows 11
  • Unity Version: 6000.0.41f1
  • Netcode Version: 2.4.0
  • Netcode Commit: I have no clue
  • Netcode Topology: Client-Server with Distributed Authority

Additional Context

Replacing the SetTrigger("Slash") call with a direct animator.CrossFade("Slash", 0.1f, 1) on all clients via a ClientRpc fixes the issue and respects transition durations consistently across clients. This suggests that NetworkAnimator's trigger syncing doesn't apply transition settings properly for additional Animator layers. I haven't tested it with base-layers or non-trigger variables to check, it's completely possible that it happens anyway.

GabrielBigardi avatar Jun 09 '25 18:06 GabrielBigardi

@GabrielBigardi Could you submit a bug for this within the Unity editor (which will include your project) and then post the IN number you receive in an email here? This will speed up the process to investigate this issue.

NoelStephensUnity avatar Jun 18 '25 16:06 NoelStephensUnity

@NoelStephensUnity Hey, sorry to keep you waiting, i just created a new project specifically made to replicate the issue and submitted the bug report from the editor. The IN number i received for the report is: 105445

GabrielBigardi avatar Jun 18 '25 22:06 GabrielBigardi

Hiya @GabrielBigardi,

You should receive a notification for IN-105445 that includes a link to an adjusted version of your project along with a video of what it looks like with the minor adjustments.

There were two issues with your NetworkAnimator usage and configuration:

  • I believe you wanted to use the owner (client) authoritative mode which still requires you to create a derived owner authority class and/or an extended version of NetworkAnimator:
  • When using triggers, you are required to invoke the NetworkAnimator.SetTrigger method in order for trigger events to be properly synchronized. Setting the trigger directly on the Animator component will only synchronize the "toggled" bool state of the trigger (i.e. enabled when triggered but reset by the next frame which sends two property state updates back to back) but will not handle synchronizing the trigger event's transition and/or changes to the transition properly.

Let me know if the modifications made in your project resolve the issue you were experiencing?

For reference purposes, here is the ExtendedNetworkAnimator component I added to your project:

using Unity.Netcode.Components;

public class ExtendedNetworkAnimator : NetworkAnimator
{
    public NetworkTransform.AuthorityModes AuthorityMode;

    protected override bool OnIsServerAuthoritative()
    {
        return AuthorityMode == NetworkTransform.AuthorityModes.Server;
    }
}

We already are planning to do a QOL pass on NetworkAnimator and things like the above will come already integrated so you can just add the NetworkAnimator component, configure it, and done...until then you still need to use something like the above to configure the NetworkAnimator's authority mode.

And as opposed to invoking Animator.SetTrigger you want to invoke NetworkAnimator.SetTrigger. As a side note, you can also access Animator directly by using NetworkAnimator.Animator.

NoelStephensUnity avatar Jul 07 '25 23:07 NoelStephensUnity

Hi, thanks for the reply, i've replied in there but i will also reply in here just to make sure.

I can’t download the files to test them out — they’re being listed as “not found,” and the download button is greyed out. I haven’t tested NetworkAnimator.SetTrigger yet, but it’s a bit confusing since NetworkAnimator is supposed to synchronize all the animator variables and states.

I understand this might be because setting a trigger happens in a single frame and may not be synchronized properly for that reason. However, when testing this on layer 0 of the animator, it does seem to synchronize correctly.

I think a good approach for future updates to NetworkAnimator would be to send an RPC (or something similar) whenever SetTrigger is called. It’s confusing having to manage both the Animator and the NetworkAnimator. It would be much better if NetworkAnimator could listen for SetTrigger calls and automatically handle the RPC, making the component more plug-and-play — similar to how NetworkTransform works.

So I’d like to leave this as a suggestion for the upcoming overhaul of the NetworkAnimator component.

GabrielBigardi avatar Jul 08 '25 17:07 GabrielBigardi

@GabrielBigardi The issue at hand is that there needs to be a trigger event sent in order to handle transitions properly as it states in the Animator trigger property documentation:

Image

NetworkAnimator does eventually send the trigger information via RPC in the following internal methods:

The two primary issues with your project were:

  • The NetworkAnimator was using the server authoritative version when you were using an owner authority model.
  • Animator.SetTrigger was being invoked instead of NetworkAnimator.SetTrigger.

I am currently in a conversation with our QA to determine why you can't download the links provided. If you want, I could post the adjusted project zip file here but I need your authorization to do that since this is a public thread.

NoelStephensUnity avatar Jul 10 '25 20:07 NoelStephensUnity

Hi, if you can share it here, that would be better. There's nothing in the project that can't be made public, the character is just a placeholder I generated using some AI.

GabrielBigardi avatar Jul 11 '25 20:07 GabrielBigardi

@GabrielBigardi

Here is the modified project:

IN-105445-Fix.zip

Here is the video showing the above project running with the adjustments to your project:

https://github.com/user-attachments/assets/278d8274-8632-4218-b06d-8b53057da57c

Let me know if this resolves your issue?

NoelStephensUnity avatar Jul 14 '25 17:07 NoelStephensUnity

@GabrielBigardi Just checking in to see if you had a chance to grab the above adjusted project and if the adjustments made to the project resolves your issues?

NoelStephensUnity avatar Aug 04 '25 13:08 NoelStephensUnity

Hi, apologies for the delay in getting back to you, it’s been some busy weeks. I’ve reviewed the project, and it successfully resolves the issues.

Thank you for your time and support!

GabrielBigardi avatar Aug 05 '25 23:08 GabrielBigardi