Home | Customize | Blog | Extras | Log In | Info
Manual | D&D icons | GML Parser | Archive | Iso City
Username: Password:  
About | Features | Directory | Banners | Contact

Designing Games with GameMaker
Designing Games with GameMaker

Deactivating instances

Please be aware that deactivating and activating instances can sometimes lead to unexpected problems. So you are strongly advised not to use this feature except for very simple situation like the ones described below. The feature is mainly left in for backward compatibility.

When you create large room, for example in platform games, with a small view, many instances lie outside the view. Such instances though are still active and will execute their events. Also when performing collision checks these instances are taken into account. This can cost a lot of time, which is often not necessary. (For example, often it is not important whether instances outside the view move.) To solve this problem GameMaker contains some functions to deactivate and activate instances. Before using them you must though clearly understand how they work.

When you deactivate instances they are in some sense removed from the game. They are not visible anymore nor are any events executed for them. So for all actions and functions they don't exist anymore. This saves a lot of time but you have to be careful. For example, when you delete all instances of a particular type, deactivated instances are not deleted (because they don't exist). So don't think that a key a player picks up can unlock a deactivated door. Also persistent deactivated instances are not moved over to the next room (even though they are persistent). Also make sure that after you deactivate an instance that you no longer execute code for it. This can in particular happen when an instance deactivates itself. In general you better never have an instance deactivate itself.

The most crucial mistake you can make is to deactivate the instance that is responsible for the activation. To avoid this some of the routines below allow you to insist that the calling instance should not be deactivated itself.

Here are the available routines:

instance_deactivate_all(notme) Deactivates all instances in the room. If notme is true the calling instance is not deactivated (which is normally what you want).
instance_deactivate_object(obj) Deactivates all instances in the room of the given object. You can also use all to indicate that all instances must be deactivated or the id of an instance to deactivate an individual instance.
instance_deactivate_region(left,top,width,height,inside,notme) Deactivates all instances in the indicated region (that is, those whose bounding box lies partially inside the region). If inside is false the instances completely outside the region are deactivated. If notme is true the calling instance is not deactivated (which is normally what you want).
instance_activate_all() Activates all instances in the room.
instance_activate_object(obj) Activates all instances in the room of the given object. You can also use all to indicate that all instances must be activated or the id of an instance to activate an individual instance.
instance_activate_region(left,top,width,height,inside) Activates all instances in the indicated region. If inside is false the instances completely outside the region are activated.

For example, to deactivate all instances outside the view and activate the ones inside the view, you could place the following code in the step event of the moving character:

{
  instance_activate_all();
  instance_deactivate_region(view_xview[0],view_yview[0],
                        view_wview[0],view_hview[0],false,true);
}

In practice you might want to use a region slightly larger than the view.

Search Search


Alternative versions Alternative versions

You can also read this manual on one single long page (± 1.5 mb)

Also available in: Dutch French German

ZIP Download helpfile

Advertisement Advertisement

GameMaker Manual