Table of Contents

Struct WorldEntityRef

Namespace
KeenEyes
Assembly
KeenEyes.Abstractions.dll

Reference to an entity in another world.

public readonly struct WorldEntityRef
Inherited Members

Examples

// Client entity tracking its server counterpart
[Component]
public partial struct NetworkedEntity
{
    public WorldEntityRef ServerEntity;
}

// Usage
var serverEntity = serverWorld.Spawn().Build();
var clientEntity = clientWorld.Spawn()
    .With(new NetworkedEntity
    {
        ServerEntity = new WorldEntityRef
        {
            WorldId = serverWorld.Id,
            Entity = serverEntity
        }
    })
    .Build();

// Later, resolve the reference
if (clientWorld.Get<NetworkedEntity>(clientEntity)
    .ServerEntity
    .TryResolve(new[] { serverWorld }, out var world, out var entity))
{
    // Access the server entity
    ref var serverPos = ref world!.Get<Position>(entity);
}

Remarks

Used for scenarios where entities in different worlds need to reference each other, such as client-server simulations where a client entity tracks its server counterpart.

This struct stores the world ID and entity, allowing safe cross-world references that can be validated using TryResolve(IEnumerable<IWorld>, out IWorld?, out Entity).

Properties

Entity

The entity within that world.

public Entity Entity { get; init; }

Property Value

Entity

WorldId

ID of the world containing the referenced entity.

public Guid WorldId { get; init; }

Property Value

Guid

Methods

TryResolve(IEnumerable<IWorld>, out IWorld?, out Entity)

Attempts to resolve this reference to an actual entity.

public bool TryResolve(IEnumerable<IWorld> worlds, out IWorld? world, out Entity entity)

Parameters

worlds IEnumerable<IWorld>

Collection of available worlds to search.

world IWorld

The world containing the entity, if found.

entity Entity

The entity, if found and alive.

Returns

bool

True if the reference was successfully resolved.

Remarks

This method searches the provided worlds for one matching WorldId, then verifies that Entity is still alive in that world. If both checks pass, the method returns true and populates the out parameters.