<!--
{
  "availability" : [
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "TabletopKit",
  "identifier" : "/documentation/TabletopKit/TabletopGame",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "TabletopKit"
    ],
    "preciseIdentifier" : "s:11TabletopKit0A4GameC"
  },
  "title" : "TabletopGame"
}
-->

# TabletopGame

An object that manages the setup and gameplay of a tabletop game.

```
class TabletopGame
```

## Overview

First, create a [`TableSetup`](/documentation/TabletopKit/TableSetup) object that represents your game layout and equipment. Add seats for players to occupy, conforming to the [`TableSeat`](/documentation/TabletopKit/TableSeat) protocol, and equipment for them to manipulate, conforming to the [`Equipment`](/documentation/TabletopKit/Equipment) protocol.

Pass an object that conforms to the [`Tabletop`](/documentation/TabletopKit/Tabletop) or [`EntityTabletop`](/documentation/TabletopKit/EntityTabletop) protocol to the [`TableSetup`](/documentation/TabletopKit/TableSetup) initializer.

```swift
let table = Table()
root = createRootEntity(table: table.entity)
var setup = TableSetup(tabletop: table)
```

Implement your structure to initialize the protocol properties, such as `shape`, `entity`, and `id` properties for the `EntityTabletop` protocol.

```swift
struct Table: EntityTabletop {
    var shape: TabletopShape
    var entity: Entity
    var id: EquipmentIdentifier
    
    init() {
        self.entity = try! Entity.load(named: "table/table", in: contentBundle)
        self.shape = .round(entity: entity)
        self.id = .table
    }
}
```

Then, create the `TabletopGame` object that represents your game instance by passing the `TableSetup` object to the [`init(tableSetup:version:)`](/documentation/TabletopKit/TabletopGame/init(tableSetup:version:)) initializer.

```swift
game = TabletopGame(tableSetup: setup)
```

Place the [`localPlayer`](/documentation/TabletopKit/TabletopGame/localPlayer) in a seat at the table using [`claimSeat(_:)`](/documentation/TabletopKit/TabletopGame/claimSeat(_:)) or a similar method.

```swift
game.claimAnySeat()
```

Next, implement an object that renders your game layout and equipment. Set the game’s renderer, conforming to the [`TabletopGame.RenderDelegate`](/documentation/TabletopKit/TabletopGame/RenderDelegate) protocol, using the [`addRenderDelegate(_:)`](/documentation/TabletopKit/TabletopGame/addRenderDelegate(_:)) method. Implement the [`onUpdate(timeInterval:snapshot:visualState:)`](/documentation/TabletopKit/TabletopGame/RenderDelegate/onUpdate(timeInterval:snapshot:visualState:)) method to render the current state of the game. Alternatively, conform to the [`EntityRenderDelegate`](/documentation/TabletopKit/EntityRenderDelegate) protocol.

```swift
game.addRenderDelegate(self)
```

If needed, you can draw a debug representation of selected items in the game using the [`debugDraw(options:)`](/documentation/TabletopKit/TabletopGame/debugDraw(options:)) method.

```swift
game.debugDraw(options: [.drawTable, .drawSeats, .drawEquipment])
```

Then, add actions to the equipment that controls gameplay using the [`addAction(_:)`](/documentation/TabletopKit/TabletopGame/addAction(_:)-10j8v) and [`addActions(_:)`](/documentation/TabletopKit/TabletopGame/addActions(_:)) methods.

Finally, pass an object to the [`addObserver(_:)`](/documentation/TabletopKit/TabletopGame/addObserver(_:)) method that conforms to the [`TabletopGame.Observer`](/documentation/TabletopKit/TabletopGame/Observer) protocol. Implement the `Observer` protocol methods to progress gameplay when players interact with the equipment.

## Topics

### Creating a tabletop game

[`init(tableSetup: TableSetup, version: Int)`](/documentation/TabletopKit/TabletopGame/init(tableSetup:version:))

Creates a tabletop game with the specified table configuration and version of rules.

[`var rootPose: Pose3D`](/documentation/TabletopKit/TabletopGame/rootPose)

Update the root pose for the current player

[`func update(deltaTime: Double)`](/documentation/TabletopKit/TabletopGame/update(deltaTime:))

Update the game manually. Call this function if `automaticUpdate` was not set when registering the Tabletop instance.

[`func withCurrentSnapshot((TableSnapshot) -> Void)`](/documentation/TabletopKit/TabletopGame/withCurrentSnapshot(_:))

### Adding equipment to the game

[`var equipment: [any Equipment]`](/documentation/TabletopKit/TabletopGame/equipment)

[`var equipmentIDs: [EquipmentIdentifier]`](/documentation/TabletopKit/TabletopGame/equipmentIDs)

[`func equipment(matching: EquipmentIdentifier) -> (any Equipment)?`](/documentation/TabletopKit/TabletopGame/equipment(matching:))

[`func equipment<E>(of: E.Type) -> [E]`](/documentation/TabletopKit/TabletopGame/equipment(of:))

[`func equipment<E>(of: E.Type, forEntity: Entity) -> E?`](/documentation/TabletopKit/TabletopGame/equipment(of:forEntity:))

Retrieves the specified equipment type associated with an entity if it exists.

[`func equipment<E>(of: E.Type, matching: EquipmentIdentifier) -> E?`](/documentation/TabletopKit/TabletopGame/equipment(of:matching:))

### Managing seats

[`func claimAnySeat()`](/documentation/TabletopKit/TabletopGame/claimAnySeat())

Claims any free seat.
Has no effect if the player is already seated or if there are no free seats.

[`func claimSeat(some TableSeat)`](/documentation/TabletopKit/TabletopGame/claimSeat(_:))

Claims the given seat. If provided Seat is not part of the table, it has no effect

[`func claimSeat(matching: TableSeatIdentifier)`](/documentation/TabletopKit/TabletopGame/claimSeat(matching:))

Claims the given seat. If provided ID does not exist, it has no effect

[`func releaseSeat()`](/documentation/TabletopKit/TabletopGame/releaseSeat())

Releases the seat for this player. If the player is not seated it has no effect

### Getting the player

[`var localPlayer: Player`](/documentation/TabletopKit/TabletopGame/localPlayer)

The player who runs this tabletop game instance on their device.

### Adding actions

[`func addAction(some TabletopAction)`](/documentation/TabletopKit/TabletopGame/addAction(_:)-10j8v)

[`func addAction(some CustomAction)`](/documentation/TabletopKit/TabletopGame/addAction(_:)-9zgsy)

[`func addActions(some Sequence<any TabletopAction>)`](/documentation/TabletopKit/TabletopGame/addActions(_:))

### Observing actions

[`protocol Observer`](/documentation/TabletopKit/TabletopGame/Observer)

A protocol for objects that progress gameplay when players take actions.

[`func addObserver(some TabletopGame.Observer)`](/documentation/TabletopKit/TabletopGame/addObserver(_:))

[`func removeObserver(some TabletopGame.Observer)`](/documentation/TabletopKit/TabletopGame/removeObserver(_:))

[`enum ActionCancellationReason`](/documentation/TabletopKit/TabletopGame/ActionCancellationReason)

The possible reasons for cancelling an action or an interaction.

### Jumping to bookmarks

[`func jumpToBookmark(StateBookmark)`](/documentation/TabletopKit/TabletopGame/jumpToBookmark(_:))

Restores game to the given bookmark

[`func jumpToBookmark(matching: StateBookmarkIdentifier)`](/documentation/TabletopKit/TabletopGame/jumpToBookmark(matching:))

Restores game to the given bookmark

[`var bookmarks: [StateBookmarkIdentifier]`](/documentation/TabletopKit/TabletopGame/bookmarks)

### Starting interactions

[`func startInteraction(onEquipmentID: EquipmentIdentifier) -> TabletopInteraction.Identifier?`](/documentation/TabletopKit/TabletopGame/startInteraction(onEquipmentID:))

Starts a local interaction. It will return `nil` if too many interactions are already happening at the same time.

### Canceling interactions

[`func cancelAllInteractions()`](/documentation/TabletopKit/TabletopGame/cancelAllInteractions())

Cancels all local and remote interactions.
This releases control of all the equipment and rolls back all the actions
added to the canceled interaction.

[`func cancelInteraction(matching: TabletopInteraction.Identifier)`](/documentation/TabletopKit/TabletopGame/cancelInteraction(matching:))

Cancel the local or remote interaction matching the given identifier.
This causes any actions added to it to be rolled back, and releases the
controlled equipment and any tossed equipment.

### Rendering the table

[`func addRenderDelegate(some TabletopGame.RenderDelegate)`](/documentation/TabletopKit/TabletopGame/addRenderDelegate(_:))

[`func removeRenderDelegate(some TabletopGame.RenderDelegate)`](/documentation/TabletopKit/TabletopGame/removeRenderDelegate(_:))

[`protocol RenderDelegate`](/documentation/TabletopKit/TabletopGame/RenderDelegate)

A protocol for the object that renders your entire game.

[`protocol EntityRenderDelegate`](/documentation/TabletopKit/EntityRenderDelegate)

A protocol for the object that renders your entire game using RealityKit.

### Supporting multiple players

[`func attachNetworkCoordinator(some TabletopNetworkSessionCoordinator)`](/documentation/TabletopKit/TabletopGame/attachNetworkCoordinator(_:))

[`func detachNetworkCoordinator()`](/documentation/TabletopKit/TabletopGame/detachNetworkCoordinator())

[`var multiplayerDelegate: (any TabletopGame.MultiplayerDelegate)?`](/documentation/TabletopKit/TabletopGame/multiplayerDelegate-swift.property)

[`protocol MultiplayerDelegate`](/documentation/TabletopKit/TabletopGame/MultiplayerDelegate-swift.protocol)

An object that handles players joining multiplayer games.

### Enabling group activities

[`func coordinateWithSession(GroupSession<some GroupActivity>)`](/documentation/TabletopKit/TabletopGame/coordinateWithSession(_:))

Begins coordination of the game with a group session

### Drawing debug representations

[`func debugDraw(options: DebugDrawOptions)`](/documentation/TabletopKit/TabletopGame/debugDraw(options:))

Enable or disable debug visualizations



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)