Entity Reservation System

What does it do

The Entity Reservation System provides simple way to access reserved entity IDs when spawning SpatialOS entities.

It maintains a pool of reserved IDs that you can access without the network hop of a ReserveEntityIds command. The system will aim to keep the pool refilled.

Note: Although the system will aim to keep the pool refilled, it can be depleted if you take many entity IDs in a short period of time. This fallibility is represented in the API, described below.

Synchronous API

The synchronous API provides the following methods:

public bool TryTake(uint count, out EntityId[] entityIds)
public bool TryGet(out EntityId entityId);

These methods will attempt to return you 1 or more entity IDs, but will return false if the pool does not contain the amount requested.

Example:

private void SpawnCube()
{
    var entityReservationSystem = world.GetExistingSystem<EntityReservationSystem>();
    if (entityReservationSystem.TryGet(out var entityId))
    {
        SpawnCube(entityId);
    }
}

Asynchronous API

The asynchronous API provides the following methods:

public Task<EntityId[]> TakeAsync(int count);
public Task<EntityId> GetAsync();

If the pool contains the amount of IDs requested, the task will be completed immediately. If not, the request will be queued and the task completed when the pool has the required number of IDs.

Note: You should not block the main thread by calling .Wait() or .Result on these Task objects. If you are unfamiliar with asynchronous programming in C#, check out Microsoft's guidelines

Example:

private async Task SpawnCube()
{
    var entityReservationSystem = world.GetExistingSystem<EntityReservationSystem>();
    var entityId = await entityReservationSystem.GetAsync();
    SpawnCube(entityId);
}

Updated about a year ago


Entity Reservation System


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.