# Unity

The agh package for the Unity editor shows how each asset was made right where you use it, lets you tag assets and request new ones without leaving Unity, and finds the agh assets your game no longer uses. It works with Unity 2021.3 and later.

## Install it

In Unity, open **Window > Package Manager**, choose **+ > Add package from git URL**, and enter:

```text
https://github.com/chust4phun/assetgoeshere.git?path=engines/unity/com.assetgoeshere.agh
```

Unity adds Newtonsoft Json, which the package needs, on its own.

Then open **Project Settings > Asset Goes Here** and set:

- **Server**: your agh address, such as `https://app.assetgoeshere.com`, or `http://localhost:7414` for `agh serve`.
- **Project**: the agh project id, as `agh projects` lists it.
- **Repository folder**: where the Unity project sits in its repository, such as `game`. Leave it empty and the package finds it from the `.git` folder. agh paths are relative to the repository root, so `Assets/Art/wolf.png` in a project under `game/` is `game/Assets/Art/wolf.png` to agh.

These settings are saved in `ProjectSettings/AssetGoesHere.asset`, so commit it and your team gets them too.

## Sign in

Open **Window > Asset Goes Here** and choose **Sign in**. Your browser opens to sign in, as it does for `agh login`. The package and the agh CLI share one sign-in: signing in on either one signs in both, and so does signing out.

On a local `agh serve` there is no sign-in. You are the **Local user** set in Project Settings, which defaults to your computer's user name.

A build machine can sign in as an agh tool instead: set **Tool client id** and **Tool client secret** in Project Settings, or `AGH_CLIENT_ID` and `AGH_CLIENT_SECRET` in its environment. These are kept per person in EditorPrefs and never written to the project.

## See how an asset was made

Select a file agh tracks, and the Inspector shows its agh id, status, how it was made (AI-generated, AI-assisted, human-made or unknown) and by what, and its tags. Choose **agh…** for the full record in the agh window: the brief, spec and notes, who delivered the file and when, what its metadata says, the pull request it waits in, and its conversation.

The Project window marks each agh asset: **AI** for AI-generated, **AI+** for AI-assisted, **H** for human-made and **?** for unknown. Turn the marks off in Project Settings.

Without signing in, the package still reads the repository's `.agh/provenance.yaml`, so published assets show how they were made. Signing in adds the brief, tags, history, and requests that aren't published yet.

## Edit tags

In the agh window's **Asset** tab, remove a tag with **×**, or type `key=value` to add one. Tags already used in the project are suggested as you type: keys first, then the values used with that key. **Tab** takes the first suggestion and **Enter** adds the tag. Choose **Save tags** to send the changes. Admins and developers can change tags.

## Request an asset

Right-click a folder in the Project window and choose **agh > Request Asset Here…**, or open the **Request** tab. Give the file's path with its name, and the package suggests an id and kind from it, the way `agh adopt` does: `Assets/Art/Cards/Ember Wolf.png` becomes `art.cards.ember_wolf`. Write the brief, and add spec, notes and tags if they help.

The request goes into your draft batch. Tick **Submit my draft batch for approval** to send the batch with a message, and, as an admin or developer, **Approve it too** so fulfillers can start at once.

Right-click a file agh doesn't track to request a replacement for it at the same path. For a file agh does track, open **Ask for a new version** in the **Asset** tab instead.

Selecting a folder in the **Asset** tab lists the agh requests for files that aren't in it yet.

## Find unused assets

Open the **Unused** tab, or right-click and choose **agh > Find Unused Assets**, then **Scan**. A file counts as used when something the build includes refers to it, directly or through other assets such as prefabs and materials:

- the scenes in Build Settings, or every scene when Build Settings lists none
- files in `Resources` folders and in `StreamingAssets`
- preloaded assets and always-included shaders
- Addressables entries, when the project uses Addressables
- the **Always used folders** in Project Settings, for files your code loads some other way

The scan lists:

- **Unused**: nothing the build includes refers to these, and no script names them. The Project window marks them red until the next scan.
- **Named in scripts only**: no asset refers to these, but a script has their name or path in a string, so code may load them. Check before removing.
- **agh assets not in the project yet**: open requests, and published files that haven't merged or been pulled.

Untick **Only files agh tracks** to check every content file under `Assets/`. Files in `Editor` folders, scripts and plugins are never listed, since they aren't game content.
