Controls when and how the Animator component updates animations.
Use the AnimatorUpdateMode
enum to control the timing animation updates. The timing of animation updates can affect how animations sync with your game's logic and physics.
Each mode affects how animations behave and interact. Select the mode that aligns with your game's needs to avoid issues like skipped frames or desynchronization.
Additional resources: Animator, Time, FixedUpdate, Animator.updateMode and FixedUpdate.
// This script demonstrates changing the Animator update mode when pausing the game. // Attach this script to a GameObject with an Animator component. using UnityEngine; public class PlayerController : MonoBehaviour { private Animator animator; private bool isGamePaused = false; void Awake() { animator = GetComponent<Animator>(); if (animator == null) { Debug.LogError("Animator component not found!"); return; } } void Start() { // Set initial animator update mode to Normal for regular gameplay animator.updateMode = AnimatorUpdateMode.Normal; } void Update() { // Toggle pause with the "P" key if (Input.GetKeyDown(KeyCode.P)) { isGamePaused = !isGamePaused; HandlePauseState(isGamePaused); } // Handle player movement input if the game is not paused if (!isGamePaused) { HandleMovement(); } } private void HandleMovement() { // Basic movement logic float move = Input.GetAxis("Horizontal"); animator.SetFloat("Speed", Mathf.Abs(move)); // Additional Movement logic can be added here } private void HandlePauseState(bool pause) { if (pause) { animator.updateMode = AnimatorUpdateMode.UnscaledTime; Time.timeScale = 0f; // Pause the game } else { animator.updateMode = AnimatorUpdateMode.Normal; Time.timeScale = 1f; // Resume the game } Debug.Log("Game paused: " + pause + " - Animator update mode set to: " + animator.updateMode); } }
Additional resources: Animator, Time, FixedUpdate, Animator.updateMode.
Normal | Animator updates in the Update loop, aligning with the main game loop for standard animation processing. |
Fixed | Animator updates in the FixedUpdate loop. This is ideal for physics-driven animations that require frame rate independence. |
UnscaledTime | Animator updates independently of Time.timeScale, maintaining real-time animation progression. |