NetworkAnimator | Unity Multiplayer Networking (2024)

The NetworkAnimator component provides you with a fundamental example of how to synchronize animations during a network session. Animation states are synchronized with players joining an existing network session and any client already connected before the animation state changing.

  • Players joining an existing network session will be synchronized with:
    • All the Animator's current properties and states.
      • With exception to Animator trigger properties. These are only synchronized with already connected clients.
    • Any in progress transition
  • Players already connected will be synchronized with changes to Animator:
    • States
    • Transitions
    • Properties
      • NetworkAnimator will only synchronize properties that have changed since the earlier frame property values.
      • Since triggers are similar to an "event," when an Animator property is set to true it will always be synchronized.

NetworkAnimator can operate in two authoritative modes:

  • Server Authoritative (default): Server initiates animation state changes.
    • Owner's can still invoke NetworkAnimator.SetTrigger.
  • Client Authoritative: Client owners start animation state changes.

note

You need to use Unity.Netcode.Components to reference components such as NetworkAnimator.

Animator Trigger Property

The Animator trigger property type ("trigger") is basically nothing more than a Boolean value that, when set to true, will get automatically reset back to false after the Animator component has processed the trigger. Usually, a trigger is used to start a transition between Animator layer states. In this sense, one can think of a trigger as a way to signal the "beginning of an event." Because trigger properties have this unique behavior, they require that you to set the trigger value via the NetworkAnimator.SetTrigger method.

caution

If you set a trigger property using Animator.SetTrigger then this won't be synchronized with non-owner clients.

Server Authoritative Mode

The default setting for NetworkAnimator is server authoritative mode. When operating in server authoritative mode, any animation state changes that are set (triggers) or detected (change in layer, state, or any Animator properties excluding triggers) on the server side will be synchronized with all clients. Because the server initiates any synchronization of changes to an Animator 's state, a client that's the owner of the NetworkObject associated with the NetworkAnimator can lag by roughly the full round trip time (RTT). Below is a timing diagram to show this:

NetworkAnimator | Unity Multiplayer Networking (1)

In the above diagram, a client might be sending the server an RPC to tell the server that the player is performing some kind of action that can change the player's animations (including setting a trigger). Under this scenario, the client sends an RPC to the server (half RTT), the server processes the RPC, the associated Animator state changes are detected by the NetworkAnimator (server-side), and then all clients (including the owner client) are synchronized with the changed.

Server authoritative model benefits:

  • If running a plain server (non-host), this model helps reduce the synchronization latency between all client animations.

Server authoritative model drawbacks:

  • Hosts will always be "slightly ahead" of all other clients which may or may not be an issue for your project.
  • Client owners will experience a latency between performing an action (moving, picking something up, anything that causes an Animator state change).

Owner Authoritative Mode

Usually, your project's design (or personal preference) might require that owners are immediately updated to any Animator state changes. The most typical reason would be to give the local player with instantaneous visual (animation) feedback. To create an owner authoritative NetworkAnimator you need to create a new class that's derived from NetworkAnimator, override the NetworkAnimator.OnIsServerAuthoritative method, and within the overridden OnIsServerAuthoritative method you should return false like in the example provided below:

 public class OwnerNetworkAnimator : NetworkAnimator
{
protected override bool OnIsServerAuthoritative()
{
return false;
}
}

Looking at the timing for an owner authoritative NetworkAnimator, in the diagram below, you can see that while the owner client gets "immediate visual animation response" the non-owner clients end up being roughly one full RTT behind the owner client and a host would be half RTT behind the owner client.

NetworkAnimator | Unity Multiplayer Networking (2)

In the above diagram, it shows that the owner client has an Animator state change that's detected by the NetworkAnimator ( OwnerNetworkAnimator) which automatically synchronizes the server with the changed state. The server applies the change(s) locally and then broadcasts this state change to all non-owner clients.

Owner authoritative model benefits:

  • The owner is provided instant visual feedback of Animator state changes, which does offer a smoother experience for the local player.

Owner authoritative model drawbacks:

  • Non-owner clients lag behind the owner client's animation by roughly one full RTT.
  • A host lags behind the owner client's animation by roughly half RTT.

caution

The same rule for setting trigger properties still applies to owner clients. As such, if you want to programmatically set a trigger then you still need to use NetworkAnimator.SetTrigger.

Using NetworkAnimator

Using NetworkAnimator is a pretty straight forward approach with the only subtle difference being whether you are using a server or owner authoritative model.

info

NetworkAnimator is one of several possible ways to synchronize animations during a network session. Netcode for GameObjects provides you with the building blocks (RPCs, NetworkVariables, and Custom Messages) needed to create a completely unique animation synchronization system that has a completely different and potentially more optimized approach. NetworkAnimator is a straight forward approach provided for users already familiar with the Animator component and, depending upon your project's design requirements, might be all that you need.

Server Authoritative

If you decide you want to use the server authoritative model, then you can add a NetworkAnimator component to either the same GameObject that has the NetworkObject component attached to it or any child GameObject. In the below screenshot, you can see a network Prefab that houses two authoritative models. The NetworkAnimatorCube-Server GameObject has an Animator component, an AnimatedCubeController component (used for manual testing), and the NetworkAnimator component that has a reference to the Animator component.

NetworkAnimator | Unity Multiplayer Networking (3)

Owner Authoritative

If you decide you want to use the owner authoritative model, then (for example purposes) you would use your derived OwnerNetworkAnimator component as opposed to the default NetworkAnimator component like in the screenshot below:

NetworkAnimator | Unity Multiplayer Networking (4)

info

While it isn't advised to have different NetworkAnimator authoritative models "under the same root network Prefab GameObject, " you can have multiple children that each have their own Animator and NetworkAnimator all housed under a single NetworkObject and all use the same authoritative model. However, you should always consider the balance between performance (CPU or bandwidth consumption) and convenience/modularity.

Changing Animator Properties

For all Animator properties (except for triggers), you can set them directly via the Animator class. As an example, you might use the player's normalized velocity as a way to control the walking or running animation of a player. You might have an Animator float property called "AppliedMotion" that you would set on the authoritative instance (server or owner) like such:

public void ApplyMotion(Vector3 playerVelocity)
{
m_Animator.SetFloat("AppliedMotion", playerVelocity.normalized.magnitude);
}

For triggers you always want to use NetworkAnimator. One example might be that you use a trigger, called it " IsJumping, " to start a blended transition between the player's walking/running animation and the jumping animation:

public void SetPlayerJumping(bool isJumping)
{
m_NetworkAnimator.SetTrigger("IsJumping");
}
NetworkAnimator | Unity Multiplayer Networking (2024)
Top Articles
4 takeaways from the first presidential debate
Static text and static text in rule here. | Quest®
Use Copilot in Microsoft Teams meetings
Zabor Funeral Home Inc
Myexperience Login Northwell
Craigslist Mpls Mn Apartments
Practical Magic 123Movies
2024 Fantasy Baseball: Week 10 trade values chart and rest-of-season rankings for H2H and Rotisserie leagues
Wausau Marketplace
Www Thechristhospital Billpay
Wordscape 5832
Blog:Vyond-styled rants -- List of nicknames (blog edition) (TouhouWonder version)
This Modern World Daily Kos
Missed Connections Dayton Ohio
Chastity Brainwash
Comics Valley In Hindi
Best Uf Sororities
Vrachtwagens in Nederland kopen - gebruikt en nieuw - TrucksNL
Busted Newspaper Fauquier County Va
Dallas Mavericks 110-120 Golden State Warriors: Thompson leads Warriors to Finals, summary score, stats, highlights | Game 5 Western Conference Finals
Dragger Games For The Brain
67-72 Chevy Truck Parts Craigslist
Buying Cars from Craigslist: Tips for a Safe and Smart Purchase
How to Watch Every NFL Football Game on a Streaming Service
Jeff Nippard Push Pull Program Pdf
When Does Subway Open And Close
Hctc Speed Test
Prep Spotlight Tv Mn
Shiny Flower Belinda
Joann Fabrics Lexington Sc
Skepticalpickle Leak
Gesichtspflege & Gesichtscreme
How To Improve Your Pilates C-Curve
Culver's Hartland Flavor Of The Day
Tra.mypatients Folio
M3Gan Showtimes Near Cinemark North Hills And Xd
The Land Book 9 Release Date 2023
Final Exam Schedule Liberty University
Msnl Seeds
Philadelphia Inquirer Obituaries This Week
Jail View Sumter
301 Priest Dr, KILLEEN, TX 76541 - HAR.com
Ezpawn Online Payment
Sound Of Freedom Showtimes Near Lewisburg Cinema 8
Tunica Inmate Roster Release
Divinity: Original Sin II - How to Use the Conjurer Class
Juiced Banned Ad
Pike County Buy Sale And Trade
Myapps Tesla Ultipro Sign In
St Als Elm Clinic
Tyrone Unblocked Games Bitlife
Die 10 wichtigsten Sehenswürdigkeiten in NYC, die Sie kennen sollten
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 5828

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.