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

# API Documentation

Plugins in Quark Engine are dynamic libraries (`.dll` or `.so`) that extend the engine, add editor tools, and can change scene behavior at runtime. The API is built around a single exported entry point and a host-provided context for UI, entity access, and scene control.

## Quick Start

Every plugin must export `get_plugin()`. This is the only symbol the engine looks for when loading the library.

```cpp
#include "plugin.h"

static void on_update(PluginContext* ctx) {
    (void)ctx;
}

static Plugin plugin = {
    "Example Plugin",
    "1.0.0",
    nullptr,
    nullptr,
    on_update,
    nullptr
};

PLUGIN_EXPORT Plugin* get_plugin() {
    return &plugin;
}
```

> **Important:** Do not store `PluginContext*` between calls. It is only valid during the current callback and may be recreated every frame.

## What This File Covers

* What a plugin is.
* How the host loads plugins.
* What `Plugin` and `PluginContext` contain.
* The minimal plugin example.
* Links to lifecycle and features docs.

## Plugin Structure

```cpp
struct Plugin {
    const char* name;
    const char* version;
    void (*on_load)(PluginContext* ctx);
    void (*on_unload)();
    void (*on_update)(PluginContext* ctx);
    void (*on_draw_ui)(PluginContext* ctx);
};
```

* `name` is the display name shown in the plugin manager.
* `version` is a string like `"1.0.0"`.
* `on_load` is called once after the plugin is loaded.
* `on_unload` is called before the library is unloaded.
* `on_update` is called every simulation frame.
* `on_draw_ui` is called every UI pass.

## PluginContext

```cpp
struct PluginContext {
    float delta_time;
    int entity_count;
    int* selected;
    ...
};
```

`PluginContext` contains current-frame data and host functions for UI, entity access, and scene management. Treat it as temporary and never keep it after the callback returns.

## Related Docs

* [Plugin Lifecycle](https://github.com/Quark-Engine/quark-engine.github.io/blob/main/docs/api/api/lifecycle.md)
* [UI System](https://github.com/Quark-Engine/quark-engine.github.io/blob/main/docs/api/api/ui.md)
* [Scene Management](https://github.com/Quark-Engine/quark-engine.github.io/blob/main/docs/api/api/scene.md)
* [Entities](https://github.com/Quark-Engine/quark-engine.github.io/blob/main/docs/api/api/entities.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quark-engine.gitbook.io/quark-engine-docs/plugins.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
