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 Digital-Phantom · Jun 28, 2013 at 04:01 PM · animationerrorcolliderreference

Why am I getting this error ? (Animation based)

Why am I getting this error message? What do they mean by object reference not set? Ive followed a tutorial to the letter and cant see what Im doing wrong ?

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[]

Script Im using -

 var doorClip : AnimationClip;
 
 
 function OnTriggerEnter (player : Collider)
 {
     if(player.tag == "Player")
     GameObject.Find("Door").Animation.Play("Door_Open");
 }

The animation Im sure is correct (if left on auto it plays fine)

Im getting this error at the exact moment my player character enters the doors box collider.

I'll guess its probably something obvious, but Im still kinda new to unity and cant figure it out...lol

Help appreciated please guys(or ladies) ;)

Comment
Add comment
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

3 Replies

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

Answer by GameDevBryant · Jun 28, 2013 at 04:22 PM

A null reference exception means you are trying to access something that is set to null (aka not set at all). Based on this code snippet it could be one of two things: your game object or your animation component.

Try separating it out into something like this:

 GameObject door = GameObject.Find("Door");
 door.animation.clip = doorClip;
 door.animation.Play();

That way, if you still get the error you will no which part is null based on the line the error sends you to.

[Edit] If you are doing it in OnTriggerEnter(), you don't have to call GameObject.Find or assign the clip each time. That can be done in Start() or somewhere that only gets called once (making the variable 'door' in my example a class member variable.

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 Weirdo-Studios · Jun 28, 2013 at 04:29 PM

It looks to me like you don't need the variable because you don't reference it in your script you just link straight to the animation when you say:

GameObject.Find("Door").Animation.Play("Door_Open");

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 Weirdo-Studios · Jun 28, 2013 at 04:53 PM 0
Share

I think you also forgot to refernece what the animaitonclip actually was in the inspector

avatar image
0

Answer by Digital-Phantom · Jun 29, 2013 at 06:19 PM

Thanks guys, sorted now (well phase one is anyway)

 #pragma strict
 
 //Puts Drag n Drop variable slot into Script
 var doorClip : AnimationClip;
 
 function Start () {
 
 }
 
 function OnTriggerEnter () {
 
     animation.Play("SlideOpen"); // Sets name of Animation clip to be played
 
 }

This did the trick, along with your suggestions.

Side question - Do I have to make another animation for the door close? or is there a way to just play the DoorOpen animation in reverse with an OnTriggerExit function ???

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 GameDevBryant · Jul 01, 2013 at 03:07 PM 0
Share

I'm not entirely sure if you can set the time to go in reverse, but you can try playing with the ping pong wrap mode to see if you can get it that way:

http://docs.unity3d.com/Documentation/ScriptReference/Wrap$$anonymous$$ode.PingPong.html?from=Animation

That makes it play forwards then backwards by default.

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

17 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

Related Questions

Reference to Object error but script works fine 1 Answer

Destroy trigger so animation only plays once. 1 Answer

Help with Animator has not been initialized error 5 Answers

animation and sound on collide 1 Answer

Trigger animtaion when hit 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