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 Mimi · May 07, 2012 at 02:24 PM · animationnullreferenceexceptionobject-reference-error

Script finds everything but still i get "nullreference, object not set to an instance of an object"???

Hi everyone, this is my script, it prints everything correctly, so everything seems to be recognized and found, but when i want to play the animation of "Bird" i get a null reference exception "Object not set to an instance of an object", even though it prints the bird as gameobject bird! i'm very confused! how can that be? Maybe it has something to do with the fact, that the script is on a empty sprite and the object "Bird" is a child of the sprite? Has someone any idea? Thanks:)

var Baby : GameObject; var BabyPosz : float; var animationToolkit; var Bird;

function Start () {

 Baby = GameObject.Find("baby");
 Bird = GameObject.Find("bird");
 animationToolkit = gameObject.GetComponent("tk2dAnimatedSprite");
 

}

function Update () {

 BabyPosz = Baby.transform.position.z - 3.7;
 
 transform.Translate(0,0,-0.03);
 
 if(transform.position.z < BabyPosz){
     
     
 print(Bird);
 print(animationToolkit);
 print(Baby);
 print(BabyPosz);    
     
 Bird.animationToolkit.Play("Fly");
Comment
Add comment · Show 3
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 Beriss · May 07, 2012 at 02:43 PM 0
Share

What is the "tk2AnimatedSprite" ?

avatar image Mimi · May 07, 2012 at 03:41 PM 0
Share

i work with animation toolkit and i have to get this component for playing animations:)

avatar image Bunny83 · May 07, 2012 at 03:44 PM 0
Share

@Beriss and @$$anonymous$$imi: Don't post such requests as answers. Answers should answer the question above. Use comments if you need to clarify something. If you want to add something to your post you can edit it at anytime.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · May 07, 2012 at 03:41 PM

You're mixing the Bird and animationToolkit variables in a non-working way. animationToolkit is your animatedSprite component (not your child's.) You can use it as-is: animationToolkit.whatever.

When you write Bird.animationToolkit, you aren't using your animationToolket variable. Instead, you're using it as a magic word like Bird.transform or Bird.rigidbody. But animtoolkit isn't a magic words, so you get an error. C# would yell about it directly. Javascript tries to look it up and returns null.

You might mean to say: animationToolkit=Bird.GetComponent.... But, GameObject.Find("bird") isn't for finding children -- it finds a different top-level gameObject. Maybe you also want transform.Find("bird"), to find your child bird.

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 Mimi · May 07, 2012 at 04:18 PM 0
Share

Thank you very much for your answer! usually it works with bird.animationtoolkit.play but i never used it with a childobject before, so i didnt know that wouldnt work. Thanks again:)

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Please Help!! NullReferenceException when clicking restore default pose 0 Answers

Getting variable from animation returns Null 0 Answers

Bug in Object reference ? 0 Answers

Null Reference - Help 0 Answers

Object reference not set to an instance of an object... 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