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 Jul 29, 2013 at 04:08 AM by Kawaburd for the following reason:

Solved by self

avatar image
0
Question by Kawaburd · Jul 29, 2013 at 01:47 AM · nullreferenceexceptiongetcomponent

NullReferenceException. GetComponent not working?

I'm trying to write a map generator by having the different major functions in seperate scripts, and having one main one run the show. Problem is, my main script doesn't know the other ones exist.

In MainMapGen.js:

 // Parent script for all map-generator stuff.
 
 #pragma strict
 //Instantiate all necessary subscripts.
 
 function Start () {
 
 var C_Level : Level = gameObject.GetComponent(Level);
 var C_Sequences: Sequences = gameObject.GetComponent(Sequences);
 var C_Sequencer: LevelSequencer = gameObject.GetComponent(LevelSequencer);
 
 
 Debug.Log (C_Sequencer);
 C_Sequencer.RunSequence('level1');
 //Test code.  Sequence level 1 no matter what.
 
 }

In LevelSequencer.js:

 #pragma strict
 
 var sequence: String;
 
 function RunSequence (sequence) {
 
     Debug.Log('Testing switch:');
     switch (sequence) {
     case 'level1':
         Debug.Log('Everything is ok so far.');
         
         
     }
 }

Both scripts are currently tacked to my main character. I have nearly identical calls in older scripts, but for some reason they work, this doesn't. I figured I made a stupid mistake somewhere, but there's no apparent syntactic differences. What am I doing wrong here?

The full error is: NullReferenceException: Object reference not set to an instance of an object MainMapGen.Start () (at Assets/Scripts/MapGen/MainMapGen.js:14)

Comment
Add comment · Show 6
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 ExplodingCookie · Jul 29, 2013 at 02:18 AM 0
Share

Do you have the Level and Sequence scripts on your character? Also, JS and C# have occasional communication issues.

~ExplodingCookie

avatar image aldonaletto · Jul 29, 2013 at 02:24 AM 0
Share

This should work. Are you sure that $$anonymous$$ain$$anonymous$$apGen and LevelSequencer (as well as the other scripts) are attached to the same object? It won't work if they are at different hierarchy levels (one at the parent, other at the child, for instance).

avatar image Benproductions1 · Jul 29, 2013 at 03:01 AM 0
Share

What line is your error on? You should always post the whole error, or else there are way too many places it could be :)

avatar image Kawaburd · Jul 29, 2013 at 03:44 AM 0
Share

I didn't have all 4 sequences on him, but I tried that now and it didn't change anything. (Level/Sequences are blank while I try to make sure the framework itself works for what I'm trying to do). Checking the parenting, everything's on the same level. I had a 2nd copy of $$anonymous$$ain$$anonymous$$apGen on the model's cylinder, but removing that didn't fix. It just removed one instance of the error (which got thrown twice, so that was A problem at least.)

All my scripts are in js. I did that in hopes of not mashing langs together in my head and causing a veritable $$anonymous$$efield of syntax errors in the process. ^^;

The fill error in question is: NullReferenceException: Object reference not set to an instance of an object $$anonymous$$ain$$anonymous$$apGen.Start () (at Assets/Scripts/$$anonymous$$apGen/$$anonymous$$ain$$anonymous$$apGen.js:14)

And my Debug.Log above threw 'null', which AFAI$$anonymous$$ just tells me the same thing.

avatar image Benproductions1 · Jul 29, 2013 at 04:06 AM 0
Share

Can you replicate it in an empty scene?

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

19 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

Related Questions

NullReferenceException-Error when trying to GetComponent 3 Answers

Why is this null? Finding a script on an object 3 Answers

NullReferenceException. GetComponent dose not work properly 2 Answers

NullRef on my parent script 1 Answer

NullReferenceException: 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