NullReferenceException: Object reference not set to an instance of an object
The above specifically means that the Update() method on Shooter did run, and it called IsAttackerInLane(), so I disagree when you say it is not running. The stack trace shows the (reverse) order of the calls that are made and running.
Your new snippet does not confirm any of the following:
- SetLaneSpawner() was called at any time prior to Shooter.Update()
- Whether any spawners were found by the FindObjectsOfType call.
- That any of them were ‘IsCloseEnough’ to be set.
Specifically that last point, you’re trying to say “if the absolute Y distance between these two objects is less than or equal to the smallest float value possible, only then set myLaneSpawner = spawner”.
Chances are that is never becoming true, and therefore myLaneSpawner is never being set. You likely needed to add some additional tolerance value in there (although that also isn’t a guarantee any would be true), or to have a temporary object that stores “the closest” spawner found so far, and to keep replacing it any time in your loop that you find another one that is even closer than that.
Please try putting some additional Debug.Log() statements throughout your code in that area and see if your logic is working as you thought it would, and also whether it is happening before Shooter.Update() is being called (perhaps it’s not).