Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by thegirlnamedcrow · Nov 06, 2015 at 01:46 PM · animationanimatoranimationclip

Sprite animation only playing first frame

I am currently having the problem that, although my animator controller appears to be set up correctly, my animations are not playing. I am currently coding a 2D walking sprite that changes animation clips based on the direction in which he is walking, and my animator indeed switches correctly between the different directional animation clips – however, it only plays the first frame, and immediately stops there. In my animator window, the correct clip that should be playing is selected, but the bar that shows the progress is not moving.

This is an issue I've never had with Unity animations, and I'm honestly stumped on this. Has anybody had this problem before, or does anybody have an idea of how to fix it?

Thank you!

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by OctoMan · Nov 06, 2015 at 05:54 PM

There are several things you need to check.

  • Does your animation in the animation window works correct?

  • Is the speed variable of the animation set to 1?

  • Did all worked before you started coding?

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 thegirlnamedcrow · Dec 17, 2015 at 11:54 PM

@OctoMan Yes, to all of these. Sorry this took so long for me to answer this - I'm going to add some information that might help.

I'm using a spritesheet with a character that moves in the NW/SW/NE/SE directions, and I'm trying to route everything through any state in order to make smooth transitions. Let me post my code: this animation is called during the same frame that the destination is set.

 using UnityEngine;
 using System.Collections;
 
 public class BehaviorSeek : MonoBehaviour
 {
     public float Step;
     public float StoppingRadius;
     private Animator anim;
     Vector3 destination;
 
     void Start()
     {
         anim = GetComponent<Animator>();
         anim.SetBool("SW", true);
         anim.SetBool("Idle", true);
         destination = new Vector3 (0f, 0f, 0f);
 
     }
 
     void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
             destination = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             destination = new Vector3(destination.x, destination.y, destination.y);
         }
         if (CheckIfInRange(destination))
         {
             UpdateAnim(destination, false);
         }
         else if (!CheckIfInRange(destination))
         {
             MoveTo(destination);
         }
     }
 
     bool CheckIfInRange(Vector3 dest)
     {
         if (GetHypotenuse(transform.position, dest) <= StoppingRadius)
         {
             return true;
         }
         else { return false; }
     }
 
     float GetHypotenuse(Vector3 first, Vector3 second)
     {
         float diff = Vector3.Distance(first, second);
         return diff; 
     }
 
     public void MoveTo(Vector3 dest)
     {
         UpdateAnim(dest, true);
         Vector3 newPos = Vector3.Lerp(transform.position, dest, Step * Time.deltaTime);
         transform.position = newPos;
     }
 
     void UpdateAnim(Vector3 dest, bool isMoving)
     {
         if (!isMoving)
         {
             anim.SetBool("Idle", true);
             anim.SetBool("Moving", false);
         }
         else if (isMoving)
         {
             Vector3 pos = transform.position;
             if (dest.x > pos.x) //east
             {
                 if (dest.y > pos.y) // north
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", false);
                     anim.SetBool("SE", false);
                     anim.SetBool("SW", false);
                     anim.SetBool("NE", true);
 
                 }
                 else if (dest.y == pos.y) // south
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", false);
                     anim.SetBool("SE", true);
                     anim.SetBool("SW", false);
                     anim.SetBool("NE", false);
                 }
                 else if (dest.y < pos.y) // south
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", false);
                     anim.SetBool("SE", true);
                     anim.SetBool("SW", false);
                     anim.SetBool("NE", false);
                 }
             }
             else if (dest.x == pos.x) // west
             {
                 if (dest.y > pos.y) // north
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", true);
                     anim.SetBool("SE", false);
                     anim.SetBool("SW", false);
                     anim.SetBool("NE", false);
                 }
                 else if (dest.y == pos.y) // south
                 {
                     anim.SetBool("Moving", false);
                     anim.SetBool("Idle", true);
                 }
                 else if (dest.y < pos.y) //south            
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", false);
                     anim.SetBool("SE", false);
                     anim.SetBool("SW", true);
                     anim.SetBool("NE", false);
                 }
             }
             else if (dest.x < pos.x) // west
             {
                 if (dest.y > pos.y) //north
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", true);
                     anim.SetBool("SE", false);
                     anim.SetBool("SW", false);
                     anim.SetBool("NE", false);
                 }
                 else if (dest.y == pos.y) //south
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", false);
                     anim.SetBool("SE", false);
                     anim.SetBool("SW", true);
                     anim.SetBool("NE", false);
                 }
                 else if (dest.y < pos.y) //south
                 {
                     anim.SetBool("Idle", false);
                     anim.SetBool("Moving", true);
                     anim.SetBool("NW", false);
                     anim.SetBool("SE", false);
                     anim.SetBool("SW", true);
                     anim.SetBool("NE", false);
                 }
             }
         }
     }
 }

Here's the basics of my animator component, attached!

Please let me know if there's anything else I can show you that might help.


1.png (100.8 kB)
2.png (107.6 kB)
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 jste6370 · Feb 12, 2021 at 01:55 AM

I set up my idle animation in the animator so that "Any State" could could transition to idle. The problem with this is that: "Any State" includes the animation itself and there is an infinite loop causing only the first frame to show and is why the animation doesn't play.


I fixed this by: Click the transition link in the animator > In the inspector, expand settings > untick "Can Transition To"


Now my idle animation plays! I know this is almost 6 years old but it comes up first on google for me. Hope it helps lol

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

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

44 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 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

Bone length found in file is differn't then source 0 Answers

how do I create a custom sprite class 0 Answers

Animation changes when marked as legacy 0 Answers

Can't play an animation from the Animator 1 Answer

When rotating on animation, rotation is reset 0 Answers


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