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 zaphy_tom · Jun 19, 2014 at 03:26 PM · nullreferenceexceptionenabled

if (animation ["idle"].enabled == true){ gives a NullReferenceExeption?

I don't know what I need to do to get rid of this. I did try var enabled :bool as described on the docs pages but that caused a problem. This is where I was looking http://answers.unity3d.com/questions/14599/check-if-a-spesific-animation-is-playing.html. As you can see I am looking to see if an animation is playing. Or is there an other way to do this?

Comment
Add comment · Show 7
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 meat5000 ♦ · Jun 20, 2014 at 08:39 AM 0
Share

the ":bool" denotes the 'Type' of the function. You don't need to include it in your call.

Erisat's answer is correct for Legacy system.

avatar image zaphy_tom · Jun 20, 2014 at 08:51 AM 0
Share

Have used that but I don't want it to work on a mouse click I just want to check that a specific animation is playing as I am animating a scene rather than using it as part of something interactive. Also I can't use legacy as I am animating a character.

avatar image meat5000 ♦ · Jun 20, 2014 at 09:50 AM 0
Share

So you are using $$anonymous$$ecanim?

avatar image zaphy_tom · Jun 20, 2014 at 10:20 AM 0
Share

I have been but now I am using legacy animation. What I want to do is to say that when a specific animation is playing, play a certain sound. I am working with 2 animations and 2 sounds on one character. I can get both animations to play one after the other but not the sounds they seem to trigger at the same time.

 #pragma strict
 
 //private var state = 0;
 var idle : GameObject;
 var scratch : GameObject;
 var idleSound : AudioClip;
 var scratchSound : AudioClip;
 var enabled = true; 
 function Start () {
 
 
 animation.Play ();
 
 if (animation.isPlaying);
 
 //audio.Play(88200);
     audio.PlayOneShot(idleSound);
 //yield WaitForSeconds(1);
 
 //if (!animation.isPlaying);
 //animation.Play ("$$anonymous$$ouseScratch");
 ////if (animation ["$$anonymous$$ouseScratch"].enabled == true){    
 //if (scratch.animation.isPlaying);
 //    
 //    audio.PlayOneShot(scratchSound);
 
 }
 function Update () {
 
 //if (state == 0){
 //    state = 1;
 //    return;
 //}
 
 }
avatar image meat5000 ♦ · Jun 20, 2014 at 10:38 AM 0
Share

Please format your code with the 101010 button

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jun 20, 2014 at 09:01 AM

You have to understand what that error actually means. A Null-Reference-Exception happens when you use a reference to an object to do something with it, but that reference is null. If a reference is null that means that object you want to access doesn't exists.

In your code there are two possible candidates:

  • The animation component itself

  • or there is no AnimationState called "idle" in that animation component

So you either have this script on a GaemObject that doesn't have an Animation componentn attached, or that animation component doesn't have an animation called "idle".

Keep in mind that the Animation component need to be on the same OameObject. If it's on a child GameObject you can't access it that way. You would need to either get a reference to the correct child object or use GetComponentInChildren to get the Animation component.

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 Erisat · Jun 20, 2014 at 08:25 AM

http://docs.unity3d.com/ScriptReference/Animation.IsPlaying.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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Enabling/Disabling a slider from script 0 Answers

this == null 1 Answer

Weird NullReferenceException 2 Answers

Arraylist to GameObject[] array issue. 1 Answer

[Roll-a-ball] Changing UI text (NRE) 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