• 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 D3m0nE · Apr 24, 2013 at 09:14 PM · animationerrorrpc

How To Get Current Animation Name

Hello Everyone

i'm trying to send Animation Throw RPC

but i have many Animation, so i will just try to make Shortcut way

 .animation[CurrentAnimatinoName].speed = VlocityMagnitude / RunSpeed;

i want to get CurrentAnimatinoName. can anyone help me please?

Comment
Add comment · Show 1
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 mchts · Feb 29, 2016 at 04:32 AM 0
Share

Well everyone says you can't because there can be multiple animations playing at the same time etc. But in my case i have just one animation per state and found a neat way to get currently playing animation without doing all IsPlaying() loop thing. It's also precise. And i must state i'm doing this for legacy mode. Sorry if its too late and told before.

So you can call this once in start and add a specific event to each clip:

             foreach (AnimationState state in animation)
             {
                 AnimationEvent animationEvent = new AnimationEvent();
                 animationEvent.stringParameter = state.name;
                 animationEvent.functionName = "SetCurrentPlayingAnimation";
                 animationEvent.time = 0f;
                 animation[state.name].clip.AddEvent(animationEvent);
             }

Thus every single beggining of your animation state you get the name of it. Then place method "SetCurrentPlayingAnimation(string statename)" in "yourclass" attached to your object (whatever it is) and you can set the result "state.name" to a property like currentState in it.

3 Replies

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

Answer by TonyLi · Apr 24, 2013 at 11:55 PM

There is no "current animation" because multiple animations can be playing at the same time. For example, you could be cross-fading between idle and run, or you could be playing a blend of walk animations (walk forward + strafe right) and also upper body animations such as waving, all at the same time.

I recommend keeping track of the animation yourself. For example:

 string currentAnimation = null;
 currentAnimation = "Run Forward";
 animation.Play(currentAnimation);
 animation[currentAnimation].speed = VelocityMagnitude / RunSpeed;

The code above is just an example based on your question that should get you started. But in practice you'll probably want to implement something more robust.

Another approach would be to iterate through all the clips in animation[] and examine the weights. Hmm, I just noticed these have both suggested earlier in this question: http://answers.unity3d.com/questions/153785/retrieving-the-name-of-the-animation-currently-pla.html

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 D3m0nE · Apr 25, 2013 at 12:04 AM 0
Share

umm okey, so there is no way to Find the name of clip that already playing,

u know because i have allot of animation and i need to send them by RPC

so if i could found way to get the name will be allot easier,

anyway thanks

avatar image
1

Answer by SgtOkiDoki · Aug 10, 2019 at 07:12 AM

I guess that's what you have been looking for.

 private string CurrentPlayingAnimation
 {
             get
             {
                 if (this.Animation.isPlaying)
                     foreach (AnimationState item in this.Animation)
                         if (this.Animation.IsPlaying(item.name))
                             return item.name;
                 return null;
            }
 }
 
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
1

Answer by Seb_GTB · Feb 17, 2021 at 04:38 PM

Mmmm I prefer...

 Animator animator;
 AnimatorClipInfo[] animatorinfo;
 string current_animation;
 
 
     void Awake()
     {
         animator = GetComponent<Animator>();
     }
 
     void Update()
     {
         animatorinfo = this.animator.GetCurrentAnimatorClipInfo(0);
         current_animation = animatorinfo[0].clip.name;
     }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

15 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

Related Questions

Multiple Cars not working 1 Answer

Can't send RPC function since no connection was started.login script 1 Answer

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

i just got unity and when i open the program i get a error saying transaction is invalid 2 Answers

BCE0005: Unknown identifier: 'DirectionRay'. 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