1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Discussion Any plans to make instance activation_deactivation instant?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by vdweller, Sep 18, 2018.

  1. vdweller

    vdweller Member

    Joined:
    Jun 24, 2016
    Posts:
    136
    As has already been discussed in this thread,

    https://forum.yoyogames.com/index.p...ce-activation-deactivation-shenanigans.47238/

    Instance activation/deactivation does not happen instantaneously. Specifically,
    The reverse, Deactivation then immediately Activation seems to work. I haven't thoroughly tested if deactivation actually happens instantaneously.

    Is there any chance you could alter this behavior and make these functions have immediate effect?

    To illustrate an example, with the current behavior, we get this:
    1) Some instances are activated and some are deactivated due to prior processing.
    2) Suppose that I want to temporarily activate all instances of a kind, for example to count all enemies in a room regardless of their active/inactive status.
    3) This doesn't work as activation does not take place immediately.

    This is just an example. I am not looking for workarounds for this specific case.

    @rwkay @Nocturne Any insight on this? Could this happen in a future update?
     
  2. csanyk

    csanyk Member

    Joined:
    Jun 20, 2016
    Posts:
    821
    Another thought on this: Would it be of interest to anyone to add Activated and Deactivated as Events? Similar in concept to Create and Destroy Events, they would fire their code when an instance is Activated, or just prior to it being Deactivated.

    I don't use activation/deactivation all that much, but I can see it being potentially useful.
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,709
    It would be of interest to anyone who'd use it, but also not strictly dependent on action from YoYo.

    Set aside 2 user events for activation/deactivation, then use scripts to bundle calls to those events with activation/deactivation functions.

    Example:
    Code:
    ///@function deactivate_object(obj)
    with (argument0) {
      event_user(7);
    }
    instance_deactivate_object(argument0);
    
    Code:
    ///@function activate_object(obj)
    instance_activate_object(argument0);
    with (argument0) {
      event_user(8);
    }
    
    Edit: Fixed wrong order on activate.
     
    Last edited: Sep 20, 2018
    IndianaBones and csanyk like this.
  4. The-any-Key

    The-any-Key Member

    Joined:
    Feb 2, 2017
    Posts:
    1,522
    If the instance was active in the beginning of the step/tick you can temporary deactivate it and re-activate it in the same step.
    Ex you can do this:
    Code:
    // Deactivate outside view
    with obj_mine
    {
       // Say this will deactivate 5 of 10 instances in room
       if x>outside_view
       {
          Add_to_list[c]=id;
          c+=1;
          instance_deactivate_object(id);
       }
    }
    // Run check for all inside view
    with obj_mine
    {
       will only loop the 5 that is active
    }
    // Re activate again
    loop Add_to_list and run instance_activate_object(Add_to_list[i])...
    // Loop all 10 again
    with obj_mine
    {
       will only loop the 10 instances
    }
    
    However. If the instance is de-active when the step/tick start. You need to activate it, wait for the next step, and then it will work with the "with obj { }".
    Ex:
    Code:
    // Run check for all inside view (there are 10 in total and 5 is deactivated from the beginning of the step/tick)
    with obj_mine
    {
       will only loop the 5 that is active
    }
    // Re activate again
    loop Add_to_list and run instance_activate_object(Add_to_list[i])...
    // Run check for all inside view (there are 10 in total and 5 is deactivated from the beginning of the step/tick)
    with obj_mine
    {
       will only loop the 5 that is active, the 5 will be active in the next step/tick
    }
    
    My guess is that when an instance is de-active when the step start, GM don't add it to it's internal event handler list (a list where all instances that will be processed).
    And this is good. All de-activated instances will be skipped and your game run faster.

    But if you have them in the event handler, even if they are deactivated. This would allow you to instantly activate them and use them in a "with obj { }".
    However, this would mean they need to be looped in the event handler and will be partly processed. So you will lose the speed you gain when deactivate an instance. And we don't want that.

    It may be possible if the handlers is working differently. But it might be a big job to change the architecture of GMs internal instance handling, just to get this working.
     
  5. vdweller

    vdweller Member

    Joined:
    Jun 24, 2016
    Posts:
    136
    @The-any-Key I am not sure why you wrote this reply. I mean, constitutionally speaking, I guess you have the right to do so, but it has nothing to do with the initial post, in which not only I do highlight how the thing actually works right now, but I also explicitly state that I am not looking for workarounds (I have already implemented them since I empirically know how the thing works).

    The post was aimed primarily at people involved with development of GM:S2 and about discussing the potential and/or limitations of making instance activation/deactivation have immediate effect. Your explanation about why it is the way it is could be p. much close to the truth though.
     
  6. csanyk

    csanyk Member

    Joined:
    Jun 20, 2016
    Posts:
    821
    You might not have needed The-Any-Key's workaround, but others reading this thread who don't have a workaround might find it valuable :)
     
  7. The-any-Key

    The-any-Key Member

    Joined:
    Feb 2, 2017
    Posts:
    1,522
    Sorry, I just wanted to put you into the know if deactivation actually happens instantaneously.
     

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