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 /
This question was closed Feb 22, 2017 at 03:45 PM by YetiStudio for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by YetiStudio · Jun 06, 2014 at 07:22 PM · animationobjectreferenceinstance

i don't understand "NullReferenceException: Object reference not set to an instance of an objec"

Hello so i try to understand by searching "NullReferenceException: Object reference not set to an instance of an object" on google but i didn't find my answer so everytime i click on play this message is spamming the console, I'm trying to put animations of a character in a script (Idle, Run, Walk,...)

there is my Script:

 //Public variables
 var speed:float;
 var speedRun:float;
 var speedRotate:float;
 var gravity:float;
 
 //Private variables
 
 private var controller:CharacterController;
 private var moveDirection:Vector3;
 private var deltaTime:float;
 private var characterContent;
 private var runAnim:boolean;
 
 function Start () {
    
      controller = GetComponent("CharacterController");
      characterContent = transform.find("Perso");
 }
 
 function Update () {
 
     //Cadence du temps
     deltaTime = Time.deltaTime;
     
     //On ne cours pas
     runAnim = false;
     
     //Deplacements Haut/bas
     if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)){
         moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speedRun);
         runAnim = true;
     }else{
         moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speed);
     }
     
     
     if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow)){
             if(!runAnim){
                 characterContent.animation.CrossFade("Walk", 0.2);
             }else{
                 characterContent.animation.CrossFade("Run", 0.2);
             }
     }else{
         characterContent.animation.CrossFade("Idle_01", 0.2);
     }
     
     //changer sur l'axe
     moveDirection = transform.TransformDirection(moveDirection);
     
     //rotation personnage
     transform.Rotate(Vector3(0,Input.GetAxis("Horizontal") * speedRotate * deltaTime,0));
     
     //gravity
     moveDirection.y -= gravity;
     
     //Deplacement du Character Controller    
     controller.Move(moveDirection * deltaTime);
       
 }


So The error seems to be on the line 45 (in MonoDevelop)or line 23 (on this topic) which is " characterContent.animation.CrossFade("Idle_01", 0.2);" Tne animation of the idle is called "Idle_01" on unity so i don't understand where the error came from ... If someone can help me it would be great !

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 Landern · Jun 06, 2014 at 07:44 PM 0
Share

In your start function... is it Perso or Person? Just curious since this may not be found if there are misspellings.

 characterContent = transform.find("Perso");
avatar image Nick4 · Jun 06, 2014 at 09:39 PM 0
Share

Are you sure the animation "Idle_01" is attached to the animation component of your character?

avatar image YetiStudio · Jun 07, 2014 at 11:04 AM 0
Share

So first thank you all for the answers

@Landern It's actually "Perso" (it's a shortcut of "Person" in french)

@Nick4 Yes on the "Inspector" there is the component "Animation" and it's write Element 0 Idle_01 (Watch the screenshot under the first answer)

1 Reply

  • Sort: 
avatar image
1

Answer by Bilelmnasser · Jun 06, 2014 at 09:49 PM

NullReferenceException: Object reference not set to an instance of an object mean you trying to access an object that not been assigned (null) , make sure the animation is attached to your game object character :)

haha i see it now , change this line to this :

 characterContent = transform.find("Perso");
 
 //change it to this line 
 
 characterContent=gameObject.GetComponent(Perso);
 

Make sure your script is attached to the parent object Glem :)

Comment
Add comment · Show 4 · 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 YetiStudio · Jun 09, 2014 at 01:24 PM 0
Share

I'm not sure to understand, there is a screen if it can help you :s alt text

sans titre.png (228.8 kB)
avatar image Jeff-Kesselman · Jun 09, 2014 at 02:18 PM 0
Share

Use Debug.Log to print the characterContent and characterContent.animation

One of them is null. Once you find out which, you cans address why it is that way.

avatar image YetiStudio · Jun 09, 2014 at 03:23 PM 0
Share

@Jeff$$anonymous$$esselman thanks for the answer but i'm new on unity and i try to find by myself but i can't find, i check this page about the debug: http://docs.unity3d.com/ScriptReference/Debug.Log.html

But i don't understand where have i to put the commands and what put exactly ? If someone have a tutorial for me or can explain me in details step by step it's really kind (sorry for my (bad) english)

Even if the answer is obvious please post it because i'm a beginner :)

avatar image Bilelmnasser · Jun 09, 2014 at 06:51 PM 0
Share

characterContent = transform.find("Perso");

//change it to this line

characterContent=gameObject.GetComponent(Perso); $$anonymous$$ake sure your script is attached to the parent object Glem :)

Follow this Question

Answers Answers and Comments

25 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

Related Questions

NullReferenceException:"Object reference not set to an instance object" 1 Answer

Script decides not to run anymore 1 Answer

Object reference not set to an instance of an object 0 Answers

NullReferenceException: Object reference not set to an instance of an object ? 1 Answer

Referencing Objects in Unity 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