Krotox Engine › Docs › Scripting API › Core & Lifecycle

Inspector fields & attributes

Which C# field types the editor shows and saves, referencing entities, other scripts and assets from the inspector, and the attributes that shape the inspector: Range, Min, Max, Header, Space, Tooltip, ReadOnly, HideInInspector, ShowInInspector and Color.

Public fields on your script appear in the Properties panel under the Script component. Values you set there are saved with the scene and applied when the game starts, so designers can tune numbers without touching code.

Field types the inspector supports

C# typeShown as
float, double, int, long, uint, ulong, short, ushort, byte, char, boolNumber fields and checkboxes.
stringA text field. A field named exactly TargetScenePath shows a scene picker.
Vector2, Vector3, Vector4Vector fields. Add [Color] to a Vector3/Vector4 for a colour picker.
EntityAn entity slot: drag an entity from the Hierarchy.
A script class, such as public EnemyAI Target;An entity slot that resolves to that entity's script instance at startup. Stays null (with a warning) if the entity has no such script.
Prefab, Texture2D, Font, AudioClip, MaterialAn asset slot: drag the asset from the Content Browser.
A ScriptableObject subclassAn asset slot for a .ktxasset of that class.
Arrays of any of the aboveAn editable list with add and remove rows.

Other custom classes are not exposed.

public class Turret : Entity
{
    public float Range = 8.0f;
    public Entity Target;            // drag an entity here
    public EnemySpawner Spawner;     // resolves to the EnemySpawner script on the chosen entity
    public Prefab BulletPrefab;      // drag a .prefab here
    public AudioClip FireSound;
    public Vector2[] PatrolPoints;   // edited as a list
    public string TargetScenePath;   // scene picker
}

Attributes

AttributeEffect
[Range(min, max)]Shows a slider.
[Min(value)] / [Max(value)]Clamp a number. With both, the field becomes a slider; with one, the value is clamped after editing.
[Header("Title")]A bold section heading above the field.
[Space(height)]Extra space above the field (default 10).
[Tooltip("Text")]Text shown when hovering the field.
[ReadOnly]Shown but not editable.
[HideInInspector]Public but hidden. Still saved.
[ShowInInspector]Shows (and saves) a private field.
[Color]A colour picker for a Vector3 or Vector4.
[ExecutionOrder(int)]On the class: startup order. See the lifecycle.
public class Turret : Entity
{
    [Header("Targeting")]
    [Tooltip("World units. Enemies further away are ignored.")]
    [Min(0.0f)] public float Range = 8.0f;
    [Min(0.1f), Max(5.0f)] public float FireRate = 1.0f;    // slider from 0.1 to 5

    [Header("Look")]
    [Color] public Vector4 LaserColor = new Vector4(1, 0.2f, 0.2f, 1);

    [Space(12)]
    [ReadOnly] public int ShotsFired;                        // visible, not editable
    [HideInInspector] public float Cooldown;                 // saved, not shown
    [ShowInInspector] private Entity m_Target;               // private, but shown and saved
}

Default values

The C# initializer (public float Speed = 5f;) is the default. The inspector shows 0 or empty for a field you have not edited yet; that placeholder is not saved and not applied, so the initializer still wins. As soon as you edit a field, the edited value is saved and used.

If you rename a field, its saved value is dropped and the initializer applies again. Re-enter the value after a rename.

Referencing other scripts

A field typed as another script class gives you that script directly, with no lookup:

public class Door : Entity
{
    public Switch OpenedBy;          // drag the entity that has the Switch script

    void OnUpdate(float ts)
    {
        if (OpenedBy != null && OpenedBy.IsOn)
            Active = false;
    }
}

For an Entity field, get its script with As<T>():

public Entity Player;

void OnCreate()
{
    PlayerController controller = Player.As<PlayerController>();   // null if it has none
}

Fields on spawned prefabs

A prefab keeps the field values it was saved with. After Instantiate, the new entity's scripts have already started, so set extra values on the returned script:

Entity bullet = Instantiate(BulletPrefab, WorldPosition);
bullet.As<Bullet>().Speed = 20.0f;