- Home /
Another NullReferenceException: question...(Java)
I've been working on a project from Unity blueprints by DeepPixel. It's a top down spaceship shooter. I've been trying to solve this for a few days now and am coming up empty. The problem happens specifically when the player ship is destroyed and respawns gaining a temporary invincibility. The error is: NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) gameManager.respawnPlayer () (at Assets/_scripts/gameManager.js:119) gameManager.Update () (at Assets/_scripts/gameManager.js:42)
The lines of code referenced are 42:
function Update () {
if (respawn == true && playerLives != 0)
{
/*Line42*/ respawnPlayer();
}
}
and line 119:
function respawnPlayer()
{
startTime = Time.time;
player1 = Instantiate(playerObj,playerSpwn.transform.position,playerObj.transform.rotation) as GameObject;
var script1 = player1.transform.gameObject.GetComponent("shipController");
script1.playerInvincible = true;
script1.shieldOn = true;
respawn = false;
}
I apologize for the length. Any help on understanding the error is appreciated regardless if it fixes it or not.
Im guessing this is line 119:
player1 = Instantiate(playerObj,playerSpwn.transform.position,playerObj.transform.rotation) as GameObject;
Answer by perchik · Mar 05, 2014 at 08:39 PM
Check to see if the script1 is null:
var script1 = player1.transform.gameObject.GetComponent("shipController");
if(script1== null) Debug.LogError("heres my problem...instantiated player doesn't have a shipController component");
Thanks for the trouble shoot. Sure enough the instantiated clone is co$$anonymous$$g up empty! I never even considered that would be the problem.
Your answer
Follow this Question
Related Questions
What is wrong with my script? 1 Answer
Object reference not set to an instance of an object help (JS) 0 Answers
NullReferenceException 1 Answer
Object reference not set to an instance of an object 1 Answer
Hi I get an error code when i'm using my Javascript and I can't understand how to fix it... :( 1 Answer