> For the complete documentation index, see [llms.txt](https://docs.gamesense.biz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gamesense.biz/api-reference/il2cpp.md).

# IL2CPP

Read accessible game objects and classes.

The `il2cpp` module provides access to available game classes and objects.

IL2CPP calls are supported inside **`on_update`** only. They are unavailable during initial script loading and in `on_paint`.

## il2cpp.available

`il2cpp.available(): boolean`

Checks whether IL2CPP is currently accessible.

```lua
register_callback("on_update", function()
    if not il2cpp.available() then return end

    local avatar = il2cpp.root("local_avatar")
    if avatar and avatar:valid() then
        local class_name = avatar:class():name()
    end
end)
```

## il2cpp.root

`il2cpp.root(name: string): il2cpp_object | nil`

Returns a registered game object by name or `nil` if unavailable.

Available root: `"local_avatar"`.

## il2cpp.find\_class

`il2cpp.find_class(name: string): il2cpp_class | nil`

Finds a game class by name, or returns `nil` if it cannot be found.

## il2cpp\_object methods

| Method                            | Description                        |
| --------------------------------- | ---------------------------------- |
| `:valid(): boolean`               | Checks whether the object is valid |
| `:class(): il2cpp_class`          | Returns the object's class         |
| `:get(field: string): any`        | Reads a field                      |
| `:set(field: string, value: any)` | Writes a field                     |
| `:call(method: string, ...): any` | Invokes an instance method         |

## il2cpp\_class methods

| Method                                 | Description             |
| -------------------------------------- | ----------------------- |
| `:name(): string`                      | Class name              |
| `:namespace(): string`                 | Namespace               |
| `:fields(): table`                     | Available fields        |
| `:methods(): table`                    | Available methods       |
| `:has_field(name: string): boolean`    | Checks for a field      |
| `:call_static(name: string, ...): any` | Invokes a static method |

## Example: display the object class

```lua
local status = menu.label("Avatar: unknown")

register_callback("on_update", function()
    if not il2cpp.available() then return end

    local avatar = il2cpp.root("local_avatar")
    if avatar and avatar:valid() then
        status:set("Avatar: " .. avatar:class():name())
    end
end)
```

{% hint style="warning" %}
**IL2CPP objects are only valid within the callback in which they were obtained.** Do not retain `il2cpp_object` handles across callbacks.
{% endhint %}

Writing fields (`:set`) and invoking methods (`:call`, `:call_static`) require **Allow unsafe scripts**. Some classes and fields may not be exposed.


---

# 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://docs.gamesense.biz/api-reference/il2cpp.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.
