---
title: ScriptableObject
slug: world-sdk-guide/scriptableobject
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

ZepetoScriptableObject supports Unity ScriptableObject. ZepetoScriptableObject is a data container that saves large amounts of data, such as world data settings and character options.

To create a new ZepetoScriptableObject file, click the \[+] icon in the top left corner of the Project panel, or click Assets → Create → ZEPETO → ScriptableObject.

::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-ly1N62ko5k7yD_oi9a2Eg-20240904-102418.png" size="60" width="754" height="630" position="center" showCaption="false"}



The newly created ZepetoScriptableObject needs to be connected by creating scripts with a defined data class.

::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-UBN5P5kclKDUF0wl5s31n-20240904-102418.png" size="68" width="585" height="246" position="center" showCaption="false"}

Make a new ZEPETOScript file, and declare the data you will use as the member variables.

Here are some sample codes that can be used as data.

:::CodeblockTabs
TypeScript

```typescript
import { Vector3, Quaternion } from 'UnityEngine';

export default class PlayerScriptObjectDef {  

    public name: string;
    public hp: number;      
    public position: Vector3;
    public rotation: Vector3;
 }
```
:::



When you link the ZEPETOScript with the defined data class to ZepetoScriptableObjects, you will see those data in the Inspector window, as shown below.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-WxkBAYpAkQIw3rCI1VfT8-20240904-102418.png)



Create a ZEPETOScript file to call data from the ZepetoScriptableObject.

Import the ZepetoScriptableObject from the ZEPETOScript and import the data type you have declared as well.

:::CodeblockTabs
TypeScript

```typescript
import { ZepetoScriptableObject } from 'ZEPETO.Script';
import PlayerScriptObjectDef from './playerDefine/PlayerScriptObjectDef';
```
:::



::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-WoXCJ6ZSrzFbrmoDprSmZ-20240904-102418.png" size="50" width="247" height="98" position="center" showCaption="false"}



Declare the ZepetoScriptableObject’s as properties in the ZEPETOScript.

:::CodeblockTabs
TypeScript

```typescript
public player: ZepetoScriptableObject<PlayerScriptObjectDef>;
public enemy: ZepetoScriptableObject<PlayerScriptObjectDef>;
```
:::



Open the Inspector window in ZEPETOScript assign values for the ZepetoScriptableObject properties, as shown below.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-FlWp-r09qaGr43OQPrc7l-20240904-102418.png)



This sample shows how you can use the ZepetoScriptableObject and access it’s values.

:::CodeblockTabs
TypeScript

```typescript
// Direct access by name
console.log(`play name : ${this.player["name"]}`);
console.log(`play hp : ${this.player["hp"]}`);      
console.log(`play position : (${this.player["position"].x}, ${this.player["position"].y}, ${this.player["position"].z})`);
console.log(`play rotation : (${this.player["rotation"].x}, ${this.player["rotation"].y}, ${this.player["rotation"].z})`);
 
// Generic data call
let monsterState = this.enemy.targetObject;
console.log(`enemy name : ${monsterState.name}`);
console.log(`enemy hp : ${monsterState.hp}`);
console.log(`enemy position : (${monsterState.position.x}, ${monsterState.position.y}, ${monsterState.position.z})`);
console.log(`enemy rotation : (${monsterState.rotation.x}, ${monsterState.rotation.y}, ${monsterState.rotation.z})`);
```
:::



To access a primitive type of member variable, declare it as a generic type or covert it using type casting, like the example shown below.

:::CodeblockTabs
TypeScript

```typescript
// Type casting
let playerPosition = this.player["position"] as Vector3;
console.log(`player position : (x:${playerPosition.x}, y:${playerPosition.y}, z:${playerPosition.z})`);
  
// Generic type can access class member
console.log(`enemy position : (x:${monsterState.position.x}, y:${monsterState.position.y}, z:${monsterState.position.z})`);
```
:::



Check the full code example for ScriptableObject.

:::CodeblockTabs
TypeScript

```typescript
import { Vector3 } from 'UnityEngine';
import { ZepetoScriptBehaviour, ZepetoScriptableObject } from 'ZEPETO.Script';
// Import scriptable object type definition
import PlayerScriptObjectDef from './playerDefine/PlayerScriptObjectDef'; 

export default class ScriptableObjectSample extends ZepetoScriptBehaviour {

    public player: ZepetoScriptableObject;
    // Generic type call
    public enemy: ZepetoScriptableObject<PlayerScriptObjectDef>; 

    Awake() {
        // Direct access by name
        console.log(`play name : ${this.player["name"]}`);
        console.log(`play hp : ${this.player["hp"]}`);
        console.log(`play position : (${this.player["position"].x}, ${this.player["position"].y}, ${this.player["position"].z})`);
        console.log(`play rotation : (${this.player["rotation"].x}, ${this.player["rotation"].y}, ${this.player["rotation"].z})`);

        // Generic data call
        let monsterState = this.enemy.targetObject;
        console.log(`enemy name : ${monsterState.name}`);
        console.log(`enemy hp : ${monsterState.hp}`);
        console.log(`enemy position : (${monsterState.position.x}, ${monsterState.position.y}, ${monsterState.position.z})`);
        console.log(`enemy rotation : (${monsterState.rotation.x}, ${monsterState.rotation.y}, ${monsterState.rotation.z})`);

        // Type casting
        let playerPosition = this.player["position"] as Vector3;
        console.log(`player position : (${playerPosition.x}, ${playerPosition.y}, ${playerPosition.z})`);

        // Generic type can access class member
        console.log(`enemy position : (${monsterState.position.x}, ${monsterState.position.y}, ${monsterState.position.z})`);
    }
}
```
:::

