SCRIPTING API / Scripts and entities / Entity
Entity
Handle to an entity in one world (scene). It mirrors the engine's 32-bit entity id: a 20-bit slot index and a 12-bit generation. Destroying an entity bumps the generation of its slot, so a stored handle reports IsAlive false instead of naming the next entity that reuses the slot.
Kindstruct
NamespaceKroys.EngineScripting
Members14
Source
Entity.csEXAMPLE
In a script
A complete script that uses Entity; copy it into your scripts project.
Core.cs
public sealed class DoorSwitch : EntityScript { public string DoorName = "Door"; // a child of this entity, set in the Inspector private Entity door; protected override void OnStart() { door = Entity.FindChild(DoorName, recursive: true); if (!door.IsValid) Debug.LogWarning($"{Entity.Name}: no child called {DoorName}"); } protected override void OnTriggerEnter(Entity other) { // A stored handle stays safe: after Destroy, IsAlive is false. if (door.IsAlive) { Debug.Log($"{other.Name} opened {door.Name}"); door.Destroy(); } } }
REFERENCE
Members
Properties
#public static Entity Invalid { get; }Invalid entity handle used when a lookup fails.
#public uint Id { get; }The engine's 32-bit entity id (index and generation). Session only: never persist it; use an EntityRef.
#public uint Index { get; }Slot index of the entity (low 20 bits of
Id).#public uint Generation { get; }Generation of the slot when this handle was taken (high 12 bits of
Id).#public World World { get; }The world (scene) this entity belongs to.
#public bool IsValid { get; }Gets whether this handle names an entity at all (it may still have been destroyed).
#public bool IsAlive { get; }Gets whether the referenced native entity still exists.
#public string Name { get; }Gets the entity name.
#public Transform Transform { get; }Gets the transform wrapper for this entity.
#public Entity Parent { get; }Gets the parent entity, or Entity.Invalid when this entity is at the hierarchy root.
#public int ChildCount { get; }Gets the number of direct child entities.
Methods
#public void Destroy()Destroys this entity in the native scene.
#public Entity GetChild(int index)Returns the direct child at index, or Entity.Invalid when the index is invalid.
#public Entity FindChild(string name, bool recursive = false)Finds a child by name. Set recursive to true to search all descendants.
Signatures
public static Entity Invalid { get; } public uint Id { get; } public uint Index { get; } public uint Generation { get; } public World World { get; } public bool IsValid { get; } public bool IsAlive { get; } public string Name { get; } public Transform Transform { get; } public Entity Parent { get; } public int ChildCount { get; } public void Destroy() public Entity GetChild(int index) public Entity FindChild(string name, bool recursive = false)
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.