Defender instances keep trying to access destroyed attacker instances

Here’s the error I’ve been trying to fix for a bit now:

Blockquote
MissingReferenceException: The object of type ‘AttackerSpawner’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
Shooter.IsAttackerAheadInLane () (at Assets/Scripts/Shooter.cs:45)
Shooter.Update () (at Assets/Scripts/Shooter.cs:72)

The errors occur per instance of Defender after Attacker instances are destroyed in their lane. Most Defender instances aren’t changing their animation state from attacking to idle, but some are. I thought the animation state part of the error was an animation bug similar to what Ben had, so I went and redone the transitions with a new boolean variable name, but to no avail.

Lines 45 and 72 the console mentions are the same as in the example, just different variable names.

So far I’ve tried implementing null checks in the Shooter script, used ‘this’ in the Health script for destroying gameObjects, and commented out my code and pasted Ben’s code, still no luck :frowning:

Hello Sandro,

Could you copy/paste your code into your reply please, let’s see if we can work it out together :slight_smile:


See also;

Change on Start() of Shooter.cs the animator to

animator = this.GetComponent<Animator>();

or

animator = GetComponent<Animator>();

the above worked for me, I had the same problem of random instances trying to acess animator of a destroyed instance

Privacy & Terms