Enemy AI stopped working (null ref)

So all of the sudden my enemies dont do anything when i attack or get in range. When i get in the range of an enemy, Unity is giving me a null reference on my fighter script for the GetIsInRange() function and when it calls it in update. Dont know exactly what just happened? any thoughts? I hadnt changed anything in those section. I wonder if it has to do with the progression SO attached to the units. Everything else seems to be working.

private bool GetIsInRange() { return Vector3.Distance(transform.position, target.transform.position) < currentWeapon.GetWeaponRange(); }

There are two things that can be null in this method:
target (target.transform.position) or currentWeapon (currentWeapon.GetWeaponRange();

Usually, the issue here is the target. If you don’t have a current target, then the method can’t get the target.transform.position.

The best solution for this is to start the Update() method with:

if(target==null) return;
1 Like

Oh wow i found the issue, somehow in my Start function I lost an = in my if statement

       if(currentWeapon == null)
        {
            //then equip defualt otherwise the save system has already done its job
            EquipWeapon(defaultWeapon);
        }

i had if(currentWeapon = null). Sometimes i feel like I’m going cross-eyed looking for syntax errors (especially when still compile)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms