• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

S

Slothagami

Guest
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:
Code:
///Alarm 6 event

instance_deactivate_all(true);
instance_activate_object(oFloor);

var terrain_load_dist, entity_load_dist;
terrain_load_dist = 100;
entity_load_dist = 70;

instance_deactivate_region(
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,
false, 
true
);

instance_activate_region(
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,
true
);

instance_activate_object(oCamera);
instance_activate_object(oLight_Controller);

alarm[6] = 10;
thanks in advance!
 

Phil Strahl

Member
From the manual:
Technically they don't really exist anymore, except as a pointer within the deactivation process itself, which means that a deactivated instance cannot be manipulated or changed in any way at all until it is re-activated again. So, these functions should be used with great care as they can cause problems when not used properly [...]
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
Code:
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.
Code:
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.
 
S

Slothagami

Guest
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
Code:
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.
Code:
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.
Thanks Phil Strahl, that really helped!
 
Top