FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

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

  • ✇Recent Questions - Game Development Stack Exchange
  • Help with player strafing rotationThunderbiscuit
    Problem: Player strafes in all directions fine but when rotated 180 degrees the opposite direction he can barely move in any direction. //Move the player _controller.Move(new Vector3(_input.move.x, 0f, _input.move.y) * Time.deltaTime * MoveSpeed / 2); //Rotate the player according to the camera's x rotation _controller.gameObject.transform.rotation = Quaternion.Euler(0f, _cinemachineTargetYaw, 0f); This script is on the starter assets character controller. have also tried the following with th
     

Help with player strafing rotation

Problem:

Player strafes in all directions fine but when rotated 180 degrees the opposite direction he can barely move in any direction.

//Move the player
_controller.Move(new Vector3(_input.move.x, 0f, _input.move.y) * Time.deltaTime * MoveSpeed / 2);

//Rotate the player according to the camera's x rotation
_controller.gameObject.transform.rotation = Quaternion.Euler(0f, _cinemachineTargetYaw, 0f);

This script is on the starter assets character controller.

have also tried the following with the same effect:

_controller.gameObject.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, _cinemachineTargetYaw, 0), 15f * Time.fixedDeltaTime);

I’m thinking i shouldn’t use the camera as the rotation reference but am stuck on where to go from here Thanks for any advice or help at all

❌
❌