Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Commander Quackers · Nov 26, 2013 at 06:37 PM · animationerrorstate

The animation state could not be played because it couldn't be found!

Hi, trying to make a custom FPS player with self-made animations but when I use this code attached to the First Person Controller and press shift, it gives me the error in the question.

Here's the code I'm using, it references to animations in the Main Camera.

     childObject= GameObject.Find("Main Camera");
     if (ch.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift")){
         speed = runSpeed;
           childObject.animation.Play("fpsrun");
           }
           else {
           childObject.animation.Play("fpswalk");    
     }


Anyone know a quick fix for this? The animations are in the Assets folder. Do they need to be in a special folder somewhere? Also, they are attached to an animation tab in the inspector in Main Camera.

Any help? Thanks!

Comment
Add comment · Show 22
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image clunk47 · Nov 26, 2013 at 06:46 PM 1
Share

What is ch??? Please post full script so I can troubleshoot.

avatar image KiraSensei · Nov 26, 2013 at 06:48 PM 1
Share

Is the game object which contains this script animated ? or is the childObject animated ?

avatar image KiraSensei · Nov 26, 2013 at 06:53 PM 1
Share

So your animations only consist on moving the camera ?

Do you have exactly one object called "$$anonymous$$ain Camera", and does it contains the animations "fpsrun" and "fpswalk" (I think it is case sensitive, so check it carefully in the inspector) ?

avatar image clunk47 · Nov 26, 2013 at 06:57 PM 1
Share

Why are you putting local variables and defining childObject in Update()? You should create your variables at the top of your script and define them in Start() if they are not going to change.

avatar image KiraSensei · Nov 26, 2013 at 07:02 PM 1
Share

$$anonymous$$ake a screenshot of inspector of the main camera to show us your animations please.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
32
Best Answer

Answer by clunk47 · Nov 26, 2013 at 08:24 PM

Your animations are not being found because they must be marked as legacy. Go to your project pane and select one of the animations (fpswalk or fpsrun). Then set the inspector to Debug Mode as shown in the photo attached. The animation type will probably be 2. Set it to 1. Repeat this step for your other animation(s).

Also, just for some debugging purposes, and cleaner code, try this as far as your script goes.

 #pragma strict
 
 private var childObject : GameObject;
 
 var walkSpeed: float = 7; // regular speed
 var crchSpeed: float = 3; // crouching speed
 var runSpeed: float = 20; // run speed
 
 private var chMotor: CharacterMotor;
 private var ch: CharacterController;
 private var height: float; // initial height
 
 var h : float;
 var speed : float;
 var lastHeight : float;
 
 var childAnim : Animation;
 
 function Start()
 {
     childObject = Camera.main.gameObject;
     childAnim = childObject.animation;
     chMotor = GetComponent(CharacterMotor);
     ch = GetComponent(CharacterController);
     height = ch.height;
     h = height;
     speed = walkSpeed;
 }
 
 function Update()
 {
     if(childAnim.GetClip("fpsrun") && childAnim.GetClip("fpswalk"))
     {
         if (ch.isGrounded && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
         {
             speed = runSpeed;
             childObject.animation.CrossFade("fpsrun", 0.25f);
         }
         
         else
             childObject.animation.CrossFade("fpswalk", 0.25f);    
     }
     
     else print("Animations not found.");
     
     if (Input.GetKey(KeyCode.C))
     { // press C to crouch
         h = 0.5 * height;
         speed = crchSpeed; // slow down when crouching
     }
 
     chMotor.movement.maxForwardSpeed = speed; // set max speed
     ch.height = Mathf.Lerp(ch.height, h, 5*Time.deltaTime);
     lastHeight = ch.height; // crouch/stand up smoothly 
     transform.position.y += (ch.height-lastHeight)/2; // fix vertical position
 }

animtype.png (21.5 kB)
screen.png (55.3 kB)
Comment
Add comment · Show 32 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Commander Quackers · Nov 26, 2013 at 08:26 PM 1
Share

Thanks! Worked great, finally I can move on!

avatar image clunk47 · Nov 26, 2013 at 08:26 PM 1
Share

Glad I could help, I learned something new as well :D

avatar image Commander Quackers · Nov 26, 2013 at 08:34 PM 2
Share

Yeah, it removes the "jumpy" transition from fpswalk to fpsrun, looks way better than it was when it was animation.play!

avatar image clunk47 · Nov 26, 2013 at 08:50 PM 2
Share

Well, for example, if you're using W and S or Up and Down Arrows (Vertical Axis) to walk, you could do something like this:

 if(Input.GetAxis("Vertical") != 0)
 {
     if (ch.isGrounded && Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift) || Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightShift))
     {
         speed = runSpeed;
         childObject.animation.CrossFade("fpsrun", 0.25f);
     }
 
     else
     {
         speed = walkSpeed;
         childObject.animation.CrossFade("fpswalk", 0.25f);   
     } 
 }
avatar image Commander Quackers · Nov 26, 2013 at 08:54 PM 2
Share

Worked great, thanks again.

Show more comments
avatar image
1

Answer by phreakhead · Sep 10, 2017 at 03:20 AM

If you don't want to mark your animations as legacy, you can use the new Playables API to play non-legacy AnimationClips:

 private List<PlayableGraph> graphs = new List<PlayableGraph> ();
 
 // Just call this function when you want to play an AnimationClip on a specific GameObject.
 // from https://docs.unity3d.com/Manual/Playables-Examples.html
 private PlayableGraph playAnim(AnimationClip clip, GameObject obj) {
     PlayableGraph playableGraph;
 
     AnimationPlayableUtilities.PlayClip(obj.AddComponent<Animator>(), clip, out playableGraph);
 
     // save all graphs we create and destroy them at the end of our scene.
     // you might need to optimize this if you make a lot of animations.
     graphs.Add (playableGraph);
 
     return playableGraph;
 }
 
 void OnDisable() {
     foreach (var g in graphs) {
         g.Destroy();
     }
     graphs.Clear ();
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by SharkoFR · Dec 04, 2016 at 08:33 PM

Hi now we just need check the box legacy in debug mode

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unity_bfawXRcvR563OA · Jun 19, 2019 at 03:29 PM 0
Share

when changed to legacy, my animation inspector is all grayed out.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

RayCasting + Animation Problem 0 Answers

The AnimationClip 'Attack' used by the Animation component 'Knife' must be marked as Legacy. 1 Answer

Animation error please help me! 1 Answer

The AnimationClip 'Running' used by the AnimationComponent 'corpse' must be marked as Legacy? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges