Destroying an object doesn't clear your reference to it.

The problem
A null check that always passes.
GameObject _target; protected override void OnUpdate(){ if ( _target == null ) return; AimAt( _target.WorldPosition );}
After the target is destroyed, _target still holds the old reference. It is not null.
The fix
Ask if it is still there.
IsValid() is false for null and false for destroyed, so one call covers both.
nullordestroyed→IsValid() is false
The fix in code
One check for both.
protected override void OnUpdate(){ if ( !_target.IsValid() ) { _target = FindTarget(); return; } AimAt( _target.WorldPosition );}
Gone? Find a new one. It's an extension method, so it is safe to call on null.
Also
Lists hold on to the dead too.
// drop every enemy that was destroyed_enemies.RemoveAll( e => !e.IsValid() );
Our own trucking game prunes its lists exactly like this.
The rule
Gone isn't null. Ask IsValid.
- Still there?
- x.IsValid()
- Null or destroyed
- false either way
- Lists
- RemoveAll + IsValid