<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GroupActivities",
  "identifier" : "/documentation/GroupActivities/SpatialTemplateRole",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Group Activities"
    ],
    "preciseIdentifier" : "s:15GroupActivities19SpatialTemplateRoleP"
  },
  "title" : "SpatialTemplateRole"
}
-->

# SpatialTemplateRole

An interface for defining roles that you assign to the
participants of a group activity.

```
protocol SpatialTemplateRole : Hashable, Sendable
```

## Overview

Adopt the [`SpatialTemplateRole`](/documentation/GroupActivities/SpatialTemplateRole) interface in a custom `enum`
and use it with your custom spatial template. Roles are
an optional way for you to assign a purpose to participants with
a spatial Persona. For example, a spatial template for a game might
define roles for the opposing teams. When a participant joins an
activity, assign one of your custom roles to place them in a
specific seat of your template. Seats in the template are available only
to participants with spatial Personas.

The following example shows a spatial template for a table tennis
game with two teams. The first four seats are for the players of the
team, and the last seat is for a spectator. When participants request
a role for the red or blue team, the template assigns them to the
first available seat in the array with that role.

```
struct SimpleTableTennis: SpatialTemplate {
    enum Role: String, SpatialTemplateRole {
        case blueTeam
        case redTeam
    }

    var elements: [any SpatialTemplateElement] = [
        .seat(position: .app.offsetBy(x: -1, z: -3), role: Role.blueTeam),
        .seat(position: .app.offsetBy(x: -1, z:  3), role: Role.redTeam),

        .seat(position: .app.offsetBy(x:  1, z: -3), role: Role.blueTeam),
        .seat(position: .app.offsetBy(x:  1, z:  3), role: Role.redTeam),

        .seat(position: .app.offsetBy(x: -2, z:  0)),
    ]
}
```

## Topics

### Getting the role identifier

[`var roleIdentifier: String`](/documentation/GroupActivities/SpatialTemplateRole/roleIdentifier)

The unique identifier string for the role.

## Relationships

### Inherits From

[`Hashable`](/documentation/Swift/Hashable)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)