[Solved]stop objects on edge of loaded area falling out of it

Discussion in 'Programming' started by Slothagami, Jul 12, 2019.

  1. Slothagami

    Slothagami Member

    May 30, 2019
    I have been using instance_(de)activate_region and things similar, but i have found that if one block is dependent on another (checking below before falling, etc...) will just fall out of the world or something because what its checking for does not exist

    I have water in my game that falls and pools in low points, if the bottom of the pool is unloaded, the water falls and gets unloaded too, getting stuck inside other blocks

    I also have trees that if there is no block under them they break that are breaking just from unloading them
    this is the code I have used:
    ///Alarm 6 event
    var terrain_load_dist, entity_load_dist;
    terrain_load_dist = 100;
    entity_load_dist = 70;
    camera_get_view_x(view_camera[0]) - terrain_load_dist, 
    camera_get_view_y(view_camera[0]) - terrain_load_dist,
    camera_get_view_width(view_camera[0]) + terrain_load_dist * 2,
    camera_get_view_height(view_camera[0]) + terrain_load_dist * 2,
    camera_get_view_x(view_camera[0]) - entity_load_dist, 
    camera_get_view_y(view_camera[0]) - entity_load_dist,
    camera_get_view_width(view_camera[0]) + entity_load_dist * 2,
    camera_get_view_height(view_camera[0]) + entity_load_dist * 2,
    alarm[6] = 10;
    thanks in advance!
  2. Phil Strahl

    Phil Strahl Member

    Jul 3, 2016
    From the manual:
    Since your game relies on the instances existing in some way I would suggest to not rely on instance_(de)activate and instead roll your own solution, e.g. by introducing a flag. For example you could have an object "obj_asset" that all environment objects (trees, pools of water, etc.) are children of. In its create event introduce a flag, something like
    is_active = true;
    In each child of "obj_asset" you could check if an instance is active or not and don't run expensive calculations, e.g.
    if (!is_active)
      // do only the essentials here
      exit; // <-- this ends the code execution in the event right there, so nothing that follows will be run
    // anything that's supposed to run when the asset is active goes here
    This should sit at the top of the step event.

    You could also do this in other events, such as the Draw event, to keep your game performant, but that's a matter of profiling. What matters most is that all instances do exists and each instance's step event gets run.

    To activate or deactivate you could write a script that acts similar to instance_activate_region(), just call it differently, e.g. asset_activate_region();

    Hope this points you in the right direction.
    Slothagami and RefresherTowel like this.
  3. Slothagami

    Slothagami Member

    May 30, 2019
    Thanks Phil Strahl, that really helped!
    Phil Strahl likes this.

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