cubesEntities and Components

All Out games are built around entities (things in the world) and components (behavior/data attached to entities).

If you’ve used Unity before: think “GameObject + Components”. If you’ve used Roblox: think “Instance + Scripts/Components”. The core idea is the same: you compose gameplay by adding components to entities.

Entities

Entities exist in two common ways:

  • Placed in the editor: they’re already in the scene at startup.

  • Created at runtime: you spawn them from script.

Creating and destroying entities

entity := Scene.create_entity();
entity->set_local_position({10, 20});
entity->set_local_scale({2.5, 2.5});
entity->set_local_rotation(0);

// When you're done:
entity->destroy();
circle-exclamation

Iterating entities

Components

Components are the units of behavior. A component “lives on” an entity and can read/modify that entity.

Getting and adding components

Iterating components

Built-in components you’ll use a lot

Sprite_Renderer

Prefabs (Prefab_Asset)

Prefabs must be created in the editor. In scripts, you instantiate them.

Spine (Spine_Animator)

If you’re using 2D animated characters, you’ll often work with Spine_Animator. See Spine.

Writing a custom component

Make new components in dedicated files (e.g. orbiter.csl) and attach them to entities either:

  • Manually in the editor, or

  • At runtime with entity->add_component(...)

Components can implement lifecycle callbacks:

  • ao_start()

  • ao_update(dt)

  • ao_late_update(dt) (after all updates)

  • ao_end() (when destroyed)

Example:

circle-info

Lifecycle methods for global scripts (ao_start, ao_update, ...) are covered in Game/Frame Lifecycle.

Serialized fields (@ao_serialize)

Use @ao_serialize to expose a field in the editor (and often to enable saving/persistence where applicable).

Finding nearby components (proximity queries)

CSL does not have collision callbacks. A common pattern is “query nearby components and check distance”.

Useful helpers:

Example:

Best practices

  • Per-player state belongs on Player. Avoid global variables that would break with multiple players.

  • Prefer components for gameplay behaviors. You’ll end up with reusable pieces you can attach to different entities.

  • Keep cosmetic work local. UI/particles should usually run behind is_local() checks.

Last updated