Search Unity

Read Synchronized Flag on layer

Discussion in 'Animation' started by DDNA, Jan 18, 2017.

  1. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    I am writing some code that synchronizes two animators, in a general way.

    The problem I am running into is that if a layer is synchronized, the unity kicks up a warning.

    'Calling Animator.GotoState on Synchronize layer'

    Is there a way I can tell at run-time if an animator's layer is synchronized?
     
    futurlab_xbox likes this.
  2. Forberg

    Forberg

    Joined:
    Oct 27, 2018
    Posts:
    25
    Ran into the same problem, would like to know, if the i-th layer of an animator is a sync layer
     
    futurlab_xbox likes this.
  3. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    I too would like to know this. How can we avoid this error if we can't check for it?
     
    futurlab_peterh likes this.
  4. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Is no one working on Mecanim anymore?

    This generates a bogus error that has no effect. Any further error that doesn't get logged is blamed on this message. Can we just shut it off?
     
    futurlab_peterh likes this.
  5. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I ran into the same thing in a system that tries to reset all layers to their default state. Ended up needing to make an array that the user has to use to manually specify which layers to reset, which is annoyingly pointless from the perspective of users.

    There are a lot of stupid things like this in Animator Controllers that either log an error without an exception the caller can catch or even worse, just silently fail to do what you want (like calling Play twice in the same frame simply ignores the second call).

    But yeah, probably no one's working on it because they're making a new animation system for DOTS. And given the general direction of DOTS ("performance by default" instead of "easy development by default") I fully expect them to come up with yet another poorly designed animation system.
     
  6. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    For those who are looking for how to do this here is an editor only solution to get an array of layer sync flags:

    Code (CSharp):
    1.     public bool[] GetSynchronizedLayerFlags(Animator animator)
    2.     {
    3.         var runtimeController = animator.runtimeAnimatorController;
    4.         if(runtimeController == null)
    5.         {
    6.             Debug.LogErrorFormat("RuntimeAnimatorController must not be null.");
    7.             return;
    8.         }
    9.      
    10.         if (runtimeController is AnimatorOverrideController overrideController)
    11.         {
    12.             runtimeController = overrideController.runtimeAnimatorController;
    13.         }
    14.  
    15.         var controller = runtimeController as UnityEditor.Animations.AnimatorController;
    16.         if(controller == null)
    17.         {
    18.             Debug.LogErrorFormat("AnimatorController must not be null.");
    19.             return;
    20.         }
    21.  
    22.         var synchronizedLayers = new bool[controller.layers.Length];
    23.  
    24.         for (var index = 0; index < controller.layers.Length; index++)
    25.         {
    26.             synchronizedLayers[index] = (uint) controller.layers[index].syncedLayerIndex <
    27.                 (uint) controller.layers.Length;
    28.         }
    29.  
    30.         return synchronizedLayers;
    31.     }
    This code is based off of posts Getting AnimatorController from Animator and Getting AnimatorController from Animator
     
    Last edited: Jan 4, 2023
    Jaimi likes this.