SharedGameObject turns null

Murat

New member
Hello All,

I am trying to create a seek and destroy behaviour. It works fine until the target runs away. Then it throws an NullRefException in the "IsInGunRange" class.

Screenshot 2020-07-21 at 18.43.09.png


A snippet from IsInGunRange class:

C#:
public override TaskStatus OnUpdate() {
        if (target.Value.transform != null) {
            Debug.Log(target.Value.transform);
            Transform t = target.Value.transform;

            if (Vector3.Distance(t.position, transform.position) < weapon.range) {
                return TaskStatus.Success;
            }

        }
        return TaskStatus.Failure;
    }

"target" is a SharedGameObject that is returned by "CanSeeObject". Null reference exception throws on the null check line. I don't understand why the sequence won't abort when "CanSeeObject" fails. I tried every kind of conditional aborts.
 
The sequence task will stop when the Can See Object task fails. My guess is that there is another location that Is In Gun Range that is used.
 
Top