Vixen
02b45cc4
csharp
public readonly record struct Entity

A generation-checked handle to an entity: a dense slot index, the version that slot was on when the handle was taken, and the world it belongs to. Reusing a slot bumps its version, so a stale handle compares unequal to the entity that now lives there instead of silently addressing it.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

This is the *runtime* identity and is never written to a scene file: ids are dense and reused, so a saved one means nothing when loaded back. Identity that survives save and load is a component (see docs/plan/04-ecs-and-scripting.md § Determinism).

The world id is carried in the handle rather than checked by convention because passing an entity from the editor's world to the play world is a real mistake with no other way to detect it — both handles are live, both slots exist, and the versions agree far more often than anyone expects.

It lives in Vixen.Core beside ComponentTypeId and ComponentAttribute rather than in Vixen.Ecs, for the same reason those do: the reflection and serialization generators name it, and they cannot reference the ECS.

Fields and properties (7)

  • public int Id

    The dense slot index. Slot 0 is never allocated, so it means "no entity".

  • public int Version

    The slot's version when the handle was taken.

  • public short WorldId

    Which world the slot lives in.

  • public const int MaxTextLength

    Longest text ToString can produce: three numbers and two separators.

  • public static Entity Null

    The handle to no entity. Slot 0 is never allocated, so this cannot collide.

  • public bool IsNull

    Whether this is Null.

  • public ulong Packed

    Slot and version in one word — version high, id low — for hashing and for packing into a sort key.

Methods (17)

  • public Entity(int Id, int Version, short WorldId)

    A generation-checked handle to an entity: a dense slot index, the version that slot was on when the handle was taken, and the world it belongs to. Reusing a slot bumps its version, so a stale handle compares unequal to the entity that now lives there instead of silently addressing it.

  • public static Entity FromPacked(ulong packed, short worldId = 0)

    Unpacks a handle produced by Packed.

  • public int CompareTo(Entity other)
  • public static bool operator <(Entity left, Entity right)

    Whether sorts before .

  • public static bool operator <=(Entity left, Entity right)

    Whether sorts before or equal to .

  • public static bool operator >(Entity left, Entity right)

    Whether sorts after .

  • public static bool operator >=(Entity left, Entity right)

    Whether sorts after or equal to .

  • public override string ToString()

    Renders the handle as id:version@world.

  • public string ToString(string? format, IFormatProvider? formatProvider)

    Formats the value of the current instance using the specified format.

  • public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)

    Tries to format the value of the current instance into the provided span of characters.

  • public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)

    Tries to format the value of the current instance as UTF-8 into the provided span of bytes.

  • public static Entity Parse(string s, IFormatProvider? provider = null)

    Parses a string into a value.

  • public static Entity Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)

    Parses a span of characters into a value.

  • public static bool TryParse(string? s, IFormatProvider? provider, out Entity result)

    Tries to parse a string into a value.

  • public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Entity result)

    Tries to parse a span of characters into a value.

  • public static bool TryParse(string? s, out Entity result)

    Parses the id:version@world form.

  • public static bool TryParse(ReadOnlySpan<char> s, out Entity result)

Used by (334, showing 40)

  • ArenaMultiplayer
  • ArenaThirdPersonShooter
  • CharacterAnimationThirdPersonShooter
  • FighterMultiplayer
  • GameClientMultiplayer
  • PlayerRigThirdPersonShooter
  • ProgramEcsStressTest
  • RespawnWhenBelowThirdPersonShooter
  • SliceResolverNetworkSoak
  • SoakNetworkSoak
  • Vixen_Samples_Multiplayer_CombatantReplicatorMultiplayer
  • Vixen_Samples_Multiplayer_VitalsReplicatorMultiplayer
  • WeaponFireThirdPersonShooter
  • WorldBenchmarksVixen.Benchmarks.Ecs
  • AllNetworkedSourceVixen.Net
  • AnimationSystemVixen.Animation
  • ArchetypeVixen.Ecs
  • AudioEventSystemTestsVixen.Audio.Tests
  • AudioSystemTestsVixen.Audio.Tests
  • BehaviorVixen.Engine
  • BehaviorRegistrationTestsVixen.Engine.Tests
  • BehaviorStoreVixen.Engine
  • BehaviorTestsVixen.Engine.Tests
  • BitExactnessTestsVixen.Net.Tests
  • CameraBlendTableVixen.Engine
  • CameraDirectorSystemVixen.Engine
  • CameraDirectorTestsVixen.Engine.Tests
  • CameraExtractionTestsVixen.Rendering.Tests
  • CameraTargetsVixen.Engine
  • CandidateVixen.Engine
  • ChannelVixen.Ecs
  • CharacterAllocationTestsVixen.Physics.Tests
  • CharacterSceneTestsVixen.Physics.Tests
  • ChildVixen.Engine
  • ChildSequenceVixen.Engine
  • ChunkVixen.Ecs
  • ClientPredictionTestsVixen.Net.Tests
  • CommandVixen.Ecs
  • CommandBufferVixen.Ecs
  • CommandBufferTestsVixen.Ecs.Tests