Question: What is the id in GameMaker?


In GameMaker, each instance of an object at runtime is given a unique identifier known as the id. This id is crucial for referencing and interacting with specific instances within your game's code.

Here is how you might use id in GameMaker:

Checking an Instance's ID

Each instance has its own id which can be referenced by using the id keyword. For example:

if ( == some_value) { // Perform actions on this specific instance }

Storing IDs for Later Use

You can store an instance's id in a variable for future reference:

var player_instance_id; player_instance_id =;

Later, you can use instance_exists(id) to check if the stored instance is still alive before performing actions:

if (instance_exists(player_instance_id)) { // The instance is still around, and we can do something with it. }

Using IDs with Data Structures

When you're dealing with lists, grids, or other data structures, you might store multiple IDs to manage several instances:


And when iterating over these structures, you can use the IDs to interact with the actual instances:

for (var i = 0; i < ds_list_size(instance_list); ++i) { var inst_id = ds_list_find_value(instance_list, i); if (instance_exists(inst_id)) { // Access the instance directly using the stored ID } }

Unique Identification

The primary purpose of id is to have a way to uniquely identify instances even if they are of the same object type. No two instances will have the same id value during a game's execution, which allows for very precise control.

It's worth noting that this id attribute is automatically managed by GameMaker and should not be manually changed, as it is integral to how GameMaker identifies and operates on instances.

These examples show how you might utilize id in various contexts, but the applications are numerous and varied depending on your game's specific needs and logic.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.