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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Exported Game Fails, but The In-Unity One Works

Discussion in 'Scripting' started by cjburkey01, Apr 14, 2014.

  1. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    Hello. I'm using the Detonator Framework, and it works fine in the Unity editor. No problems, perfectly fine. But when I export it. I get a NullReferenceEception. It says after that: Object reference not set to an instance of an Object.

    Here is the code for spawning an explosion:
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var ragdoll : Transform;
    5. var carpet : Transform;
    6. var player : Transform;
    7. var boom : Transform;
    8. var wall : Transform;
    9. var nuke : Transform;
    10. var ragdollCount : int;
    11. var carpetCount : int;
    12. var hSliderValue : float = 1.0;
    13.  
    14. function OnGUI() {
    15.  
    16.     ragdollCount = GameObject.FindGameObjectsWithTag("Ragdoll").Length;
    17.     carpetCount = GameObject.FindGameObjectsWithTag("Carpet").Length;
    18.  
    19.     GUI.Box(Rect(170,10,150,30), "" + player.position.x);
    20.     GUI.Box(Rect(170,50,150,30), "" + player.position.y);
    21.     GUI.Box(Rect(170,90,150,30), "" + player.position.z);
    22.     GUI.Box(Rect(170,130,150,30), ragdollCount + " Ragdolls");
    23.     GUI.Box(Rect(170,170,150,30), carpetCount + " Carpets");
    24.     hSliderValue = GUI.HorizontalSlider(Rect(170,210,150,30), hSliderValue, 0.0, 1.0);
    25.     Time.timeScale = hSliderValue;
    26.    
    27.     if (GUI.Button(Rect(10,10,150,30),"Spawn A Ragdoll")) {
    28.         Debug.Log("Spawning Thing");
    29.         Instantiate(ragdoll, Vector3(player.position.x, 10, player.position.z), Quaternion.identity);
    30.     }
    31.    
    32.     if (GUI.Button(Rect(10,50,150,30),"Spawn 10 Ragdolls")) {
    33.         Debug.Log("Spawning Thing");
    34.         for(var i : int = 0; i < 10; i++) {
    35.             Instantiate(ragdoll, Vector3(player.position.x, 10, player.position.z), Quaternion.identity);
    36.         }
    37.     }
    38.    
    39.     if (GUI.Button(Rect(10,90,150,30),"Spawn 100 Ragdolls")) {
    40.         Debug.Log("Spawning Thing");
    41.         for(var j : int = 0; i < 100; i++) {
    42.             Instantiate(ragdoll, Vector3(player.position.x, 10, player.position.z), Quaternion.identity);
    43.         }
    44.     }
    45.    
    46.     if (GUI.Button(Rect(10,130,150,30),"Delete A Ragdoll")) {
    47.         Debug.Log("Deleting Thing");
    48.         Destroy(GameObject.FindWithTag("Ragdoll"));
    49.     }
    50.    
    51.     if (GUI.Button(Rect(10,170,150,30),"(Disabled)")) {
    52.         Debug.Log("Spawning Thing");
    53.         //Instantiate(carpet, Vector3(player.position.x, 10, player.position.z), Quaternion.identity);
    54.     }
    55.    
    56.     if (GUI.Button(Rect(10,210,150,30),"(Disabled)")) {
    57.         Debug.Log("Spawning Thing");
    58.         for(var k : int = 0; i < 100; i++) {
    59.             //Instantiate(carpet, Vector3(player.position.x, 10, player.position.z), Quaternion.identity);
    60.         }
    61.     }
    62.    
    63.     if (GUI.Button(Rect(10,250,150,30),"Delete A Carpet")) {
    64.         Debug.Log("Deleting Thing");
    65.         Destroy(GameObject.FindWithTag("Carpet"));
    66.     }
    67.    
    68.     if (GUI.Button(Rect(10,290,150,30),"Boom Wall")) {
    69.         Debug.Log("Boom Wall");
    70.         Instantiate(boom, Vector3(6, 0.67, 60), Quaternion.identity);
    71.     }
    72.    
    73.     if (GUI.Button(Rect(10,330,150,30),"Reload Wall")) {
    74.         Debug.Log("Reload Wall");
    75.         Destroy(GameObject.FindWithTag("Wall"));
    76.         Instantiate(wall, Vector3(6, 0.67, 60), Quaternion.identity);
    77.     }
    78.    
    79.     if (GUI.Button(Rect(10,370,150,30),"Reload Game")) {
    80.         Debug.Log("Reload Game");
    81.         Application.LoadLevel(Application.loadedLevel);
    82.     }
    83.    
    84.     if (GUI.Button(Rect(10,410,150,30),"Nuke")) {
    85.         Debug.Log("Nuke");
    86.         Instantiate(nuke, Vector3(player.position.x + 25, player.position.y, player.position.z + 25), Quaternion.identity);
    87.         Instantiate(boom, Vector3(player.position.x + 25, player.position.y, player.position.z + 25), Quaternion.identity);
    88.     }
    89.    
    90. }
    91.  
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    The most obvious answer is that you havent assigned a gameobject to the ragdoll/carpet/boom/nuke etc variables, in the inspector
     
  3. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    Well, then why does it work the the game view of Unity. It only fails in the export
     
  4. qorthos

    qorthos

    Joined:
    Apr 13, 2014
    Posts:
    6
    Is your game using something in the Assets/Editor directory?
     
  5. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    Yes, but it works for other things. That's what I don't get
     
  6. qorthos

    qorthos

    Joined:
    Apr 13, 2014
    Posts:
    6
    As far as I'm aware, Unity does not include include UnityEditor namespace or Assets/Editor in final builds. Try moving your assets out of the Assets/Editor folder and try again.
     
  7. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    where is that? It's not in the project file
     
  8. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    OHH, the answer to that question is no. I am not, I didn't understand that :p
     
  9. qorthos

    qorthos

    Joined:
    Apr 13, 2014
    Posts:
    6
    Oh, well, nuts.

    Do you know which object is actually null? I'm guessing it's either Ragdoll or Carpets.
     
  10. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    It's the Bomb Object that causes the error. When ever I click the Boom Wall button, or the Nuke button, it spams the console with that error(the dev console export feature) until you reload the application. I am using this for the explosions:
    http://u3d.as/content/ben-throop/detonator-explosion-framework/1qK
     
  11. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26
    Are we allowed to bump(sorry I'm a newb)
     
  12. cjburkey01

    cjburkey01

    Joined:
    Nov 8, 2013
    Posts:
    26