Search Unity

Animation Helper

Discussion in 'Animation' started by yeagob, Mar 8, 2015.

  1. yeagob

    yeagob

    Joined:
    Jan 27, 2014
    Posts:
    18
    Hi!

    Im watching the Animation Asset Api tutorial, from Unity5 tutorials, where explain how to make a Animator Controler automaticly with the Animation Helper. But in the Window menu of Unity 5 it doesn't exist. There is no Animation Helper nowhere.

    Somebody knows where it is?
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    You have to create that "AnimationHelper.cs" editor script first, into Editor folder,
    then it should appear to that menu given in the MenuItem line of that script
     
  3. Humphling

    Humphling

    Joined:
    Apr 29, 2015
    Posts:
    3
    Complete beginner here:
    what script is needed to be in that file and where does it need to go
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    In the Project panel: Create new folder called Editor/
    In the Project panel:Create new C# script, name it "AnimationHelper" and move it into that Editor/ folder
    Copy (write) the code from the video into that "AnimationHelper" script
    Then it should work as shown in the video
     
  5. Humphling

    Humphling

    Joined:
    Apr 29, 2015
    Posts:
    3
    Thanks
    I got it working now :)
     
  6. Humphling

    Humphling

    Joined:
    Apr 29, 2015
    Posts:
    3
    #if UNITY_EDITOR using UnityEditor; using UnityEditor.Animations; using UnityEngine; public class AnimationHelper : EditorWindow { public GameObject target; public AnimationClip idleAnim; public AnimationClip walkAnim; public AnimationClip runAnim; [MenuItem ("Window/Animator Helper")] static void OpenWindow () { //Get existing open window or if none, make a new one: GetWindow<AnimationHelper>(); } void OnGUI() { target = EditorGUILayout.ObjectField("Target Object", target, typeof(GameObject), true) as GameObject; idleAnim = EditorGUILayout.ObjectField("Idle", idleAnim, typeof(AnimationClip), false) as AnimationClip; walkAnim = EditorGUILayout.ObjectField("Walk", walkAnim, typeof(AnimationClip), false) as AnimationClip; runAnim = EditorGUILayout.ObjectField("Run", idleAnim, typeof(AnimationClip), false) as AnimationClip; if (GUILayout.Button("Create")) { if (target == null) { Debug.LogError ("No target for animator controller set."); return; } Create(); } } void Create () { AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/" + target.name + ".controller"); // Adds a float parameter called Speed controller.AddParameter("Speed", AnimatorControllerParameterType.Float); //Add states AnimatorState idleState = controller.layers[0].stateMachine.AddState("Idle"); idleState.motion = idleAnim; //Blend tree creation BlendTree blendTree; AnimatorState moveState = controller.CreateBlendTreeInController("Move", out blendTree); //BlendTree setup blendTree.blendType = BlendTreeType.Simple1D; blendTree.blendParameter = "Speed"; blendTree.AddChild(walkAnim); blendTree.AddChild(runAnim); AnimatorStateTransition LeaveIdle = idleState.AddTransition(moveState); AnimatorStateTransition leaveMove = moveState.AddTransition(idleState); LeaveIdle.AddCondition(AnimatorConditionMode.Greater, 0.01f, "Speed"); leaveMove.AddCondition(AnimatorConditionMode.Less, 0.01f, "Speed"); target.GetComponent<Animator>().runtimeAnimatorController = controller; } } #endif




    Copy and paste the above into a c# file
     
    cvaughan02 likes this.
  7. LINKENN

    LINKENN

    Joined:
    Jun 23, 2015
    Posts:
    1
    hello everyone.
    I rewrite all the whole code. I don't know why the animator helper window wont work, I putted idle animation and run animation is putting itself automatically and I can't to change run animation. Animator Helper .png someone can tell me what is wrong?
    I have unity 5.
     
  8. fionarat

    fionarat

    Joined:
    Jun 8, 2015
    Posts:
    6
    I need help
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    hi, whats the problem?
     
  10. fionarat

    fionarat

    Joined:
    Jun 8, 2015
    Posts:
    6
    my scripts are not workeing
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    Are there any error messages?
     
  12. fionarat

    fionarat

    Joined:
    Jun 8, 2015
    Posts:
    6
  13. fionarat

    fionarat

    Joined:
    Jun 8, 2015
    Posts:
    6
    so can you help
     
  14. fionarat

    fionarat

    Joined:
    Jun 8, 2015
    Posts:
    6
    hey
     
  15. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    well..what error messages you have?
     
  16. CrazyZombieKiller

    CrazyZombieKiller

    Joined:
    Jun 8, 2015
    Posts:
    6
    Unbelievable. We have to drop the code into Unity ourselves?? I did, after having to spend a lot of time parsing the code since the comment lines plank out everything and I don't know these functions. But nevertheless, after a lot of work I shouldn't have to do I got a clean compile. And of course it didn't work. The menu didn't pop up. No console error messages. Nothing. Unbelievable. Is there anything that could be done.
     
  17. Miklauz

    Miklauz

    Joined:
    Jul 25, 2016
    Posts:
    1
    @LINKENN

    if you copy and paste the above code you get that error.
    to fix it go into void OnGUI()
    and find this line:
    runAnim = EditorGUILayout.ObjectField("Run", idleAnim, typeof(AnimationClip), false) as AnimationClip;
    then simply delete idleAnim and type runAnim, so you get that line:
    runAnim = EditorGUILayout.ObjectField("Run", runAnim, typeof(AnimationClip), false) as AnimationClip;

    worked for me. regards.

    p.s. i just realized i'am a bit late so sorry that noone helped you when you needed it...