Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by Jonas_F · Sep 08, 2016 at 02:47 PM · animationanimatorgetcomponentanimationstatemonobehavior

How can I access the AnimationState component?

Hey everyone,

I'm having a Sprite with an Animator component and when I'm trying to access the AnimationState I'm getting this error:

ArgumentException: GetComponent requires that the requested component 'AnimationState' derives from MonoBehaviour or Component or is an interface.

This is the relevant code part:

 Transform test = BIG_parent.transform.FindChild("big2D").gameObject.transform.FindChild("big_idle_0");
         anim2dState = test.GetComponent<Animator>().GetComponent<AnimationState>();

I also tried test.gameObject.GetComponent<Animator>().gameObject.GetComponent<AnimationState>(); or test.gameObject.GetComponent<AnimationState>(); or various combinations of these variants.

The class that contains this code inherits MonoBehaviour. AnimationState apparently inherits from TrackedReference, which is depricated and has no documentation.

I can't use the Animation component instead of the animator, because I need to be able to set the Speed parameter of the Animator to -1, and I need the AnimationState to access the AnimationState.length and AnimationState.time

I can post more code or information if you need it. Thanks for your time.

Comment
Add comment · Show 2
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 Jonas_F · Sep 08, 2016 at 03:16 PM 0
Share

A year ago @chrisholdem wrote that there is no way to access the AnimationState without an animation component. Is this still true untill today? http://answers.unity3d.com/questions/1002400/how-do-i-set-the-time-of-an-animation-playing-in-t.html Heres what I'm trying to do:

I have the top down view of a sailboat sprite. There is an animation for the moving sail - if the boat adjust it's position relativ to the wind, the sail should move accordingly. The animation contains 60 frames from "Sail is as far left as possible" to "Sail is as far right as possible". If I steer a little bit to the right, the animation should play some frames forward and stop. If I steer a little bit to the left, the animation should play some frames backward and stop.

avatar image Jonas_F · Sep 08, 2016 at 03:33 PM 0
Share

I also tried to use GetComponent(typeof(AnimationState))m but then I get a warning that UnityEngine.Component can't be converted into UnityEngine.AnimationState

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jonas_F · Sep 08, 2016 at 03:58 PM

Ok, I think I found a work around. Animator has the GetCurrentAnimatorStateInfo() method, and it looks as if this method can give me all the information I need. At least I'm not getting error messages anymore.

 Animator test = BIG_parent.transform.FindChild("big2D").gameObject.transform.FindChild("big_idle_0").gameObject.GetComponent<Animator>();
 AnimatorStateInfo currentState = test.GetCurrentAnimatorStateInfo(0);
 animationTime = currentState.normalizedTime;
 targetTime = ((TWA + 180) / 360) * currentState.length;
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

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

Trigger to reverse current animation state 1 Answer

How to call Animator from another script 0 Answers

Error: MissingComponentException: There is no 'Animator' attached - Animator is attached but disappears on play. Can anyone fix? 3 Answers

How do I modify animation parameters from script (C#) 1 Answer

Animator Position VS Script Vector 3 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