Quick answer: Add a singleton check in the object’s Create event: if more than one exists, destroy this. Or never place persistent objects in rooms — create from a Game Start controller.
Music manager runs fine in room 1. Player exits to room 2, returns to room 1. Two music tracks play simultaneously because both the original persistent instance and the new room-placed instance exist.
The Symptom
Persistent object accumulates duplicates each time you re-enter its placement room. Over time, dozens of copies running.
The Fix
Singleton check in Create.
/// In obj_music_manager Create event
if (instance_number(object_index) > 1) {
instance_destroy();
exit;
}
// First instance: do setup
audio_play_sound(snd_main_theme, 10, true);
If a duplicate already exists, the new one destroys itself before doing any setup. Original keeps running.
Or: don’t place persistent objects in rooms.
/// In obj_controller Create (placed in start-up room only)
if (!instance_exists(obj_music_manager)) {
instance_create_layer(0, 0, "Instances", obj_music_manager);
}
Create once from the start-up controller. Persistence keeps it across rooms; no room placements duplicate.
Verifying
Travel back and forth between rooms. instance_number(obj_music_manager) should stay at 1. show_debug_message it from a Step event during dev to confirm.
“Singleton check or controller-spawn. Persistent stays one.”
Related Issues
For instance_deactivate, see deactivate region. For surface lost, see surface lost.
Check on Create. Or never room-place. One instance.