• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows GMS:2 Butthurt Vending S01E03: Instance Activation/Deactivation shenanigans

vdweller

Member
EDIT: Activation then Deactivation works if Activation happens, say, in the Step Event and Deactivation in the End Steap event. God help you if other parts of the code mess with this. This changes nothing. My butthurt is valid.

In the third episode of our Game Maker Studio 2 Bugathon, we have to deal with instance activation/deactivation.

In my game, in the master control object, every few steps some instances get activated/deactivated depending on their position in the view.

Now, in some specific places in the game, in another object, I am running some code where I want to temporarily activate some objects (to count them at any given time, for example), then deactivate them again.

I think you understand where this is going.

Instance activation/deactivation does not occur immediately. (This quirk existed in 1.4 too, but at least I found that things mostly worked if I placed that code in Begin Step event.)

We are talking about code like this:

Code:
instance_activate_object(obj_enemy);
var z=0; with obj_enemy z+=1;
print(z);
print("++++++++++++++++++++++++++++");
if id.enemycheck_initial=0 then {
    id.enemycheck_initial=1;
    id.enemiesexist_initial=instance_exists(obj_enemy);
}
deactivateenemies();

instance_activate_object(obj_cave_bigdoor);

if id.enemiesexist_initial=false then { //no enemies here in the first place
    //blah
} else {
    //blah
}
Results (the number is the enemies present in the room (the correct number is 2)):

0 ,
++++++++++++++++++++++++++++ ,
2 ,
++++++++++++++++++++++++++++ ,
0 ,
++++++++++++++++++++++++++++ ,
0 ,
++++++++++++++++++++++++++++ ,
2 ,
++++++++++++++++++++++++++++ ,
0 ,
++++++++++++++++++++++++++++ ,
etc

No matter if I put the code in Begin, Normal or End Step, results are inconsistent. In an even more lulzy turn of events, functions like instance_number() don't work at all (always returns zero), hence the with statement in the beginning of the code. Executing this code every few steps instead of every step doesn't change anything, I tried that too in the ~10 hours I wasted trying to decipher this behavior.

My butthurt venting, after wasting so many hours, culminates into the following questionnaire:
  • Why is this instance activation/deactivation behavior undocumented?
  • Is the only usefulness of those functions to simply do an instance_deactivate_object() / instance_activate_region() for the view every few steps? Why is it impossible to make them work consistently in another section of our code since apparently they don't happen instantaneously?
  • How come that, when doing some positioning calculations eg for an animal, if I call instance_deactivate_object() for a specific instance, do my stuff, and then reactivate said instance, it works OK? Why can't I do the reverse, eg Activate first then Deactivate, if for example I want to count something?
  • Why is this instance activation/deactivation behavior undocumented?
  • Why when activating instances then immediately calling instance_number() or instance_exists() returns zero? Do you even understand what functionality and possibilities are crippled because apparently activation/deactivation runs in some process that may or may not be synced to the actual game?
  • Are you aware that, as they are programmed now, activation/deactivation cause problems like flickering on the y-axis in conjuction with depth=-y? Do you know that activating/deactivating can mess up collision masks in large areas with many objects, and you have to reassign those masks manually after reactivating by writing the following, award-winning, magnum opus of human thought, code?
    Code:
    var t=mask_index; mask_index=<whatever>; mask_index=t; //mind=blown
  • Aside from a few flagship games that have gotten away with it, do you know how hard it is to work around these stuff when making a large game? Do you even know how many hours I have wasted, constantly questioning my code while it was the engine the entire time? Are you really satisfied that you abandoned 1.x, as per your usual tactics, to present an even buggier version (for which you amply charge money nonetheless), which you will no doubt ditch again in a few years for version 3 and so on?
  • Why is this instance activation/deactivation behavior undocumented?
  • I can and I will work around this problem, like I did with all the other problems the engine threw at me. But why do I have to do so in the first place?
PS I have filed bugs for the problems I've encountered so far, except for the collision mask thing.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Deactivating and activating instances is not instant and won't be fully activated or deactivated until the NEXT full step after the function was called. I actualy thought this WAS documented, but you are right and it's not, so it WILL be for the next update.
 

vdweller

Member
Thank you. I am glad to see that my salty ramblings actually did amount to something useful.

Please note that it seems like Deactivate -> Activate is working in the same step, while Activate -> Deactivate doesn't.
 
S

SleepyMolecule

Guest
Oh hey I just found this thread while looking for info on activation/deactivation.
Regarding your 'counting objects' when you retrieve a list of objects from a layer (see the layer_instance_get_instance help article for example), It does not matter if they are active or not.
You can then check if the instance in question is active by doing an instance_exists(id), only active objects will return true!
Hopefully this helps you or anyone else who finds themselves in the same spot.
 

vdweller

Member
Oh hey I just found this thread while looking for info on activation/deactivation.
Regarding your 'counting objects' when you retrieve a list of objects from a layer (see the layer_instance_get_instance help article for example), It does not matter if they are active or not.
You can then check if the instance in question is active by doing an instance_exists(id), only active objects will return true!
Hopefully this helps you or anyone else who finds themselves in the same spot.
That's quite an interesting find! However in a Zelda-like game with lots of managed layers holding constantly changing depths, I don't know if that could be of use. Anyways, workarounds do exist, I was just frustrated because I ended up burning 2-3 days with this.
 
Top