• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

is room_goto() destroying previous room instances?

C

Christop777

Guest
Hello, I'm new to GameMaker and I try to make a game for iPhone.
I have a "room_1" room with some instances created in it. Then, I use room_goto(room_2) to go to "room_2".
My question is : Do I have to use, for each instance of "room_1", an instance_destroy() instruction to destroy all instance before leaving this room?
Or can I consider that going to "room_2" will automatically destroy all the instances created into "room_1" ?
Thank you!
Christophe
Paris, France
 
A

Aura

Guest
All instances are automatically destroyed before moving to another room (and recreated when you return) unless you are using some sort of persistence, so you don't need to do that.
 
L

LegendarySavior

Guest
All the objects will be destroyed if you switch rooms. You might have to save everything and load it on the room start if you want to continue.
 
A more concise answer, the following instances will be destroyed at room change:
  • ALL deactivated instances, even if they are marked as 'persistent', and even if the room itself is marked 'persistent'
  • In a non-persistent room, all non-persistent instances will be destroyed
The following instances will NOT be destroyed at room change:
  • All active instances which are marked as 'persistent', regardless if the room itself is marked 'persistent'
  • In a persistent room, all non-persistent, active instances will be saved to memory and these cannot be accessed until that room is reloaded
And of course, all instances are destroyed at game end. A thing to note, however, is that the Destroy Event is not triggered by a room change, even if it gets removed from memory. You have to explicitly destroy the instance in order to trigger the event. You do not HAVE to implicitly destroy every instance, unless you need to free up dynamically created resources that are referenced exclusively in that instance.

Hope this helps.
 

FrostyCat

Redemption Seeker
Note that the kind of destruction that happens to non-persistent instances when changing rooms is special: It doesn't trigger Destroy events the way instance_destroy() does. Be careful about this if you rely on the Destroy event to clean up dynamically allocated resources such as data structures.
 
C

Cartoonicus

Guest
Are you sure this is how it works? I'm clicking on a button to start an audio file, then leaving the room and the audio file is still playing. Neither the object or the room are marked persistent
 
H

Homunculus

Guest
Are you sure this is how it works? I'm clicking on a button to start an audio file, then leaving the room and the audio file is still playing. Neither the object or the room are marked persistent
You should probably create your own thread instead of bumping this one.
Anyways, some things are tied to a global scope. A sound that is being played is not dependent from the instance that started playing it (although that instance may have a reference to that specific sound). The same is true for other things like sprites being added on runtime or data structures, you may create those from an active instance and save the result to an instance variable, but they are not stored "inside" that instance, they are global in scope.
 

FrostyCat

Redemption Seeker
Are you sure this is how it works? I'm clicking on a button to start an audio file, then leaving the room and the audio file is still playing. Neither the object or the room are marked persistent
This topic is about instances, not sounds. Changing a room or removing the instance that started it won't stop a sound. Sounds live in a parallel, globally-scoped system away from the regular rooms-and-instances flow.

Also, stop bumping up old topics that don't belong to you. You've been told before by a moderator to keep your paws off archival material.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Hello, I'm new to GameMaker and I try to make a game for iPhone.
I have a "room_1" room with some instances created in it. Then, I use room_goto(room_2) to go to "room_2".
My question is : Do I have to use, for each instance of "room_1", an instance_destroy() instruction to destroy all instance before leaving this room?
Or can I consider that going to "room_2" will automatically destroy all the instances created into "room_1" ?
Thank you!
Christophe
Paris, France
Instances are removed when you change rooms (except ones with the persistent variable set true), but their Destroy event isn't triggered. (Their Room End event is triggered instead) If you need an object to have its destroy event triggered when changing rooms (e.g. because you clean up dynamic resources there), just put an instance_destroy() call in the relevant objects' room end event.

Also, if you want to destroy every object in the room for some reason, you could simply do this:
Code:
with(all){
  instance_destroy()
}
Note that the object that runs this code will still exist in some way until it's done with its code, so if you want to create some new stuff and not have a completely empty room, you can do that after the with-all-destroy loop.
 
Top