Krotox Engine › Docs › Start Here › Concepts

Core concepts: entities, components, scenes and assets

The mental model behind Krotox: entities and components, scenes, assets and their IDs, scripts, units, layers, and the update loop.

Five ideas explain almost everything in Krotox. Once they click, the rest of the docs read easily.


1. Entities and components

An entity is just an identity: an empty object in your scene. It does nothing and shows nothing until you give it components.

A component is a small bundle of data that gives an entity one ability:

To get...Add this component
a position, rotation and sizeTransform2D (every entity has one)
a picture on screenSpriteRenderer
a view of the worldCamera2D
physics movementRigidbody2D
a shape that collidesBoxCollider2D, CircleCollider2D, CapsuleCollider2D, PolygonCollider2D
a grid of tilesTilemap and Grid
buttons and HUD textCanvas, RectTransform, UIButton, UIText
your own behavioura C# script

A "player" is therefore not a special thing. It is an entity with a sprite, a rigidbody, a collider and a controller script. A "coin" is an entity with a sprite, a trigger collider and a pickup script. This is called an entity-component system (ECS), and Krotox uses EnTT for it.

Full list: 2D Component Reference.


2. Scenes

A scene is one level, menu or screen: a set of entities saved to a .ktx file. A build has a start scene, marked in Build Settings, that loads first. Save with Ctrl + S.

Entities can be parented: a child moves, rotates and scales with its parent. A character's weapon is a child of the character.


3. Assets

Assets are the files your game uses: textures, sounds, fonts, shaders, scripts and scenes. They live in your project's Assets folder.

Each asset gets a .meta sidecar file holding a stable 64-bit ID. Scenes refer to assets by that ID, not by file name. That is why renaming or moving an asset inside the editor never breaks anything, and why you should not shuffle assets around in your file explorer.

A prefab is a saved entity you can spawn many times, for example a bullet or an enemy. In code you use Entity.Instantiate.


4. Scripts

Gameplay is written in C#. A script is a class that inherits from Entity and declares lifecycle methods (OnCreate and OnUpdate are plain methods; the others use override):

MethodWhen it runsTypical use
OnAwakeOnce at startup, before any OnCreateLook up components
OnEnableAt startup, after every OnAwakeStart listening for things
OnCreateOnce, after every OnAwake and OnEnableSet initial state, talk to other entities
OnUpdate(ts)Every frameInput, movement, game logic
OnFixedUpdateOn a fixed 60 Hz stepPhysics-related code
OnLateUpdateAfter physics and animation settleCameras that follow a target
OnDisable / OnDestroyJust before the entity is destroyed during PlayClean up

ts is the time in seconds since the last frame. Multiply by it to make movement independent of frame rate. Public fields on a script appear in the Inspector.

See Entity Lifecycle for the full diagram.


5. Space, units and layers


How a frame runs

Input  ->  OnUpdate (your scripts)  ->  Physics step (fixed 60 Hz, OnFixedUpdate)
       ->  OnLateUpdate  ->  Renderer batches all sprites  ->  Present to screen

The renderer batches sprites into as few draw calls as it can. You can watch the draw-call count and frame time in the editor's Profiler.

Where to go next