Why last waypoint offscreen = enemy object destruction on camera exit?

If the last waypoint is within the camera screen, the enemy is destroyed upon reaching it.
If a waypoint is off-screen but is not the last, the enemy is destroyed upon reaching the last waypoint.
If the last waypoint is off-screen, the enemy is destroyed upon (pivot, not even the whole sprite) exiting the screen rather than upon reaching the off-screen waypoint.
Is this some sort of Unity implicit “optimization”?


Did you use the OnBecameInvisible method in your code or do you have an if-statement? Or a collider calling the Destroy method?

If not, the enemy should not get destroyed. At least not by Unity.

no, I’ve followed 100% the code in the course, so it’s only our code that should destroy it upon reaching the last waypoint. it happens in the instructor’s video course too, I think.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? And have you checked whether the last waypoint is included in your array in your Inspector?

yes, I’ve compared the code. What I’m saying is that not only happens in my project, but in the video course lesson too.

Can i just clarify something here as i havent been into the code in a very long time to be fair but if the 3rd waypoint is out of the camera range and we have say 4 waypoints its destroying at waypoint 3?

Is this the behaviour you are getting that you are are highlighting?

Sorry if this sounds odd but getting the clarification i can then see how this might be happening and download the course at this point.

If you have OBS can you record a video showing this so i can replicate it with the course files.

This topic was automatically closed after 7 days. New replies are no longer allowed.

Privacy & Terms