---
title: SpatialTemplateRole
framework: groupactivities
role: symbol
role_heading: Protocol
path: groupactivities/spatialtemplaterole
---

# SpatialTemplateRole

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

## Declaration

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

## Overview

Overview Adopt the 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

- [roleIdentifier](groupactivities/spatialtemplaterole/roleidentifier.md)

## Relationships

### Inherits From

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Custom spatial templates

- [Building a guessing game for visionOS](groupactivities/building-a-guessing-game-for-visionos.md)
- [SpatialTemplate](groupactivities/spatialtemplate.md)
- [SpatialTemplatePreference](groupactivities/spatialtemplatepreference.md)
- [SpatialTemplateSeatElement](groupactivities/spatialtemplateseatelement.md)
- [SpatialTemplateElement](groupactivities/spatialtemplateelement.md)
- [SpatialTemplateElementPosition](groupactivities/spatialtemplateelementposition.md)
- [SpatialTemplateElementDirection](groupactivities/spatialtemplateelementdirection.md)
