# GameService

<Badge tone="type">class · Singleton&lt;GameService&gt;</Badge> <Badge>Unity component</Badge> <Badge>singleton</Badge>

```csharp
public sealed class GameService : Singleton<GameService>, IGameService
```

**Namespace:** `AR51.Unity.SDK` · **Implements:** `IGameService`

Tracks the high-level **game lifecycle state** and drives **placement of placeable objects** in the scene. Reach it via the singleton (`GameService.Instance`); subscribe to `GameStateChanged` to react to lifecycle transitions, and call `SetPlaceable` to run an async placement flow.

All positions are in **meters** (Unity world space).

## Properties

<div className="apiPropTable">

| Property | Type | Default | Description |
|---|---|---|---|
| **State** | | | |
| `State` | `GameState` | — | current lifecycle phase (`Ready` / `Started` / `Stopped` / `Lobby`); `get` public, `set` private |
| **Configuration** | | | |
| `PlayerName` | `string` | `"Player#1"` | display name for the local player |
| `Placeables` | `GamePlaceable[]` | — | placeable objects available to this game |

</div>

## Method summary

| Method | Returns | |
|---|---|---|
| [`EnterLobby`](#enterlobby) | `void` | <Badge>Unity component</Badge> |
| [`SetPlaceable`](#setplaceable) | `Task<PlacingResult>` | <Badge tone="accent">async</Badge> |
| [`Setup`](#setup--cancelsetup) | `void` | <Badge tone="warn">⚠️ no-op stub</Badge> |
| [`CancelSetup`](#setup--cancelsetup) | `void` | <Badge tone="warn">⚠️ no-op stub</Badge> |

→ Full descriptions in [Method details](#method-details) below.

## Events

| Event | Signature | Fires when |
|---|---|---|
| `GameStateChanged` | `GameStateEventHandler(GameState state)` | the game's lifecycle `State` transitions (`Ready` ⇄ `Started` ⇄ `Stopped` ⇄ `Lobby`) |

`State` reflects the current lifecycle phase; subscribe to `GameStateChanged` to be notified on every transition rather than polling `State`.

## Method details

### EnterLobby

<ApiBody kind="method" tags="Unity component">

```csharp
public void EnterLobby();
```

Moves the game into the **`Lobby`** state. `GameStateChanged` fires with the new state.

<Example inferred>

```csharp
var game = GameService.Instance;
game.GameStateChanged += state => Debug.Log($"Game state → {state}");
game.EnterLobby();   // State becomes Lobby; GameStateChanged fires
```

</Example>

</ApiBody>

### SetPlaceable

<ApiBody kind="method" tags="async">

```csharp
public Task<PlacingResult> SetPlaceable(IPlaceable placeable);
```

Starts an **async placement** for `placeable` and resolves once placement completes. The resulting `PlacingResult` carries the anchor id and the completion state.

<Params>
<Param name="placeable" type="IPlaceable">the object to place in the scene</Param>
</Params>

<Returns type="Task<PlacingResult>">a task that resolves with the placement result — anchor id + completion state</Returns>

<Example inferred>

```csharp
PlacingResult result = await GameService.Instance.SetPlaceable(myPlaceable);
// result carries the anchor id and the final placement state
```

</Example>

</ApiBody>

### Setup / CancelSetup

<ApiBody kind="method" tags="Unity component">

```csharp
public void Setup();
public void CancelSetup();
```

Intended to begin / cancel a setup phase.

:::caution[⚠️ Needs confirmation]
In this SDK version, `Setup()` and `CancelSetup()` appear to be **no-op stubs** — they have no observable effect. Treat them as not-yet-implemented until confirmed against the source.
:::

</ApiBody>

## See also

- [`ServiceManager`](/docs/sdk-api/unity-api/classes/servicemanager) — entry point that brings up the service layer GameService runs on
- [`UnityService`](/docs/sdk-api/unity-api/classes/unityservice) — remote-control façade over Unity scene operations
- [Connection](/docs/sdk-api/unity-api/connection) — services and lifecycle overview
- [Class index](/docs/sdk-api/unity-api/classes) — all Unity SDK types
