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
3
Question by Dengar · Apr 15, 2014 at 05:16 PM · animationanimationeventanimationstateanimation events

AnimationEvent.animationState help: NullReferenceException

Okay so I added this event to the timeline of my animation at a certain frame. I want to know what animation state had sent this event. Except I get this error:

 NullReferenceException
 ThisCScript.someSuch (UnityEngine.AnimationEvent ae) (at Assets/Dude/ThisCScript.cs:94)

Here's the function that is being called by the event.

 public void someSuch (AnimationEvent ae)
     {
         AnimationState state = ae.animationState;
         string name = state.name;
         print (name);
         print (ae.floatParameter);
         print (ae.intParameter);
         print (ae.stringParameter);
     }

If I comment out the string name = state.name part, and also the print(name) parts, the code works fine. It outputs the parameters just fine.

I even tried to use the debugger. When I looked at the value for ae.animationState, it said "object reference not set to an instance of an object". I am not sure what causes this though. I mean the script is most certainly called by an animation. Can anybody tell me what I'm doing wrong?

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 chriseng · Apr 28, 2014 at 10:03 PM 0
Share

I am experiencing the same problem. AnimationEvent.animationState is always null whether responding to callbacks from $$anonymous$$ecanim or the legacy animation system, it seems. The documentation (https://docs.unity3d.com/Documentation/ScriptReference/AnimationEvent-animationState.html) suggests that this may occur if "the method is called outside of an animation event callback", but I am sure that I am calling the method from within said callback.

avatar image JakobHAndersen chriseng · Jul 07, 2014 at 03:50 PM 0
Share

I am having the exact same problem. Is this a bug in unity or has anyone found out what might be the problem?

In my specific case I am looking for a method to find out whether the event is fired by a state which we are transitioning (crossfading) away from.

Best regards, Jakob

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bodrp · Mar 10 at 04:43 PM

If you are using the Animator component, and not the legacy Animation component, you should use animatorStateInfo property of the AnimationEvent instead of animationState. animatorStateInfo will not be null when the function is called from an Animator's animation event.

More information about AnimatorStateInfo can be found here: https://docs.unity3d.com/ScriptReference/AnimatorStateInfo.html

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

23 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

Related Questions

Error in AnimationState.cpp Line: 307 1 Answer

Wait for Animation 1 Answer

Get an Animator state inside an AnimationEvent callback of the last frame 2 Answers

Blending two animations in a sequence? 1 Answer

Simple state switching to mouse over & pressed requires 2 animation clips with some parts duplicated? 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