Quick answer: Pair instance_deactivate_region with instance_activate_region every frame. Activate around the camera (with a margin), then deactivate the world’s leftover. Without the activate step, instances stay frozen forever after the camera passes.

Big open level. You use instance_deactivate_region to keep frame rate up. Player walks past a screen of enemies, comes back, the enemies are gone — they’re still there in memory but invisible and unreachable. The deactivate has no implicit mirror.

The Symptom

After scrolling the camera around the level, instances that should be visible are missing. instance_number(obj_enemy) returns 0. instance_count still shows the deactivated ones. Activating manually with instance_activate_object(obj_enemy) brings them back — but breaks the optimization.

What Causes This

instance_deactivate_region deactivates all instances inside or outside a region. It does not track the camera; it does not auto-reactivate. If you only call deactivate (with the “outside region” flag), instances that move outside the screen later are never deactivated, but more importantly, instances that were deactivated when the camera was elsewhere never come back when the camera returns.

The Fix

Use a margin region tied to the camera. Activate it, then deactivate everything outside.

/// In obj_world Step Event

var margin = 200;
var _x1 = camera_get_view_x(view_camera[0]) - margin;
var _y1 = camera_get_view_y(view_camera[0]) - margin;
var _x2 = _x1 + camera_get_view_width(view_camera[0])  + margin*2;
var _y2 = _y1 + camera_get_view_height(view_camera[0]) + margin*2;

// Order matters: activate first, then deactivate the leftover.
instance_activate_region(_x1, _y1, _x2-_x1, _y2-_y1, true);
instance_deactivate_region(_x1, _y1, _x2-_x1, _y2-_y1, false, true);

The activate call brings back any instance inside the camera region (with margin). The deactivate call deactivates anything outside. The margin keeps off-screen instances active long enough to slide into view smoothly.

Why Activate Before Deactivate

If you deactivate first, the engine considers any deactivated instance untouchable until you activate it. Calling deactivate with “not in region” on already-deactivated instances has no useful effect. Calling activate first re-evaluates the world, then deactivate trims off-screen.

What to Exclude

Don’t deactivate persistent objects (the player, controllers, music handlers). Use instance_deactivate_object(obj_enemy) instead of region if you want to be selective by type, or run the region deactivate but explicitly reactivate persistent objects:

instance_activate_object(obj_player);
instance_activate_object(obj_world);
instance_activate_object(obj_audio_director);

Cadence

Running activate+deactivate every frame is fine for small to medium rooms. For very large rooms (10k+ instances), throttle to every 5 frames:

if (frame_counter mod 5 == 0) {
    // activate / deactivate logic
}

Verifying

Set show_debug_overlay(true). The instance count and active count diverge as you scroll — total stays constant, active fluctuates with what’s on screen plus margin. If active drops to nearly zero and the screen looks empty, something deactivated the player or the world manager.

“Activate the camera region. Deactivate the rest. Re-activate persistent objects. Frame rate holds; nothing disappears.”

Related Issues

For instance counts confusing, see instance counts. For room performance, see large room frame drops.

Activate the visible. Deactivate the rest. Persistent objects opt out.