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
WorldId
ID of the world containing the referenced entity.
public Guid WorldId { get; init; }
Property Value
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
worldsIEnumerable<IWorld>Collection of available worlds to search.
worldIWorldThe world containing the entity, if found.
entityEntityThe entity, if found and alive.
Returns
- bool
True if the reference was successfully resolved.