# Tutorial: avatars in Unreal Engine

The `Sona360` plugin in an Unreal Engine project, and its two projects: SonaStarter (avatars in a room, one
loaded by a Blueprint node, one reaching through Control Rig IK, the player editor) and SonaPlaza (twelve avatars
walking, the bare starter).

## 1. Add the plugin

1. Download the SDK for Unreal ([installing](../install.md)).
2. Copy the `Sona360` folder into your project's `Plugins` folder and put `sona-licence.json` at
   `Content/Sona360/sona-licence.json`. The starter project this tutorial reads from is `starters/unreal-starter` in
   [360sona-templates.tar.gz](../360sona-templates.tar.gz) ([getting it](../install.md#starters-and-templates)): copy the plugin into its `Plugins` folder and open
   `SonaStarter.uproject`.
3. Enable the plugin and restart the editor. The plugin needs Unreal Engine 5.8 or later: its materials are saved
   by 5.8.

## 2. An avatar on an actor

The starter spawns an actor per avatar and gives it a `USonaAvatarComponent`:

```cpp
USonaAvatarComponent* Avatar = NewObject<USonaAvatarComponent>(A, TEXT("Avatar"));
Avatar->Manifest = Manifest;
Avatar->Clip = TEXT("idle");
A->SetRootComponent(Avatar);
A->AddInstanceComponent(Avatar);
Avatar->SetWorldTransform(T);
Avatar->RegisterComponent();
```

In a Blueprint, the latent node Load 360sona Avatar does the same and fires On Ready or On Failed.

## 3. IK from a Control Rig

The 360sona Control Rig component keeps a rig whose controls (`ik_hand_l`, `ik_hand_r`, `ik_foot_l`, `ik_foot_r`,
`look`) are the avatar's IK targets. Move a control from a Blueprint, Sequencer or your own rig graph, and the core
solves the limb towards it inside the joint limits ([IK guide](../guides/ik.md)).

## 4. The player editor

Press E (or the gamepad's Back button) in the starter. `USonaEditorWidget` opens the editor; On Done gives the new
manifest for `SetManifest`.

## 5. Run

Play in the editor, or package the project as usual; the plugin ships the libraries for each platform.

## 6. The plaza project

`starters/unreal` in [360sona-templates.tar.gz](../360sona-templates.tar.gz) is the bare starter: twelve avatars in costumes walking about a plaza built from
the engine's basic shapes.

1. Copy the `Sona360` plugin into its `Plugins` folder.
2. Put `sona-licence.json` at `Content/Sona360/sona-licence.json`. `Config/DefaultGame.ini` leaves `AppId`
   empty, so the plugin opens the app its download is made for.
3. Open `SonaPlaza.uproject` and play. The walkers are `Content/Sona360/plaza-cast.json`.

Unreal draws the same scene as [the plaza starter](starter-plaza.md) on every other platform.

## Next

- [The Unreal guide](../guides/unreal.md) covers every part of the plugin, and the [engine reference](../reference/engines.md#unreal) lists every component, property and Blueprint function.
- Credit: the plugin shows the "Powered by 360sona" badge in a corner of the game viewport.
