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 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 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 \[ creating 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 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 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 📘 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 you can adjust the position and rotation of the object appropriately to get the desired look in the inspector, assign the neck pillow object to the pref item, and select neck for the body bone