Destroy instance out of sight (Performace Question)

Discussion in 'Programming' started by streng, Aug 16, 2019 at 9:23 AM.

  1. streng

    streng Member

    Joined:
    Jun 10, 2019
    Posts:
    12
    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
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,867
    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).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice