---
title: Attaching objects to ZEPETO characters
slug: world-sdk-guide/attaching-objects-to-zepeto-characters
docTags: 
createdAt: 2024-09-02T08:34:13.134Z
---

Attach an object to a ZEPETO character so that when the character moves, the object moves with it.

::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-RVU1Pj2VnYVimqUgTc6-f-20240904-102420.gif" size="40" width="800" height="648" position="center" showCaption="false"}



## STEP 1 : Prepare an Object Prefab



First, you need to turn your object into Prefab.
Create an object, drag it to the Asset folder and make it a Prefab.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-a1A3QEkz2EOYUKkkmWhU6-20240904-102418.png "Example of an Object Prefab")



## STEP 2 : Script to attach the object to a specific part of the character



- Implement the ZEPETO character creation code in Scene as a default.

:::hint{type="info"}
**📘&#x20;**&#x50;lease refer to the following guide. \[[Create a ZEPETO Character](docId:_K4o-TkIw83Wg_jhy0ISA)]
:::



### STEP 2-1 : Write the script

1\) Create Hierarchy > Create Empty Object and rename it to AttachObject.

2\) Create Project > Create > ZEPETO > TypeScript and rename it to AttachObject.

3\) Write a sample script like below.

```typescript
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { ZepetoCharacter, ZepetoPlayers } from 'ZEPETO.Character.Controller';
import { Transform, Animator, GameObject, HumanBodyBones, Object } from 'UnityEngine';

export default class AttachObject extends ZepetoScriptBehaviour {

    // The object prefab to be attached on the body.
    public prefItem: GameObject;
    // The bone to attach the object to.
    public bodyBone: HumanBodyBones;

    private _localCharacter: ZepetoCharacter;

    Start() {
      
        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
            // Find the local player and set it to _localCharacter.
            this._localCharacter = ZepetoPlayers.instance.LocalPlayer.zepetoPlayer.character;
            // Get the _localCharacter's animator component.
            const animator: Animator = this._localCharacter.ZepetoAnimator;
            // Get the position of the bone to attach the object to.
            const bone: Transform = animator.GetBoneTransform(this.bodyBone);
            // Create the object prefab.
            Object.Instantiate(this.prefItem, bone) as GameObject;
          
        });
    }
}
```



- The script flows as follows:
  - Start()
    - Register the ZepetoPlayers.instance.OnAddedLocalPlayer event listener, which will fire when a local player is added.
    - Set the local player to the \_localCharacter variable.
    - Get the animator component of \_localCharacter, get the location specified in bodyBone, and create the prefab specified in prefItem at that location.



### STEP 2-2 : Setting the Attachment Location in the Inspector

1\) After finishing writing the script, add the script to the AttachObject object.

2\) In the Inspector, assign the Pref Item, Body Bone.

- Pref Item is the object prefab.
- Body Bone is the location where the object will be created.
  - Select LeftHand to make it look like you are holding the object in your hand.



![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-da9YMvrZkYu620CaOeWE0-20240904-102418.png "Example Script Setting Screen")



3\) Press the Play button to run and you will see the ZEPETO character with the object attached to his left hand.



## STEP 3 : Apply



You can attach any object to the desired location of the Body Bone in the same way.

:::hint{type="info"}
**📘 Unity HumanBodyBones**
[https://docs.unity3d.com/ScriptReference/HumanBodyBones.html](https://docs.unity3d.com/ScriptReference/HumanBodyBones.html)
:::



The following is an example of attaching a Neck Pillow object from BuildIt to the character's neck to make it look like the ZEPETO character is wearing a neck pillow.

::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-NvEWim8bsEaTZfU8ZnIWz-20240904-102420.gif" size="58" width="800" height="648" position="center" showCaption="false"}



- You can adjust the Position and Rotation of the object appropriately to get the desired look.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-nQ0DQLTax73xt5ioGw0Hm-20240904-102418.png "Example of Object Prefab configuration")



- In the Inspector, assign the Neck Pillow object to the Pref Item, and select Neck for the Body Bone.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-_Id79tFqG3jX3dvvG1Cjb-20240904-102418.png "Example Script Setting Screen")

