Skip to main content
My typo
Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Unity NullreferenceexceptionNullReferenceException even though I see it's not in the debugger

typos
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Unity NullReferenceNullreferenceexception even though iI see itsit's not in the debugger

This is the full error:

NullReferenceException: Object reference not set to an instance of an object.

Variable activeWeapon is set to an instance in the Unity editor. The problem occurs when setting the bullet.transform.position. I can follow the Debugger and see that activeWeapon is not null when I step into and after that line. But when I step out of the function, then I get the error above. Even when I use activeWeapon.Transformtransform I get the same error. Using

Using the player's transform shoots the bullet from the player, and not from the active weapon's position.

public void weaponAttack()
{
    GameObject bullet = ObjPoolWeapon.Instance.GetPooledObj();
    //Vector3 spawnLocation = activeWeapon.transform.position + activeWeapon.spawnLocationWM;
    **bullet.transform.position = activeWeapon.spawnLocationGO.transform.position;**
    bullet.transform.rotation = Quaternion.identity;
    bullet.SetActive(true);
}

image of debugger

Unity NullReference even though i see its not in the debugger

This is the full error:

NullReferenceException: Object reference not set to an instance of an object.

Variable activeWeapon is set to an instance in the Unity editor. The problem occurs when setting the bullet.transform.position. I can follow the Debugger and see that activeWeapon is not null when I step into and after that line. But when I step out of the function, then I get the error above. Even when I use activeWeapon.Transform I get the same error. Using the player's transform shoots the bullet from the player, and not from the active weapon's position.

public void weaponAttack()
{
    GameObject bullet = ObjPoolWeapon.Instance.GetPooledObj();
    //Vector3 spawnLocation = activeWeapon.transform.position + activeWeapon.spawnLocationWM;
    **bullet.transform.position = activeWeapon.spawnLocationGO.transform.position;**
    bullet.transform.rotation = Quaternion.identity;
    bullet.SetActive(true);
}

image of debugger

Unity Nullreferenceexception even though I see it's not in the debugger

This is the full error:

NullReferenceException: Object reference not set to an instance of an object.

Variable activeWeapon is set to an instance in the Unity editor. The problem occurs when setting the bullet.transform.position. I can follow the Debugger and see that activeWeapon is not null when I step into and after that line. But when I step out of the function, then I get the error above. Even when I use activeWeapon.transform I get the same error.

Using the player's transform shoots the bullet from the player, and not from the active weapon's position.

public void weaponAttack()
{
    GameObject bullet = ObjPoolWeapon.Instance.GetPooledObj();
    //Vector3 spawnLocation = activeWeapon.transform.position + activeWeapon.spawnLocationWM;
    **bullet.transform.position = activeWeapon.spawnLocationGO.transform.position;**
    bullet.transform.rotation = Quaternion.identity;
    bullet.SetActive(true);
}

image of debugger

Improved formatting and grammar
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

This is the full error: NullReferenceException: Object reference not set to an instance of an object.

NullReferenceException: Object reference not set to an instance of an object.

Variable activeWeapon is set to an instance in the Unity editor. The problem occurs when setting the bullet.transform.position. I can follow the Debugger and see that activeWeapon is not null when I step into and after that line. But when I step out of the function, then I get the error above. Even when I use activeWeapon.Transform I get the same error. Using the player's transform shoots the bullet from the player, and not from the active weapon's position.

public void weaponAttack()
{
    GameObject bullet = ObjPoolWeapon.Instance.GetPooledObj();
    //Vector3 spawnLocation = activeWeapon.transform.position + activeWeapon.spawnLocationWM;
    **bullet.transform.position = activeWeapon.spawnLocationGO.transform.position;**
    bullet.transform.rotation = Quaternion.identity;
    bullet.SetActive(true);
}

image of debugger

This is the full error: NullReferenceException: Object reference not set to an instance of an object.

Variable activeWeapon is set to an instance in the Unity editor. The problem occurs when setting the bullet.transform.position. I can follow the Debugger and see that activeWeapon is not null when I step into and after that line. But when I step out of the function, then I get the error above. Even when I use activeWeapon.Transform I get the same error. Using the player's transform shoots the bullet from the player, and not from the active weapon's position.

public void weaponAttack()
{
    GameObject bullet = ObjPoolWeapon.Instance.GetPooledObj();
    //Vector3 spawnLocation = activeWeapon.transform.position + activeWeapon.spawnLocationWM;
    **bullet.transform.position = activeWeapon.spawnLocationGO.transform.position;**
    bullet.transform.rotation = Quaternion.identity;
    bullet.SetActive(true);
}

image of debugger

This is the full error:

NullReferenceException: Object reference not set to an instance of an object.

Variable activeWeapon is set to an instance in the Unity editor. The problem occurs when setting the bullet.transform.position. I can follow the Debugger and see that activeWeapon is not null when I step into and after that line. But when I step out of the function, then I get the error above. Even when I use activeWeapon.Transform I get the same error. Using the player's transform shoots the bullet from the player, and not from the active weapon's position.

public void weaponAttack()
{
    GameObject bullet = ObjPoolWeapon.Instance.GetPooledObj();
    //Vector3 spawnLocation = activeWeapon.transform.position + activeWeapon.spawnLocationWM;
    **bullet.transform.position = activeWeapon.spawnLocationGO.transform.position;**
    bullet.transform.rotation = Quaternion.identity;
    bullet.SetActive(true);
}

image of debugger

Source Link
Loading