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 Grpm · Feb 19, 2014 at 09:15 PM · javascriptgetcomponent

Object reference not set to an instance of an object

Hello im new to scripting and im getting an error trying to acces an component on other script a float value in a array i can figure out what im doing wrong please help and if its other ways of doing this

first this is the script that is accesing the value

 #pragma strict
 var audioSource : GameObject;
 var cancion : sonido = audioSource.GetComponent(sonido);
   
 function  Start (){
 
     if (cancion.band[6] > 0.3){
     
     Debug.Log ("mayor");
     }
 
  
 }



this is the second one that is getting accesed

 var freqData:float[] = new float[8192];
 
 var listener : AudioListener;
 
  
 
 var band:float[];
 
 var g:GameObject[];
 
  
 
 function Start()
 
 {
 
     var n:int = freqData.length;
 
     var k:int = 0;
 
     for(var j=0;j<freqData.length;j++)
 
     {
 
         n /= 2;
 
         if(!n) break;
 
         k++;
 
     }
 
     band  = new float[k+1];
 
     g     = new GameObject[k+1];
 
     for (var i=0;i<band.length;i++)
 
     {
 
         band[i] = 0;
 
         g[i] = new  GameObject.CreatePrimitive(PrimitiveType.Sphere);
 
         g[i].transform.position = Vector3(i,0,0);
 
     }
 
     InvokeRepeating("check", 0, 1.0/15.0); // update at 15 fps
 
 }
 
  
 
 function check()
 
 {
 
     listener.GetSpectrumData(freqData, 0, FFTWindow.Rectangular);
 
         
 
     var k:int = 0;
 
     var crossover:int = 2;  
 
     for(var i:int;i< freqData.length;i++)
 
     {   
 
         var d = freqData[i];
 
         var b = band[k];        
 
         band[k] = (d>b)? d:b;   // find the max as the peak value in that frequency band.
 
         if (i>crossover-3)
 
         {
 
             k++;
 
             crossover *= 2;   // frequency crossover point for each band.
 
             g[k].transform.position.y = band[k]*32;
 
             band[k] = 0;
 
         }   
 
     }
 
 }
 
 private var sqrt = Mathf().Sqrt;
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 mattyman174 · Feb 19, 2014 at 11:22 PM 0
Share

You should always check that an Object is not Null before you try and access it like this, especially if its another component on another GameObject.

     function Start()
     {
         if (cancion != null)
         {
             if (cancion.band[6] > 0.3f)
             {
                 Debug.Log("$$anonymous$$ayor");
             }
         }
         else
         {
             Debug.LogError("Your cancion Object is NULL, you were about to access a NULL Object");
         }
     }

Start with that and see how you go. That should give you a clue i hope :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Commander5518 · Feb 21, 2014 at 02:52 PM

This simply means, as mattyman174 said that one of your variables is unassigned or not assigned to something that Unity expects.

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

20 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

What will happen if I GetComponent in this way? (Example) 1 Answer

How to use "GetComponent" and "transform" code in dll file? 0 Answers

disable/enable Mouse Look(c#) with a script of js 7 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