Question: What is an instance in GameMaker?

Answer

In GameMaker, an "instance" refers to an occurrence of an object placed in a room or created during the game's execution. Objects in GameMaker act as blueprints for game entities, defining their properties and behaviors, while instances are what actually exist in the game world at runtime.

When you place an object in a GameMaker room using the Room Editor, you are creating an instance of that object. Instances inherit all the properties and events from their parent object, but they can also have unique properties set individually.

Here is an example of how you might create an instance of an object called obj_enemy at a random position within the room:

// Create an instance of obj_enemy at a random x and y coordinate within the room var instance_id = instance_create_layer(irandom(room_width), irandom(room_height), "Instances", obj_enemy); // You can now refer to the created instance using the instance_id variable instance_id.hitpoints = 10; // For example, setting a custom hitpoints property for this instance

Each instance has a unique ID which allows you to interact with it specifically through GML (GameMaker Language). This ID can be used to change its properties, apply movement, execute code, and more.

There are various functions in GameMaker for manipulating instances:

  • instance_create_layer(x, y, layer, obj) - Creates an instance on a specific layer.
  • instance_destroy() - Destroys the instance calling the function.
  • with (object_or_instance_id) { ... } - Executes code block for specified object type or instance.
  • instance_find(obj, n) - Finds the nth instance of the specified object type.

Instances play a crucial role in GameMaker, enabling developers to bring their game's mechanics and world to life.

Was this content helpful?

Start building today

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