GM:S 1.4 Alternatives to instance_activate

Discussion in 'Programming' started by skeptile, Oct 1, 2017.

  1. skeptile

    skeptile Member

    Joined:
    Aug 10, 2017
    Posts:
    24
    So in my game Sword and Staff, there's an overworld which even on the smallest size has a few thousand objects on it (trees, rocks, animals, etc). In order to navigate the world, I'm using instance_deactivate_all() and instance_activate_region(). However, these functions are so slow that they can't be used each step when this many instances are in the room. Instead, I've resorted to a Legend of Zelda-esque screen transition where the view is stationary until you touch the edge, and then the game activates the instances in the next area and slides to the next screen.

    My question is, is there any alternative to this? I'd really like to allow a view that follows the player smoothly, but I can't figure out a way to do this without using the "activate" functions. I'd be grateful for any input you have!
     
  2. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,593
    Its because you're using instance deactivate all.

    Have all objects you want deactivate have an outside view event with this inside:
    instance_deactivate_object(id);

    This means they will deactivate themselves when not visible on screen. This is fast.
    Now have your character activate a region corresponding to the view or a tad larger and every couple of steps or no, not every step. Depending the speed which you character (and therefore cam view) moves, you probably don't have to activate a region every step.
     
    IndianaBones likes this.
  3. skeptile

    skeptile Member

    Joined:
    Aug 10, 2017
    Posts:
    24
    I tried this, and on a typical world (about 7500 instances) each call of instance_activate_region() takes about a quarter-second, so the game stutters terribly.
     
  4. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,593
    How large is the region? Your region should only be the size of the view/cam. How on Earth can you have 7500 objects in view at once???
     
  5. skeptile

    skeptile Member

    Joined:
    Aug 10, 2017
    Posts:
    24
    They're not in the view. There are 7500 instances total in the room. The region being activated is the size of the view (1280x720), and the number of active instances at any given time is around 30. Still, activating that region takes longer the higher the total number of instances are in the room.

    EDIT: Well, I'm stupid. Your suggestion actually works perfectly! I apparently had another object calling a deactivation script simultaneously, which caused the lag. Now I have a constant 60 fps, so thanks!
     
    Last edited: Oct 1, 2017
    RangerX 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