Unity technical documentation Version 1.0.0

Avatar Cosmetics

Cosmetics for a humanoid: hats, jackets, and items in the hands. Besides a menu, the player can grab an item, hold it near the head or chest, adjust it, and let go to lock it on, the same way you put on a real hat or jacket.

com.themetrics.avatar-cosmetics · Unity 6 (6000.0) or newer

Requirements

  • Unity 6 (6000.0) or newer.
  • A humanoid Animator on the avatar. The module resolves bones through Unity Humanoid retargeting. For another avatar system, implement IAvatarSocketProvider.
  • Optional: Netcode for GameObjects 2 or newer, to replicate the outfit. The local player owns their avatar and writes the equipped mask; other peers apply it. Without Netcode, the NGO module is skipped and the rest runs single-player.
  • Optional: TheMetrics Full Body Avatar. When it is in the project, the Integration/FullBody module turns itself on (THEMETRICS_FULLBODY): bone sockets follow body swaps, and the offset-profile preview loads a real body in Edit Mode.
  • Optional: XR Interaction Toolkit 3 or newer, for the grab used by dynamic placement.
  • Optional: com.unity.ugui (TextMesh Pro is included in Unity 6) for the generated equip canvas. Nothing else in the package needs it.

Netcode and XR Interaction Toolkit are not shipped inside the cosmetics folder. The VR Multiplayer template already includes both.

Installation

  1. Import the package

    Import Avatar Cosmetics into the project.

  2. Network sync

    With Netcode, sync sits on the player next to its NetworkObject: NgoCosmeticEquipSync and NgoCosmeticPlacementSync.

  3. Grabbing

    For physical placement, install XR Interaction Toolkit from Window → Package Manager → Unity Registry.

  4. Project settings

    Open Project Settings → Avatar Cosmetics. Rig Prefab is the networked player rig and must have an AvatarEquipOnSpawn somewhere on it. Content Root Folder is where generated prefabs are created: visuals, networked twins, grabbable activators, and dispensers. Both fields can stay empty; the tools ask for them when they need them.

Socket and index

Every cosmetic is identified by a (socket, index) pair.

Avatar Cosmetics sockets
Socket What it is for
HeadSocket Hats, helmets, glasses, and other headwear.
ChestSocket Jackets, vests, and chest armor.
RightHandSocket Items held in the right hand.
LeftHandSocket Items held in the left hand.

Each socket has its own ordered list of prefabs on AvatarEquipOnSpawn. The index is the position in that list: 0 is the first entry, 1 the second. Several items can sit on the same socket at once, up to 32, and each one is tracked by its index.

That pair shows up on CosmeticEquip components, in CosmeticOffsetProfile entries, and in RequestEquipOnLocalPlayer(socket, index).

Three ways to equip

  1. Auto-equip on spawn

    AvatarEquipOnSpawn can equip a fixed set when the rig spawns, in specific scenes. Configure it under Auto-equip in scenes, checked against File → Build Settings. Use it when everyone should start in the same uniform.

  2. Zone or button

    Add CosmeticEquip to a button, a wardrobe item, or a trigger volume. Set Socket and Cosmetic Index. Call Equip() from OnClick, or equip automatically when the local player hand enters the collider (EquipFromEquipZone, wired through ColliderEvents). If Hide Self On Success is on, the object hides once equipped and comes back if that socket and index are unequipped, so a wardrobe display does not stay empty.

  3. Generated canvas

    Tools → TheMetrics → Avatar Cosmetics → Create Equip Canvas (UI) builds a world-space canvas with a scroll view and a CosmeticEquipCanvasBuilder already wired to a button template. At Play it reads the local AvatarEquipOnSpawn catalog and clones one button per (socket, index). A click toggles equip, and the button of the current item is tinted. It needs TextMesh Pro and UnityEngine.UI. If you drive the UI with XR Interaction Toolkit, add a TrackedDeviceGraphicRaycaster and an XRUIInputModule yourself: this module does not assume XRI is installed.

  4. Physical placement

    On the grabbable prefab, add CosmeticDynamicPlacement next to CosmeticEquip. The state moves through Free, Held, Adjusting, PlacedUnlocked, and Locked.

  • Free: sitting in the world, not held.
  • Held: the player picked it up.
  • Adjusting: the player is holding it inside the target socket zone, near the head or chest, and can reposition it.
  • PlacedUnlocked: they let go inside the zone. The item is pinned to the socket and can still be grabbed again. If it is left alone, it auto-locks after a configurable delay (5 seconds by default).
  • Locked: the pose is committed. If that socket and index exist in the rig catalog, the physical object is hidden and swapped for a cheap networked twin at the captured pose. Otherwise it falls back to an inert local lock.

Every socket, hands included, has its own equip zone, editable on the rig AvatarEquipOnSpawn. A hand item has to be put on with the other hand: while the target hand is holding it, its zone is ignored.

CosmeticDressingZone goes on a trigger volume, such as a changing room. Inside it, the player can readjust items that are already locked. On exit they lock again.

Add a cosmetic

The short path is the Cosmetic Pipeline Builder.

  1. Pick the model

    Select a prefab or an .fbx, .obj, .gltf, or .glb model in the Project window.

  2. Open the wizard

    Tools → TheMetrics → Avatar Cosmetics → Create Cosmetic Pipeline from Selected Prefab...

  3. Create

    Fill in the root name, target socket, and index, then click Create Pipeline.

That generates three linked prefabs under the configured Content Root:

  • CosmeticsNetworked/{Name}Root: the worn item. It is added to the AvatarEquipOnSpawn catalog for the chosen socket and index. Every peer instantiates it from the replicated equip mask, so it needs no NetworkObject.
  • Grabbable-Activators/{Name}Root Grabbable: the physical version, with CosmeticEquip, CosmeticDynamicPlacement, and the grab component of the installed interaction layer (XRGrabInteractable when XR Interaction Toolkit is present).
  • Dispenser/{slug}-dispenser: a HoverClone trigger that gives each player their own local grabbable copy.

Fixed or dynamic

A new cosmetic is dynamic: it stays where the player lets go of it inside the zone. To make it fixed, so it always snaps to the same pose, open the rig CosmeticOffsetProfile and, on that cosmetic entry:

  1. Optional: click Preview in scene (Edit Mode). Play is not required. Move the [Preview] object into place.
  2. Click Save Pose. That makes it fixed.

Make Dynamic, on the same entry or in the CosmeticEquip inspector, clears the saved pose and makes sure the prefab has CosmeticDynamicPlacement. If the prefab is itself a NetworkObject placed in the scene, it also gets NgoCosmeticLockSync and NgoNetworkSetActive. You can save the pose of any Transform from its context menu: Save Root Position → Cosmetic Offset Profile.

Then run Validate Setup to catch anything missing or out of range.

Network and persistence

CosmeticLoadoutCapture, on the rig prefab, continuously mirrors the local player equipped masks and dynamic poses to PlayerPrefs, and restores them on spawn in the next scene.

To make a scene always start bare, such as character creation, assign a CosmeticSceneFlowConfig asset to AvatarEquipOnSpawn and list those scenes under Start Empty Scene Names.

The core has no dependency on Netcode or an interaction package: it compiles and runs standalone. With Netcode for GameObjects, THEMETRICS_NGO is defined and NgoCosmeticEquipSync, NgoCosmeticPlacementSync, NgoCosmeticLockSync, and NgoNetworkSetActive replicate the outfit. XR Interaction Toolkit adds the grab (XRIT_ENABLED). The local player is the one who writes the equipped mask.

Tools

Everything lives under Tools → TheMetrics → Avatar Cosmetics.

  • Setup Cosmetics on Selected Rig: adds the cosmetics components to the selected rig prefab and makes it the project rig used by the other tools.
  • Validate Setup: scans for missing catalog entries, out-of-range indices, dynamics that cannot be grabbed, network components without a NetworkObject, and scenes missing from Build Settings. Start here when something does not work.
  • Create Cosmetic Pipeline from Selected Prefab...: generates the prefab trio.
  • Refresh Full Body Avatar Detection: checks again whether Full Body Avatar is in the project and toggles Integration/FullBody. It also runs on every reload.
  • Create Equip Canvas (UI): builds the world-space equip menu. It needs com.unity.ugui.

Project-wide configuration is at Project Settings → Avatar Cosmetics.

Common problems

Something does not equip, or the index is wrong

Run Tools → TheMetrics → Avatar Cosmetics → Validate Setup. It points at the object: a wrong index, a network component with no NetworkObject above it, or a scene missing from Build Settings.

The physical item cannot be grabbed

Install XR Interaction Toolkit 3 and generate the pipeline again, or add the grab component of the interaction layer you have. The grabbable prefab needs CosmeticEquip and CosmeticDynamicPlacement.

Other players do not see the outfit

Confirm Netcode for GameObjects 2, a NetworkObject on the player, and NgoCosmeticEquipSync plus NgoCosmeticPlacementSync. The avatar owner is the one who writes the mask.

The item does not land on the expected pose

If it should be fixed, save the pose on the CosmeticOffsetProfile with Save Pose. Make Dynamic clears that pose on purpose.

Back to Unity development