- Home /
Question by
miksugains · Jul 12, 2016 at 11:48 AM ·
errornullreferenceexception
NullReferenceException: Object reference not set to an instance of an object
public void EndSpell () {
movement.setCanWalk (true);
animator.SetInteger ("Spell", 0);
GameObject projectile = (GameObject) Instantiate (selectedSpell.prefab, transform.position, Quaternion.Euler (new Vector3 (0, 0, dir))); //TODO ERROR
Physics2D.IgnoreCollision (myCollider, projectile.GetComponent<Collider2D> ());
Projectile_Movement movementScript = projectile.GetComponent<Projectile_Movement> ();
movementScript.caster = gameObject;
Vector3 v = new Vector3 (worldPoint.x - transform.position.x, worldPoint.y - transform.position.y, 0);
movementScript.SetDestination (transform.position, v.normalized);
selectedSpell = null;
selectedSlot = -1;
RefreshActionBarColors ();
}
That is my code (do you need more of it?) and the error is in the line "//TODO ERROR". I have searched all over google but no solution for my case. Something is null but what? The error comes everytime when I cast a spell in my game but it still kinda works. Please someone help.. :)
Comment
This means that 'selectedSpell.prefab' is null. See if that helps...
I just got back to the project and fixed it with your help. Thanks man!! Never too late to say thank you :P