Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Previewing animations with events attached?

Discussion in 'Animation' started by Dreamcube017, Mar 7, 2017.

  1. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    253
    Is there a way to preview animations with the events being triggered without having to run though the game?

    I have lots of characters with many different animations that I must add sounds and/or particle effects for, and that is very tricky to test if I have to play through the game to see them happen.

    I found this asset, but sadly it is out of date.
    https://www.assetstore.unity3d.com/en/#!/content/19119

    Is there something like this for a newer version of Unity? Thanks.
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I don't know of any package - however setting up the character in a different scene or project just to get all animations triggers, sounds particle fx etc working seems like a simple solution.

    Alternatively you could create a simple testing scene (padded room) in the game, place the character in that scene and temporarily launch the game from that scene. This would reduce the overhead of entire game/scene loading to test the character setup.
     
    TrickyHandz likes this.
  3. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    253
    Thanks for the quick reply!

    Hm that could be cool. But in Mecanim, how do I just trigger each specific animation to play by itself without it having to be activated in the tree? I am just the sound designer, not the animator. They set up quite a complex set of trees and I'm not sure exactly what I have to set in the parameters to trigger "Fall back from mid air attack" or something else that's buried deep within.
     
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    One way is to reset the default state to the animation state you want to check out, however if the state machine is complex with code driving the actions of the character, not sure if this is a good way to go about checking individual states.
    I've not worked on a complex character setup in a while so I'd consider a better suggestion from another animator. ;)
     
  5. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    253
    Welll some of the characters are controlled by AI. I'm afraid that if I move something, it'll break everything.

    *pokes Unity Tech* How 'bout a better way to preview animations guys? ... HUH?... with all those shiny graphic improvements in 5.6 and Unity 2017???
     
  6. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    This is a very interesting problem set. I haven't really analyzed this to the fullest, but there are several approaches that could be taken to make it easier to test things out for you. So I put together a quick editor window to try to see if this helps. The idea behind it is that you select the character in your scene that you want to test. It will parse the animator states from the animator controller and create buttons that can be used to immediately trigger a state when in play mode. This is VERY unpolished and only had a few minutes of testing. I can say that I was able to verify animation events being triggered, however, depending on the complexity of the AnimatorController being used this might run into some issues. Create a new script called AnimationTester.cs in an Editor folder and drop in the following. It will be available in the menu under "Tools/Animator State Tester"

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.Animations;
    4.  
    5. public class AnimationTester : EditorWindow
    6. {
    7.     [MenuItem("Tools/Animator State Tester")]
    8.     private static void OpenWindow()
    9.     {
    10.         GetWindow<AnimationTester>();
    11.     }
    12.  
    13.     private GameObject targetGO;
    14.     private Animator animator;
    15.     private AnimatorController controller;
    16.  
    17.     private void OnGUI()
    18.     {
    19.         EditorGUI.BeginChangeCheck();
    20.         targetGO = (GameObject)EditorGUILayout.ObjectField("Target Character: ", targetGO, typeof(GameObject), true);
    21.         if (targetGO == null)
    22.         {
    23.             EditorGUILayout.HelpBox("Select a gameObject to work with", MessageType.Info);
    24.             animator = null;
    25.             controller = null;
    26.         }
    27.  
    28.  
    29.         if (targetGO == null)
    30.         {
    31.             return;
    32.         }
    33.  
    34.         Debug.Log("Change hit");
    35.         animator = targetGO.GetComponent<Animator>();
    36.         Debug.Log(animator.name);
    37.  
    38.         if (animator == null)
    39.         {
    40.             EditorGUILayout.HelpBox("No Animator found on the selected GameObject", MessageType.Error);
    41.             return;
    42.         }
    43.  
    44.         controller = animator.runtimeAnimatorController as AnimatorController;
    45.         if (controller == null)
    46.         {
    47.             return;
    48.         }
    49.  
    50.         foreach (AnimatorControllerLayer layer in controller.layers)
    51.         {
    52.             foreach (ChildAnimatorState cas in layer.stateMachine.states)
    53.             {
    54.                 if (GUILayout.Button(cas.state.name))
    55.                 {
    56.                     animator.Play(cas.state.nameHash);
    57.                 }
    58.             }
    59.         }
    60.     }
    61. }
    62.  
    63.  
    Simply assign your character, enter play mode and press the appropriate button to change to a state. As mentioned earlier, this is not polished at all, but if it helps at all let me know as this seems like a very interesting tool to build for people in your situation.
     
    Last edited: Mar 7, 2017
    chrismarch and theANMATOR2b like this.
  7. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    253
    I tried the script. It does work, but I can't get the weapon to show up.
     
  8. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    I'm glad you were able to view the animations. When it comes to showing weapons and such I don't think I can offer much help. Whatever triggers the action to attach a weapon to the character in game would need to be called during the previewing process. A programmer on the project should be able to facilitate that fairly quickly. It shouldn't be too difficult for an in house tool to be developed for that in my opinion.
     
  9. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    253
    Ah that's ok. I can hear the sounds right away and that is plenty. And sorry, I was rather tired when I wrote that. I am able to get access to the animations so I can add events to them. Thank you! I'll keep you updated if something else happens.
     
  10. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    theANMATOR2b likes this.