Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

JavaScript: BCE0055: Internal compiler error: Object reference not set to an instance of an object.

Discussion in 'Scripting' started by NearlyANinja, Jun 20, 2014.

  1. NearlyANinja

    NearlyANinja

    Joined:
    Apr 5, 2014
    Posts:
    1
    I'm trying to use a random number generator to select the next section of an area but for some reason i'm getting the error "BCE0055: Internal compiler error: Object reference not set to an instance of an object." on line 5

    I've never received this error before and searching through the forums i've only stumbled across issues with redefining variables within the same class. Except i'm using a switch/case statement rather than 20 different if/else statements simply because of the ((soon to be)) large amount of stages.

    So if i'm not redefining already set variables then what is the issue??


    Code (JavaScript):
    1. var getNext = function(next){
    2.     var stage = Random.Range(0,2);
    3.     Debug.Log(stage);
    4.     if(next == "secA"){
    5.         switch(stage){
    6.             case 0:
    7.                 secA = s1;
    8.                 next = "secB";
    9.                 Debug.Log(next);
    10.                 break;
    11.             case 1:
    12.                 secA = s2;
    13.                 next = "secB";
    14.                 Debug.Log(next);
    15.                 break;
    16.             case 2:
    17.                 secA = s3;
    18.                 next = "secB";
    19.                 Debug.Log(next);
    20.                 break;
    21.             default:
    22.                 Debug.LogError("Stage chooser F***ed up.");
    23.         }
    24.     }
    25. }
     
    Last edited: Jun 20, 2014
  2. Amon

    Amon

    Joined:
    Oct 18, 2009
    Posts:
    1,357
    it's complaining about line 5. I'm going to assume that 'stage' is the problem. Is the script attatched to a stage Prefab or GameObject?

    Is stage another script?

    Basically this error only occurs when you try to do anything on something that has not been instantiated, initiated etc!
     
  3. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    stage is declared in line 2 as an int.
     
  4. Erisat

    Erisat

    Joined:
    Jan 31, 2013
    Posts:
    88
    well stage is "var stage = Random.Range(0,2);" on line two. I had an issue before using random.range in that the compiler couldn't decide what i meant by Random, because if you have imported system and unityengine together, youll end up with UnityEngine.Random and System.Random. ive had that issue before. not sure if this is your problem though because i would think that the compiler would have yelled about it sooner than line 5 >.> just throwing in my two cents. Im not sure about it.