Destroy instance out of sight (Performace Question)

streng

Member
Hi,

I want to ask, how to implement mechanism that destroy object when leave my current sight (I’m don’t using views)


So, my current implementation (It’s a bullet object for clarification, if bullet leave player sight, I want to destroy it):


Step event of the bullet object:

Code:
if (x <  - 100) {

instance_destroy();

}

The question is, when player plays the game a many bullet objects can be created in game, for example 200 objects at same time. Each of this objects must run the if condition in own step event, and i just think this can be a performance issue.

Currently work fine even for 200 bullets, but I don’t want to waste with resource, so question is, is there any better way of implementation? For example, in control object step event for all bullet instances with x < -100 and then destroy it all? Or something like this


Thanks for answers
 

NightFrost

Member
Early in game's development is not the time to dwell on micro-optimizations. Anyhow, you're going to check each bullet's position individually if you're going to destroy them based on coordinates. Implementations may differ but that's what you'll end up doing, so the time used will be on a rough scale the same (unless you go out of your way to be inefficient about it).
 
Top