Create & Manage Actors

This guide will walk through creating & managing Tivet Actors.


Actor tags

Tags are simple key-value pairs attached to every actor. Tags serve two purposes:

  1. Actor Discovery: Find specific actors using client.get(tags, opts)

  2. Organization: Group actors for monitoring & administration purposes

When choosing tags, follow these best practices:

  • Keep values short and concise

  • Use consistent naming patterns

  • Avoid storing sensitive information

The name tag is required and specifies which type of actor to spawn.

Common tag patterns

The following examples show different ways tags can be used to organize actors:

Party CodeChat

// Connect to a game server using a party code
const gameServer = await client.get<GameServer>({
  name: 'game_server',
  partyCode: 'ABCDEF'
});

Client

Clients are used to connect & manage actors.

To create a new client, write:

Documentation

Attempts to find an existing actor matching the provided tags. If no matching actor is found, it creates a new one with those tags.

Documentation

Explicitly create a new actor with the provided tags.

Documentation

Connects to an actor based on its ID.

It's recommended to use tags instead of using actor IDs directly.

For example:

Options

opts.parameters

All client methods accept a parameters property. This can be used to pass information about the current connection, such as authentication tokens or usernames.

For example:

opts.create.tags

When creating an actor, you can specify additional tags beyond those used for querying. If opts.create.tags is not provided, the query tags will be used. For example:

opts.create.region

By default, actors are created in the region with the lowest latency for the client. You can override this by specifying create.region:

opts.noCreate

To prevent creating a new actor if it does not exist, pass the noCreate option. For example:


Shutdown actor

For security reasons, actors must be shut down from within the actor itself using this._shutdown(). For example:

Last updated