Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Catlard · Jun 02, 2011 at 05:13 PM · nullreferenceexceptionparenting

Spooky NullReferenceException MYSTERY

EDIT: Someone knows what's wrong with this, but I don't understand what they're trying to tell me! Can you guys explain to to me?

Hey, folks!

So, I'm having a heck of a time trying to figure out why my code isn't compiling. It's telling me that the Object Reference is not set to an instance of an object...but i've assigned all the variables in the inspector, and I know that the syntax for the variables in the scripts I'm referencing are correct. The syntax for the script I'm referencing is also correct. But it still tells me that the placer script is null when I put in a print statement.

It points to the first if statement, where I'm first referring to "placer", when the error pops up. It might not mean anything, but the object that this script is placed on is parented to another object which is parented to the first person controller, which is where the placer script is...that wouldn't change anything, would it?

Please, any help on understanding this would be really appreciated!

Spooked,

Simon

UPDATE: I've discovered that half the time it's telling me that it knows what placer.number_of_objects is, and half the time it doesn't...

 var eyeofbeholder : GameObject;
 var placer;
 placer = eyeofbeholder.GetComponent("Music Placer");
 var thislevel: int;
 var switched = false;
 
 function Awake()
 {
     audio.volume = 0.0;
 }
 
 function Update()
 {
     if((!switched && placer.number_of_objects==thislevel && (placer.music_level != placer.number_of_objects || placer.number_of_objects == 0)) || placer.music_level == thislevel)
     {
         switched = true;
         placer.music_level = placer.number_of_objects;
         Switch();
     }
 }
 
 function Switch() 
 {
     if(audio.volume == 1.0)
     {    
         audio.volume = 0.0;
     }
     else
     {
         audio.volume = 1.0;
     }
 }
 
 function Reset()
 {
     switched = false;
 }
Comment
Add comment · Show 9
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 almo · Jun 02, 2011 at 05:30 PM 0
Share

Code reformatted. Easier if you use the code button. :)

avatar image Catlard · Jun 02, 2011 at 06:10 PM 0
Share

ah, thanks, almo! Now, if only I could figure out what the problem was....I'd be a happy man.

avatar image flaviusxvii · Jun 02, 2011 at 06:32 PM 0
Share

Take a screenshot of the inspector where you've assigned something to the 'placer' variable. Post this screenshot to imgur.com and come back with the link.

avatar image Catlard · Jun 02, 2011 at 06:40 PM 0
Share

Okay, cool...so here's the first picture I've uploaded...of the object that the script is assigned to. Next I'll upload a photo of the script I'm trying to reference, the music placer script. But the "placer" variable is just defined in the script, right? It's just a script on the eyeofbeholder object.

http://imgur.com/yzmwq

avatar image Catlard · Jun 02, 2011 at 06:48 PM 0
Share

Here's the script I'm referencing...

http://imgur.com/ryEo3

Thanks so much for the help!

S

Show more comments

3 Replies

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

Answer by Catlard · Jun 03, 2011 at 03:53 PM

I totally figured out what was wrong with this. It was a straight up situation where I was trying to call something outside of any method, so when the awake functions were running, they weren't finding it the variables they were looking for. Grrr.

Comment
Add comment · Show 2 · 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 flaviusxvii · Jun 03, 2011 at 04:01 PM 0
Share

Ahh!! I code all in C# and I didn't remember if stuff outside of functions in Javascript would implicitly be included in Start() or Awake() or something. Wow.. sorry for the wild goose chase.

avatar image Catlard · Jun 03, 2011 at 04:07 PM 0
Share

On the contrary, my good man...without you, I wouldn't even be chasing a goose. Just my own butt. Thanks for all your help! It made a big difference to know I wasn't alone in the coding universe, if nothing else.

avatar image
0
Best Answer

Answer by Catlard · Jun 02, 2011 at 07:51 PM

I'm totally psyched that you see what's wrong, but I don't quite understand what you mean. Music Placer is a script, so it can't have a component, right? So how can I have a First person controller on it?

Are you talking about in the script, or in the inspector? I'm not seeing what you've noticed.

Sorry!

Simon

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
1

Answer by flaviusxvii · Jun 02, 2011 at 07:15 PM

Ahh.. eyeOfTheBeholder is a FirstPersonController.. it doesn't have a "Music Placer" component.

Comment
Add comment · Show 3 · 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 Catlard · Jun 02, 2011 at 07:24 PM 0
Share

Hmm...it's a good thought, and I jumped to check my First Person Controller for the music placer script, but to me in the picture it looks like it does....that's what's centered in the inspector in the second picture, right?

avatar image flaviusxvii · Jun 02, 2011 at 07:42 PM 0
Share

You have a First Person Controller in your $$anonymous$$usic Placer.. not the other way around.

avatar image Catlard · Jun 03, 2011 at 12:59 AM 0
Share

I'm totally psyched that you see what's wrong, but I don't quite understand what you mean. $$anonymous$$usic Placer is a script, so it can't have a component, right? So how can I have a First person controller on it?

Are you talking about in the script, or in the inspector? I'm not seeing what you've noticed.

Sorry!

Simon

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Instantiating child as parent not working : Object Pooling 1 Answer

Null Ref Exception on Tag of Parent Transform 1 Answer

NullReferenceException with SwitchController script 1 Answer

C# variable type problem, always get NullRefExc 1 Answer

Errors with Image Effects 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