• 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 Jun 02, 2011 at 01:06 AM by Bravini for the following reason:

null reference exception question on a long script without pointing the lines of the error(s).

avatar image
0
Question by Catlard · Jun 02, 2011 at 01:01 AM · nullreferenceexception

Null script error...in the Sylvester Stallone of scripts.

Hey folks!

Just a simple coding error--with a really long, brute force script! I couldn't figure out how to put the scripts in an array, so I'm just doing this the hard way. But that's not the problem. The problem is that it's telling me there's a NullReferenceException, and that the Object Reference is not set to an instance of the object, and pointing to the first time I attempt to reference one of my scripts' Switch functions. All the scripts are the same, actually...just on eleven different objects. Print statements are telling me that the script that's giving me the error is Null...so I guess I'm not referencing any of this correctly?

I will tell tales of your heroism to all my friends in my design studio, if you can help me figure this one out. Thanks so much for your time. I feel stuck, right now...

Simon.

var maincamera:Camera; var eyeofbeholder : GameObject; var destroyer; destroyer = eyeofbeholder.GetComponent("Character Destroyer"); var wind_audio_object: GameObject; var backbeat_audio_object: GameObject; var banjo_audio_object: GameObject; var bass_audio_object: GameObject; var melody_audio_object: GameObject; var kick_and_hh_audio_object: GameObject; var tamborine_audio_object: GameObject; var snare_and_funk_audio_object: GameObject; var disco_hh_audio_object: GameObject; var mooooo_audio_object: GameObject; var boingy_audio_object: GameObject; var aloha_audio_object: GameObject;

var wind_audio_script; var backbeat_audio_script; var banjo_audio_script; var bass_audio_script; var melody_audio_script; var kick_and_hh_audio_script; var tamborine_audio_script; var snare_and_funk_audio_script; var disco_hh_audio_script; var mooooo_audio_script; var boingy_audio_script; var aloha_audio_script;

wind_audio_script = eyeofbeholder.GetComponent("Audio Switch"); backbeat_audio_script = eyeofbeholder.GetComponent("Audio Switch"); banjo_audio_script = eyeofbeholder.GetComponent("Audio Switch"); bass_audio_script = eyeofbeholder.GetComponent("Audio Switch"); melody_audio_script = eyeofbeholder.GetComponent("Audio Switch"); kick_and_hh_audio_script = eyeofbeholder.GetComponent("Audio Switch"); tamborine_audio_script = eyeofbeholder.GetComponent("Audio Switch"); snare_and_funk_audio_script = eyeofbeholder.GetComponent("Audio Switch"); disco_hh_audio_script = eyeofbeholder.GetComponent("Audio Switch"); mooooo_audio_script = eyeofbeholder.GetComponent("Audio Switch"); boingy_audio_script = eyeofbeholder.GetComponent("Audio Switch"); aloha_audio_script = eyeofbeholder.GetComponent("Audio Switch");

var flower:Transform; var bee:Transform; var cloud:Transform; var butterfly:Transform; var sign:Transform; var mesa:Transform; var mushroom:Transform; var tree:Transform; var cow:Transform; var rock:Transform; var rainbow:Transform;

var music_level = 0; var loop_length = 18; var number_of_objects = 0; var mybeat; var timecount = 0.00; var currentbeat = 0.00;

function Start() { StartLoop(); }

function StartLoop() { number_of_objects = destroyer.combocount; if(number_of_objects >= 1) { Invoke("Flower", .75); } if(number_of_objects >= 2) { Invoke("Bee", .75); } if(number_of_objects >= 3) { Invoke("Cloud", .75); } if(number_of_objects >= 4) { Invoke("Butterfly", .75); } if(number_of_objects >= 5) { Invoke("Sign", .75); } if(number_of_objects >= 6) { Invoke("Mesa", .75); } if(number_of_objects >= 7) { Invoke("Mushroom", .75); } if(number_of_objects >= 8) { Invoke("Tree", .75); } if(number_of_objects >= 9) { Invoke("Cow", .75); } if(number_of_objects >= 10) { Invoke("Rock", .75); } if(number_of_objects >= 11) { Invoke("Rainbow", .75); } if(music_level != number_of_objects || number_of_objects == 0) { switch(music_level) { case 0: wind_audio_script.Switch(); break; case 1: backbeat_audio_script.Switch(); break; case 2:
banjo_audio_script.Switch();
break; case 3:
bass_audio_script.Switch();
break; case 4:
melody_audio_script.Switch();
break; case 5:
kick_and_hh_audio_script.Switch();
break; case 6:
tamborine_audio_script.Switch();
break; case 7:
snare_and_funk_audio_script.Switch();
break; case 8:
disco_hh_audio_script.Switch();
break; case 9:
mooooo_audio_script.Switch();
break; case 10:
boingy_audio_script.Switch();
break; case 11:
aloha_audio_script.Switch(); break; } music_level = number_of_objects; switch(music_level) { case 0: wind_audio_script.Switch(); break; case 1: backbeat_audio_script.Switch(); break; case 2:
banjo_audio_script.Switch();
break; case 3:
bass_audio_script.Switch();
break; case 4:
melody_audio_script.Switch();
break; case 5:
kick_and_hh_audio_script.Switch();
break; case 6:
tamborine_audio_script.Switch();
break; case 7:
snare_and_funk_audio_script.Switch();
break; case 8:
disco_hh_audio_script.Switch();
break; case 9:
mooooo_audio_script.Switch();
break; case 10:
boingy_audio_script.Switch();
break; case 11:
aloha_audio_script.Switch(); break; } } Invoke("StartLoop",loop_length); }

function Flower() { mybeat = Instantiate (flower, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5), Quaternion.identity); mybeat.tag = "Flower"; }

function Bee() { mybeat = Instantiate (bee, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5), Quaternion.identity); mybeat.tag = "Bee"; }

function Cloud() { mybeat = Instantiate (cloud, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5), Quaternion.identity); mybeat.tag = "Cloud"; }

function Butterfly() { mybeat = Instantiate (butterfly, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5), Quaternion.identity); mybeat.tag = "Butterfly"; }

function Sign() { mybeat = Instantiate (sign, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5), Quaternion.identity); mybeat.tag = "Sign"; }

function Mesa() { mybeat = Instantiate (mesa, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5), Quaternion.identity); mybeat.tag = "Mesa"; }

function Mushroom() { mybeat = Instantiate (mushroom, Vector3(-10, 1.7, transform.position.z+maincamera.farClipPlane), Quaternion.identity); mybeat.tag = "Mushroom"; }

function Tree() { mybeat = Instantiate (tree, Vector3(-10, 1.7, transform.position.z+maincamera.farClipPlane), Quaternion.identity); mybeat.tag = "Tree"; } function Cow() { mybeat = Instantiate (cow, Vector3(-10, 1.7, transform.position.z+maincamera.farClipPlane), Quaternion.identity); mybeat.tag = "Cow"; }

function Rock() { mybeat = Instantiate (rock, Vector3(10, 1.7, transform.position.z+maincamera.farClipPlane+1), Quaternion.identity); mybeat.tag = "Rock"; }

function Rainbow() { mybeat = Instantiate (rainbow, Vector3(10, 1.7, transform.position.z+maincamera.farClipPlane+1), Quaternion.identity); mybeat.tag = "Rainbow"; }

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

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Checking for null against Texture2D 0 Answers

How do I check if an object is null? 6 Answers

Variable Assigning with GameObject.Find("") causing NullReferenceException? 0 Answers

Anyone Else wanna take a wack at the question ? Need help fixing a script error... 5 Answers

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