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);
}