Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by dotoli · Nov 20, 2013 at 06:28 PM · animation2dsprite

Mecanim Animation Using Sprite Sheets

I am using sprite sheets to animate my character that I have on a GameObject with a SpriteRender and an Animator.

I have 6 sprites for each running direction and use one sprite from each direction as my idle pose.

I have created 8 animations: 4 for each run direction and 4 for each idle direction.

My problem is now within the Mecanim Animation Controller. I have a boolean parameter "moving" and an integer "direction" that store the direction (0=up, 1=right, 2=down, 3=left).

I want any of the 8 animations to immediately interrupt another one so that for example changing from running Right to Up is instantaneous.

Creating transitions to each animation from Any State (with specific moving and direction parameters) doesn't work since Any State can trigger a transition from a state to itself (see here). So basically while the character is running up, the Running Up animation keeps on getting continuously triggered.

Is there an easy way to work around this at the moment, preferably with no scripting since I feel everything to do with animation should stay within Mecanim ? Why hasn't an option been put in to exclude the current state from Any State, it seems like a trivial feature?

For now I have put a Trigger parameter "changed" and in my player script i set that trigger when anything changes and put a trigger condition in every transition but that's really not ideal.

Am I missing something obvious?

Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ImpishMario · Dec 27, 2013 at 01:37 PM

Hey! guess you can try at least 2 solutions:

  1. you can try to avoid "Any State" and create generic Idle state and then make transitions to Idle Left/Right/Up/Down (maybe as a sub-states?) and then to link transitions to proper animation states - this should eliminate continuous triggering "feature" ;) I, however, have had some issues with this solution (apart from spaghetti structure) e.g. I have no idea why but one of my animations was looping (2 playbacks in total) while it wasn't supposed to loop at all. Therefore I decided to go with second solution;

  2. Use Any State and try to write a simple coroutine that manages your SetTrigger/SetBool whatever method you're using. This can go like this (I use it for my SetTrigger):

    using UnityEngine; using System.Collections;

    public class InterfaceAnimation : MonoBehaviour {

      public Animator animationObject;
     
         static private InterfaceAnimation Instance;
         static private bool canAnimate;
     
         void Start () {
             Instance = this;
             canAnimate = true;
         }
         
         public static IEnumerator Trigger (string trigger) {
     
             if (canAnimate) {
         
                 Instance.animationObject.SetTrigger (trigger);
                 canAnimate = false;
             }
     
             yield return new WaitForSeconds (3f);
             canAnimate = true;
         }
     }
    
    

Then you just call your coroutine and it makes sure that your trigger is not set continuously!

Hope this helps!

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
Wiki

Answer by SuarescorX · Feb 25, 2014 at 10:26 PM

Hi, it happened the same to me, all i did was save the integer into a variable before setting the animation, then, I checked if the value of the new animation was different of current. It helped me a lot in terms of optimization, since i was using it with 50 characters simultaneously

 int currentAnim
 
 void SetAnimation(int newAnim)
 {
     if(newAnim != currentAnim)
     {
         this.getComponent<Animator>().SetInteger(newAnim);
         currentAnim = newAnim;
     }
 }
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

19 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

Related Questions

Simultaneous Animation for an Object 0 Answers

I cannot make AnimationClip changing some Sprites without AnimationController. 0 Answers

Object not moving after changing animator parameter 1 Answer

Sprite Rect Moves Between Frames 0 Answers

Keyframe animation WITHOUT curve (Sprite Animation) 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