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 Foxosaur · Jun 07, 2012 at 08:29 PM · object-reference-error

Object not set to a reference(again)

Apologies for this. I know doing a != and == probably is probably open to critism but im still at the early learning stages.

I have two very basic scripts and both were working until I inserted the != part and associated var's. Can you help me pinpoint what is wrong?

robo-istat.js

 #pragma strict
 var powerup : robo_powerup;
 var Start_Player_Agility = 10;
 var Start_Player_Weight = 100;
 var Start_Player_Speed = 100;
 var Start_Jump_Speed = 2;
 var chMotor : CharacterMotor;
 var player: Transform;
 
 
 function Start () {
 
 chMotor = GetComponent(CharacterMotor);
 powerup = GetComponent(robo_powerup);
 }
 function Update () {
 
 if (powerup.triggered == true)
 { chMotor.movement.maxForwardSpeed = 1;
  print("Super Slow"); 
 }
 if (powerup.triggered != true)
 { chMotor.movement.maxForwardSpeed = Start_Player_Speed;
  print ("Normal speed");
 }
 
 
 }


Then my second script - robo_powerup.js

 #pragma strict
 var destroyedpowerup : GameObject; // Declare the object to be destroyed
 var target : Collider; //this is the variable that will hold the colliding object
 var triggered : boolean = false; //If we only want to detect the first time it's triggered
 
 
 function Start () {
 }
 
 function OnTriggerEnter(collision : Collider)
 {
 if (collision != target) //The colliding object isn't our object
 {
 return; //don't do anything if it's not our target
 }
 triggered = true;
 print("This worked");
 Destroy(destroyedpowerup);
  
 // Print - to debug testing
 // Destroy sphere
 
 }

Many thanks in advance :-)

[EDIT] Opps forgot the error - NullReferenceException: Object reference not set to an instance of an object robo-istat.Update () (at Assets/robo-istat.js:18) [/EDIT]

Comment
Add comment · Show 1
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 ExTheSea · Jun 07, 2012 at 09:00 PM 0
Share

try setting triggered in robo_powerup as a static variable like this:

static var triggered

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Jun 07, 2012 at 08:53 PM

Object reference not set to an instance of an object robo-istat.Update ()

(at Assets/robo-istat.js:18)

 function Update () 
 {
     if (powerup.triggered == true)
     {
         chMotor.movement.maxForwardSpeed = 1;
         print("Super Slow"); 
     }
     if (powerup.triggered != true)
     {
         chMotor.movement.maxForwardSpeed = Start_Player_Speed;
         print ("Normal speed");
     }
 }

The error you are getting, object reference not set to an instance (and it says which function and line it is), should help pinpoint the issue. I don't know which line it is since I don't have the line numbers, but double clicking the error would bring you to the line that caused the error. In this case, either powerup, chMotor or chMotor.movement is null, that is, not set to reference any object. Trying to access any member of a reference that doesn't lead anywhere will cause this error.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Access a Script from Another Scene? "Object Reference not set..." 1 Answer

Object reference not set to an instance of an object? C# 1 Answer

How do I pass an object to another script? 1 Answer

How to know exactly which game objects and objects are not referenced ? 1 Answer

"Object Reference not set to an instance of an object" What does it mean? 2 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