---
title: Multiplay Room State
slug: world-sdk-guide/multiplay-room-state
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-3_eY_aqy3ZYnl0QFBrYaw-20240904-102420.png)

Multiplay Room provides a State property for managing connected player or object location.

State's data definition be managed from the Schema file, which is below the multiplay package.
The onStateChange event is first called when the client successfully establishes a connection to the room, and is afterwards called whenever there are changes to the state data.



## Server API

| **API**            | **Description**                                                                                                                                                                                                                                                                         |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| state.SCHEMA\_NAME | You can access the SCHEMA\_NAME field defined in the schema file with state.<br /><br />You can modify the field value at a request from a client or internal server logic.<br /><br />The changed state is then automatically propagated to the clients using the OnStateChange event. |

:::hint{type="info"}
**📘&#x20;**&#x50;lease refer to the following guide. \[[ZEPETO.Multiplay(Server) API](https://developer.zepeto.me/docs/multiplay-server/classes/ZEPETO_Multiplay.Sandbox#state)]
:::

```typescript
import { Location } from 'ZEPETO.Multiplay.Schema';

export default class extends Sandbox {
 
   ...
   const location: Location = this.state.playerLocation;
   // Handling State.
   ...
}
```

| **API**                            | **Description**                                                                                                                                                                                      |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| room.OnStateChange(State, isFirst) | You can register a state change callback when you join the room.<br /><br />You can receive the state of the entire room for the first time, and only the changed state will be received afterwards. |

## Client API

```typescript
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { Location } from 'ZEPETO.Multiplay.Schema';

export default class SampleClient extends ZepetoScriptBehaviour {

    Start() {
        this.multiplay.RoomJoined += (room: Room) => {
            room.OnStateChange += this.OnStateChange;
        };
    }

    private OnStateChange(state: State, isFirst: boolean) {
        const location: Location = state.playerLocation;
        // Handling player location using updated State.  
    }
}
```



## Define Schema file

Schema is a data structure for defining the current state in the room. Rooms are primarily used to manage player information, player or object locations, etc.

To edit a schema, you can select Project View → MultiplayPackage Asset → schema.json, and then modify the data type to use for the World in the Inspector window.
You can modify the data type to use for the World in the Inspector window.

## STEP 1 : Defining Schema Types

Scheme Types is the Data Structure used in the World. In the Inspector → Schema Types, press the \[+] button and add data.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-Hbuk57mwqKHFvEmG_-Wf0-20240904-102429.gif "4-4-3-1.gif")



## STEP 2 : Add Room State

The Room State is the Property that shows the current status of the World Room, and is expressed in the Schema structure as defined above.

Among the Schema Types, select the typeRoom State that will be used as the current status of the World and set it as the SCHEMA\_NAME.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-2ClXYyRzwj0OspO1NGGm0-20240904-102425.gif)

### Schemas.json Example

```json
{
"State" : {"players" : {"map" : "Player"}},
"Player" : {"sessionId" : "string","zepetoUserId" : "string","transform" : "Transform","state" : "number","subState" : "number"},
"Transform" : {"position" : "Vector3","rotation" : "Vector3"},
"Vector3" : {"x" : "number","y" : "number","z" : "number"}
}
```

