Legacy GM Alternatives to instance_activate

S

skeptile

Guest
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!
 

RangerX

Member
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.
 
S

skeptile

Guest
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.
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.
 

RangerX

Member
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???
 
S

skeptile

Guest
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 by a moderator:
Top