So when I’m in the editor it’s all fine, no errors at all but when I build and run it’s just a black screen, I turned on the dev console and saw that I got “NullReferenceExpection: Object reference not set to an instance of an object”. I know what the error means when in the editor but I’ve never got it after I built the game. ![]()
I’m currently on a mac with the new os, maybe that’s why it’s not working? I’ve tried all the mac build options. Gonna try on my pc later today but if someone knows what may cause this I would be happy to know!
EDIT: It’s not working with the webplayer verision as well ![]()
EDIT 2: Added a 1 of how it looks when in the editor, building and playing the build.
EDIT 3: So I found out how to check the logs and found this:
NullReferenceException: Object reference not set to an instance of an object
at Brick.Update () [0x00068] in /Users/Something37/BrickBuster/Assets/Scripts/Brick.cs:36
(Filename: /Users/Something37/BrickBuster/Assets/Scripts/Brick.cs Line: 36)
Here is the code for that script:
using UnityEngine;
using System.Collections;
public class Brick : MonoBehaviour {
public int health;
public Material[] materialFromHealth;
public float moveSpeed;
public GameObject[] powerups;
int scoreBoost = 1;
GameObject ls;
LevelSystem system;
void Start(){
ls = GameObject.FindWithTag("LevelSystem");
system = ls.GetComponent<LevelSystem>();
}
void Update () {
switch(health){ //Check how much health the brick has and change texture after that
case 1:
renderer.material = materialFromHealth[0];
break;
case 2:
renderer.material = materialFromHealth[1];
break;
case 3:
renderer.material = materialFromHealth[2];
break;
}
if(system.ScoreBooster)scoreBoost=2;
else if(!system.ScoreBooster)scoreBoost=1;
if(health<=0){ //Checks if the brick is dead
system.score += 40 * scoreBoost;
system.bricksDestroyed += 1;
system.PlayDeathSound();
int powerup = Random.Range(0,15);
if(powerup==0)Instantiate(powerups[0], transform.position, transform.rotation);
if(powerup==1)Instantiate(powerups[1], transform.position, transform.rotation);
if(powerup==2)Instantiate(powerups[2], transform.position, transform.rotation);
if(powerup==3)Instantiate(powerups[3], transform.position, transform.rotation);
if(powerup==4)Instantiate(powerups[4], transform.position, transform.rotation);
if(powerup==5)Instantiate(powerups[5], transform.position, transform.rotation);
Destroy(gameObject);
}
else if(system.LevelComplete)Destroy(gameObject);
}
void OnCollisionEnter(Collision other){
if(other.gameObject.tag=="Player"){
system.score += 10 * scoreBoost;
health-=1;
}
foreach(ContactPoint contact in other.contacts){
if(contact.thisCollider == collider){
float sideSpeed = contact.point.x - transform.position.x;
contact.otherCollider.rigidbody.AddForce(100f * sideSpeed,0,0);
}
}
}
}
This is row 36:
if(system.ScoreBooster)scoreBoost=2;
else if(!system.ScoreBooster)scoreBoost=1;
//Elis
Have you made sure to include all scenes that are used when building?
– VioKymaCan you post the code where the error occurs please ? Since you know what this error means, did you try the basics to debug it ? (Debug.Log, breakpoints ...) ? Is it a multiplayer problem ?
– KiraSenseiThe scene is added in the build, and no, I cant post the code where the error occurs, in the editor it's all fine and I can play the game, however when I build the game (with dev console enabled) it's a black screen and the console is spammed with "NullReferenceExpection: Object reference not set to an instance of an object", nothing else, nothing about a certain script or something :/
– EllisYou should still be able to run the [debugger][1] attached to the build. Have you tried that? [1]: http://docs.unity3d.com/Documentation/Manual/Debugger.html
– Peter_GHmm, didn't know about that. However I can't really figure out how it works with the new monodevelop. Would need to debug my whole build then since it works fine in the editor. :/
– Ellis