CREATE YOUR WORLD
Interacting with Objects

Attaching objects to ZEPETO characters

9min

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

Document image




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.

Example of an Object Prefab
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.

📘 Please refer to the following guide. [Create a ZEPETO Character]



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




  • 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.



Example Script Setting Screen
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.



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.

Document image




  • You can adjust the Position and Rotation of the object appropriately to get the desired look.
Example of Object Prefab configuration
Example of Object Prefab configuration




  • In the Inspector, assign the Neck Pillow object to the Pref Item, and select Neck for the Body Bone.
Example Script Setting Screen
Example Script Setting Screen