> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monolisk.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> Complete API documentation for all CORP classes and methods

<Note>**Reading time:** \~40 minutes (reference material)</Note>

Complete API documentation for CORP (Component-Oriented Replicated Programming).

## Table of Contents

* [Core Classes](#core-classes)
  * [CORP](#corp)
  * [GameObject](#gameobject)
  * [Component](#component)
  * [Behavior](#behavior)
* [Networking Classes](#networking-classes)
  * [NetworkObject](#networkobject)
  * [NetworkBehavior](#networkbehavior)
  * [NetworkedVariable](#networkedvariable)
  * [NetworkedList](#networkedlist)
  * [NetworkedMap](#networkedmap)
  * [NetworkedSet](#networkedset)
  * [RPC](#rpc)
* [Scene Management](#scene-management)
  * [SceneManager](#scenemanager)
  * [Scene](#scene)
* [Utilities](#utilities)
  * [Signal](#signal)
  * [Collector](#collector)

***

## Core Classes

### CORP

Main entry point for the framework.

#### Methods

##### `CORP.start(configuration: Configurations.GameConfiguration): void`

Starts CORP with a configuration object.

```typescript theme={null}
CORP.start({
    startingScene: MyScene
});
```

**Parameters:**

* `configuration.startingScene` - Scene description or path to scene

##### `CORP.startFromWorkspace(): void`

Starts CORP using existing workspace instances (for rapid prototyping).

```typescript theme={null}
CORP.startFromWorkspace();
```

***

### GameObject

Represents an entity in the game world. Container for Components.

#### Constructor

```typescript theme={null}
new GameObject(name: string)
```

**Parameters:**

* `name` - Name of the GameObject

#### Properties

| Property            | Type                                                     | Description                                         |
| ------------------- | -------------------------------------------------------- | --------------------------------------------------- |
| `componentAdded`    | `Signal<[Component]>`                                    | Fires when a component is added                     |
| `componentRemoving` | `Signal<[Component]>`                                    | Fires when a component is removing                  |
| `componentSpawned`  | `Signal<[Component]>`                                    | Fires when a component spawns (NetworkBehaviors)    |
| `removing`          | `Signal<[]>`                                             | Fires when GameObject is being destroyed            |
| `ancestryChanged`   | `Signal<[GameObject, GameObject \| Scene \| undefined]>` | Fires when parent changes                           |
| `isDestroying`      | `boolean`                                                | Whether the GameObject is currently being destroyed |

#### Methods

##### `addComponent<T>(clazz: Constructable<T>, config?: ComponentConfig<T>): T`

Adds a component to the GameObject.

```typescript theme={null}
const health = player.addComponent(HealthSystem, {
    maxHealth: 100
});
```

**Parameters:**

* `clazz` - Component class to add
* `config` - Optional configuration object

**Returns:** The added component instance

##### `getComponent<T>(clazz: Constructable<T> | string): T | undefined`

Gets a component from the GameObject.

```typescript theme={null}
const health = player.getComponent(HealthSystem);
```

**Parameters:**

* `clazz` - Component class or path string

**Returns:** Component instance or undefined

##### `hasComponent<T>(clazz: Constructable<T>): boolean`

Checks if GameObject has a component.

```typescript theme={null}
if (player.hasComponent(HealthSystem)) {
    // Has health component
}
```

**Parameters:**

* `clazz` - Component class to check

**Returns:** True if component exists

##### `removeComponent<T>(clazz: Constructable<T>): void`

Removes a component from the GameObject.

```typescript theme={null}
player.removeComponent(HealthSystem);
```

**Parameters:**

* `clazz` - Component class to remove

##### `destroy(): void`

Destroys the GameObject and all its components.

```typescript theme={null}
enemy.destroy();
```

##### `setParent(parent: GameObject | Scene | undefined): void`

Sets the parent of this GameObject.

```typescript theme={null}
child.setParent(parent);
```

**Parameters:**

* `parent` - New parent GameObject, Scene, or undefined

##### `getParent(): GameObject | Scene | undefined`

Gets the parent of this GameObject.

```typescript theme={null}
const parent = child.getParent();
```

**Returns:** Parent GameObject, Scene, or undefined

##### `getChildren(): GameObject[]`

Gets all child GameObjects.

```typescript theme={null}
const children = parent.getChildren();
```

**Returns:** Array of child GameObjects

##### `getDescendants(): GameObject[]`

Gets all descendant GameObjects recursively.

```typescript theme={null}
const all = root.getDescendants();
```

**Returns:** Array of all descendant GameObjects

##### `getTransform(): CFrame`

Gets the transform (position and rotation) of the GameObject.

```typescript theme={null}
const transform = player.getTransform();
```

**Returns:** CFrame representing the transform

##### `setTransform(transform: CFrame): void`

Sets the transform of the GameObject.

```typescript theme={null}
player.setTransform(new CFrame(0, 10, 0));
```

**Parameters:**

* `transform` - New CFrame transform

##### `getPosition(): Vector3`

Gets the position of the GameObject.

```typescript theme={null}
const pos = player.getPosition();
```

**Returns:** Vector3 position

##### `getName(): string`

Gets the name of the GameObject.

```typescript theme={null}
const name = player.getName();
```

**Returns:** GameObject name

##### `getInstance(): Actor`

Gets the underlying Roblox Instance.

```typescript theme={null}
const instance = player.getInstance();
```

**Returns:** Actor instance

#### Static Methods

##### `GameObject.fromInstance(instance: Actor, name: string): GameObject`

Creates a GameObject from an existing Roblox Instance.

```typescript theme={null}
const actor = new Instance("Actor");
const gameObject = GameObject.fromInstance(actor, "MyObject");
```

**Parameters:**

* `instance` - Roblox Actor instance
* `name` - Name for the GameObject

**Returns:** New GameObject

##### `GameObject.importGameObject(description: GameObjectDescription, parent: GameObject | Scene, isClient: boolean): GameObject`

Imports a GameObject from a scene description.

***

### Component

Abstract base class for all components.

#### Constructor

```typescript theme={null}
public constructor(gameObject: GameObject, initOnCreated?: boolean)
```

**Parameters:**

* `gameObject` - GameObject this component is attached to
* `initOnCreated` - Whether to initialize immediately (default: true)

#### Properties

| Property         | Type         | Description                                               |
| ---------------- | ------------ | --------------------------------------------------------- |
| `executionOrder` | `number`     | Order in which component is initialized (lower = earlier) |
| `removing`       | `Signal<[]>` | Fires when component is about to be removed               |

#### Methods

##### `abstract onStart(): void`

Called when the component starts. Must be implemented.

```typescript theme={null}
public onStart(): void {
    // Initialization logic
}
```

##### `abstract willRemove(): void`

Called before the component is removed. Must be implemented.

```typescript theme={null}
public willRemove(): void {
    // Cleanup logic
}
```

##### `abstract getSourceScript(): LuaSourceContainer`

Returns the script that defines this component. Must be implemented.

```typescript theme={null}
protected getSourceScript(): ModuleScript {
    return script as ModuleScript;
}
```

##### `willStart(): void`

Called before onStart. Override for pre-initialization.

```typescript theme={null}
public willStart(): void {
    // Pre-initialization logic
}
```

##### `onPropertiesApplied(): void`

Called after properties are applied via serialization. Override to react to configuration.

```typescript theme={null}
public onPropertiesApplied(): void {
    // React to configured properties
}
```

##### `initialize(): void`

Initializes the component. Called internally by CORP.

##### `remove(): void`

Removes and destroys this component.

```typescript theme={null}
component.remove();
```

##### `getGameObject(): GameObject`

Gets the GameObject this component is attached to.

```typescript theme={null}
const gameObject = this.getGameObject();
```

**Returns:** GameObject instance

##### Component Shortcuts

These methods are shortcuts to GameObject methods:

```typescript theme={null}
this.getTransform()           // GameObject.getTransform()
this.setTransform(cframe)     // GameObject.setTransform()
this.getPosition()            // GameObject.getPosition()
this.getName()                // GameObject.getName()
this.getInstance()            // GameObject.getInstance()
this.getComponent(clazz)      // GameObject.getComponent()
this.destroy()                // GameObject.destroy()
```

***

### Behavior

Extends Component with serialization support. Use this as the base for most components.

#### All Component Methods

Behavior inherits all methods from Component.

#### Methods

##### `serializeState(): Partial<Behavior>`

Returns the serialized state of all `@SerializeField` properties.

```typescript theme={null}
const state = this.serializeState();
```

**Returns:** Object containing serialized field values

#### Properties

| Property    | Type        | Description                                      |
| ----------- | ----------- | ------------------------------------------------ |
| `collector` | `Collector` | Garbage collector for automatic resource cleanup |

***

## Networking Classes

### NetworkObject

Makes a GameObject replicate across the network.

#### Constructor

```typescript theme={null}
public constructor(gameObject: GameObject)
```

#### Properties

| Property          | Type                            | Description                     |
| ----------------- | ------------------------------- | ------------------------------- |
| `ownerChanged`    | `Signal<[Player \| undefined]>` | Fires when ownership changes    |
| `isLoadedChanged` | `Signal<[boolean]>`             | Fires when loaded state changes |

#### Methods

##### `spawn(): void`

Spawns the NetworkObject on the network (server only).

```typescript theme={null}
if (RunService.IsServer()) {
    netObj.spawn();
}
```

##### `changeOwnership(owner: Player | undefined): void` (Server Only)

Changes the owner of this NetworkObject.

```typescript theme={null}
netObj.changeOwnership(player); // Give to player
netObj.changeOwnership(undefined); // Give to server
```

**Parameters:**

* `owner` - New owner Player, or undefined for server

##### `getOwner(): Player | undefined`

Gets the current owner.

```typescript theme={null}
const owner = netObj.getOwner();
```

**Returns:** Owner Player or undefined (server owned)

##### `getId(): string`

Gets the unique network ID.

```typescript theme={null}
const id = netObj.getId();
```

**Returns:** Network ID string

***

### NetworkBehavior

Network-replicated component. Requires NetworkObject.

#### Constructor

```typescript theme={null}
public constructor(gameObject: GameObject, initOnCreated?: boolean)
```

#### All Behavior Methods

NetworkBehavior inherits all methods from Behavior.

#### Methods

##### `getNetworkObject(): NetworkObject`

Gets the associated NetworkObject.

```typescript theme={null}
const netObj = this.getNetworkObject();
```

**Returns:** NetworkObject component

##### `getId(): string`

Gets the unique network behavior ID.

```typescript theme={null}
const id = this.getId();
```

**Returns:** Network behavior ID

***

### NetworkedVariable

Replicated variable that synchronizes between server and clients.

#### Constructor

```typescript theme={null}
new NetworkedVariable<T>(initialValue?: T, config?: NetworkVariableConfig)
```

**Parameters:**

* `initialValue` - Initial value
* `config` - Configuration options

**Config Options:**

```typescript theme={null}
interface NetworkVariableConfig {
    replicationBehavior?: NetworkVariableReplicationBehavior; // BATCHED or INSTANTANEOUS
}
```

#### Properties

| Property         | Type             | Description                                   |
| ---------------- | ---------------- | --------------------------------------------- |
| `onValueChanged` | `Signal<[T, T]>` | Fires when value changes (newValue, oldValue) |

#### Methods

##### `getValue(): T`

Gets the current value.

```typescript theme={null}
const value = myVar.getValue();
```

**Returns:** Current value

##### `setValue(value: T): void` (Server Only)

Sets the value (server only).

```typescript theme={null}
if (RunService.IsServer()) {
    myVar.setValue(100);
}
```

**Parameters:**

* `value` - New value

***

### NetworkedList

Replicated list/array.

#### Constructor

```typescript theme={null}
new NetworkedList<T>(config?: NetworkVariableConfig)
```

#### Properties

| Property        | Type                  | Description                              |
| --------------- | --------------------- | ---------------------------------------- |
| `onItemAdded`   | `Signal<[T, number]>` | Fires when item is added (item, index)   |
| `onItemRemoved` | `Signal<[T, number]>` | Fires when item is removed (item, index) |
| `onItemSet`     | `Signal<[T, number]>` | Fires when item is set (item, index)     |

#### Methods

##### `push(item: T): void` (Server Only)

Adds an item to the end.

```typescript theme={null}
list.push("item");
```

##### `remove(index: number): T | undefined` (Server Only)

Removes an item at index.

```typescript theme={null}
const removed = list.remove(0);
```

##### `get(index: number): T | undefined`

Gets an item at index.

```typescript theme={null}
const item = list.get(0);
```

##### `set(index: number, value: T): void` (Server Only)

Sets an item at index.

```typescript theme={null}
list.set(0, "newValue");
```

##### `size(): number`

Gets the size of the list.

```typescript theme={null}
const size = list.size();
```

***

### NetworkedMap

Replicated map/dictionary.

#### Constructor

```typescript theme={null}
new NetworkedMap<K, V>(config?: NetworkVariableConfig)
```

#### Properties

| Property       | Type             | Description               |
| -------------- | ---------------- | ------------------------- |
| `onKeySet`     | `Signal<[K, V]>` | Fires when key is set     |
| `onKeyDeleted` | `Signal<[K]>`    | Fires when key is deleted |

#### Methods

##### `set(key: K, value: V): void` (Server Only)

Sets a key-value pair.

```typescript theme={null}
map.set("key", "value");
```

##### `get(key: K): V | undefined`

Gets a value by key.

```typescript theme={null}
const value = map.get("key");
```

##### `delete(key: K): boolean` (Server Only)

Deletes a key.

```typescript theme={null}
map.delete("key");
```

##### `has(key: K): boolean`

Checks if key exists.

```typescript theme={null}
if (map.has("key")) {
    // Key exists
}
```

***

### NetworkedSet

Replicated set.

#### Constructor

```typescript theme={null}
new NetworkedSet<T>(config?: NetworkVariableConfig)
```

#### Properties

| Property        | Type          | Description                |
| --------------- | ------------- | -------------------------- |
| `onItemAdded`   | `Signal<[T]>` | Fires when item is added   |
| `onItemDeleted` | `Signal<[T]>` | Fires when item is deleted |

#### Methods

##### `add(item: T): void` (Server Only)

Adds an item to the set.

```typescript theme={null}
set.add("item");
```

##### `delete(item: T): boolean` (Server Only)

Deletes an item from the set.

```typescript theme={null}
set.delete("item");
```

##### `has(item: T): boolean`

Checks if item exists in set.

```typescript theme={null}
if (set.has("item")) {
    // Item exists
}
```

***

### RPC

Namespace for RPC decorator and configuration.

#### Decorator

##### `@RPC.Method(config: RPC.Config)`

Marks a method as a Remote Procedure Call.

```typescript theme={null}
@RPC.Method({
    endpoints: [RPC.Endpoint.CLIENT_TO_SERVER],
    accessPolicy: RPC.AccessPolicy.OWNER
})
public myRPC(): void {}
```

#### Configuration

```typescript theme={null}
interface RPC.Config {
    endpoints: RPC.Endpoint[];
    accessPolicy?: RPC.AccessPolicy;
    returnMode?: RPC.ReturnMode;
    reliability?: RPC.Reliability;
}
```

#### Enums

##### `RPC.Endpoint`

* `CLIENT_TO_SERVER` - Client calls server
* `SERVER_TO_CLIENT` - Server calls client
* `CLIENT_TO_CLIENT` - Client calls client (not yet implemented)
* `CLIENT_LOCALLY` - Client calls locally
* `SERVER_LOCALLY` - Server calls locally

##### `RPC.AccessPolicy`

* `NONE` / `ANYONE` - Anyone can call
* `OWNER` - Only owner can call
* `NOT_OWNER` - Only non-owners can call

##### `RPC.ReturnMode`

* `DOES_NOT_RETURN` / `VOID` - No return value
* `RETURNS` - Returns a value

##### `RPC.Reliability`

* `RELIABLE` - Guaranteed delivery
* `UNRELIABLE` - Fast but may be dropped

***

## Scene Management

### SceneManager

Manages game scenes.

#### Properties

| Property       | Type                 | Description              |
| -------------- | -------------------- | ------------------------ |
| `currentScene` | `Scene \| undefined` | Currently loaded scene   |
| `sceneChanged` | `Signal<[Scene]>`    | Fires when scene changes |

#### Methods

##### `static loadScene(scene: SceneSerialization.SceneDescription): Scene`

Loads a scene.

```typescript theme={null}
SceneManager.loadScene(MyScene);
```

**Parameters:**

* `scene` - Scene description

**Returns:** Loaded Scene instance

##### `static unloadScene(): void`

Unloads the current scene.

```typescript theme={null}
SceneManager.unloadScene();
```

##### `static changeScene(scene: SceneSerialization.SceneDescription): void`

Changes to a new scene (unloads current, loads new).

```typescript theme={null}
SceneManager.changeScene(NewScene);
```

**Parameters:**

* `scene` - Scene description

##### `static importScene(scene: SceneSerialization.SceneDescription): Scene`

Imports a scene from description without loading.

```typescript theme={null}
const scene = SceneManager.importScene(MyScene);
```

**Returns:** Scene instance

***

### Scene

Represents a game scene.

#### Properties

| Property      | Type                                  | Description       |
| ------------- | ------------------------------------- | ----------------- |
| `description` | `SceneSerialization.SceneDescription` | Scene description |

#### Methods

##### `startFromWorkspace(): void`

Starts the scene from existing workspace instances.

```typescript theme={null}
scene.startFromWorkspace();
```

***

## Utilities

### Signal

Event system for type-safe callbacks.

#### Constructor

```typescript theme={null}
new Signal<T extends unknown[]>(name?: string)
```

**Parameters:**

* `name` - Optional name for debugging

#### Methods

##### `connect(callback: (...args: T) => void): Connection<T>`

Connects a callback to the signal.

```typescript theme={null}
const conn = signal.connect((value) => {
    print(value);
});
```

**Parameters:**

* `callback` - Function to call when signal fires

**Returns:** Connection object

##### `fire(...args: T): void`

Fires the signal with arguments.

```typescript theme={null}
signal.fire(42, "hello");
```

**Parameters:**

* `...args` - Arguments to pass to callbacks

##### `destroy(): void`

Destroys the signal and disconnects all connections.

```typescript theme={null}
signal.destroy();
```

***

### Collector

Garbage collector for automatic resource cleanup.

#### Methods

##### `add(item: RBXScriptConnection | Instance | (() => void) | { destroy(): void }): void`

Adds an item to be cleaned up.

```typescript theme={null}
collector.add(connection);
collector.add(instance);
collector.add(() => print("cleanup"));
```

**Parameters:**

* `item` - Connection, Instance, function, or object with destroy method

##### `teardown(): void`

Cleans up all added items.

```typescript theme={null}
collector.teardown();
```

***

## Type Definitions

### SceneSerialization.SceneDescription

```typescript theme={null}
interface SceneDescription {
    children: GameObjectDescription[];
}
```

### SceneSerialization.GameObjectDescription

```typescript theme={null}
interface GameObjectDescription {
    name: string;
    transform?: SerializedTransform;
    components: ComponentDescription[];
    children: GameObjectDescription[];
}
```

### SceneSerialization.ComponentDescription

```typescript theme={null}
interface ComponentDescription {
    path: ExportPathString; // ["folder", "file", "export"]
    data: Record<string, any>;
}
```

### Configurations.GameConfiguration

```typescript theme={null}
interface GameConfiguration {
    startingScene: SceneSerialization.SceneDescription | string;
}
```

***

## Next Steps

* **[Getting Started](./getting-started)**: Learn the basics
* **[Examples](./examples)**: See practical implementations
* **[Core Concepts](./core-concepts)**: Understand the architecture

***

Complete API reference for building games with CORP! 📚
