> For the complete documentation index, see [llms.txt](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/content/game-objects.md).

# Game objects

A mod can add GameMaker objects of its own, with their events written in C#. Each is a child of one of the game's objects, so the game treats its instances as that object's: a child of `o_enemy` is a unit.

```csharp
using StoneForge;

public class Marker : GameObject
{
    public Marker() : base("marker", "o_invisible_mark")
    {
        Sprite = "s_dummy";
    }

    protected override void OnCreate(Instance self) => self["life"] = 60;

    protected override void OnStep(Instance self)
    {
        self["life"] = self["life"] - 1;
        if (self["life"] <= 0)
            self.Destroy();
    }
}
```

```csharp
var marker = new Marker();
context.Objects.Add(marker);

// later, in game:
Instance made = marker.Create(x, y, depth: 0);
```

{% hint style="warning" %}
The key and parent must be **string literals** in the `base(...)` call. StoneForge's patcher reads them from your source and adds the object (`o_yourmod__marker`) to the game data at the game's next start. A new object, or a changed parent, needs a restart; its C# events reload with the mod.
{% endhint %}

{% hint style="info" %}
On the game's **native branch** an object can't have code of its own. It's added with none, under its parent (or under the game's unused `o_GMLiveDebug` if it has none), and each C# event runs on the nearest ancestor that has that event, for its own instances only. An event that no ancestor has never runs there, and the log says which. Give the object a parent with the events you override. See [Native and VM branches](/stoneforgeteam-docs/getting-started/game-branches.md).
{% endhint %}

## GameObject

|                               |                                                                                     |
| ----------------------------- | ----------------------------------------------------------------------------------- |
| `base(key, parent)`           | Its key, and the game object it's a child of (`""` for none).                       |
| `ObjectName`, `Index`         | `"o_yourmod__marker"`; its object index (`-1` until the game has it).               |
| `Sprite`                      | One of the game's sprites by name (default: its parent's).                          |
| `Persistent`, `Visible`       | Whether its instances stay from room to room (default no); are drawn (default yes). |
| `ReplacesDraw`                | Override to `true` for `OnDraw` to draw in place of the parent's Draw.              |
| `Create(x, y, depth)`         | A new instance (its Create event has run when it's returned).                       |
| `Instances`, `Owns(instance)` | Its instances now; whether an instance is one of its.                               |

## Events

Override the ones you need. Each gets the instance it runs for:

`OnCreate`, `OnDestroy`, `OnCleanUp`, `OnBeginStep`, `OnStep`, `OnEndStep`, `OnDrawBegin`, `OnDraw`, `OnDrawEnd`, `OnDrawGui`, `OnAlarm(self, n)`, `OnUserEvent(self, n)`, `OnLeftPressed`, `OnRightPressed`, `OnMouseEnter`, `OnMouseLeave`.

Every event runs the parent's first (as `event_inherited()` would), then yours - except Destroy and Clean Up, which run yours first, and Draw, which yours replaces when `ReplacesDraw` is set. With no parent's Draw, the instance's sprite is drawn, as GameMaker does.

Its instances are destroyed when the mod is switched off. To find them: `Instances.All(marker)`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/content/game-objects.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
