Server Types and How to Choose
The differences between relay, sync, and stateMachine, how to choose, and the development workflow
GS2-Realtime has three server types, depending on what the room’s server does. This page explains which one to choose and what you build after choosing.
Server Types
serverType | What the server does | What you build in the game | Suited for |
|---|---|---|---|
relay | Relays messages to specified players or to everyone | The message format and the handling after receiving it | Games that want to design their own communication freely |
sync | Delivers object state to everyone and manages who can modify it | Prefabs for display and the logic that operates them | Games that want to share positions and state |
stateMachine | In addition to sync, creates and updates objects with the rules you register | Everything in sync, plus rules written in C# or GDScript | Games that want the server to decide enemy behavior, HP, and battle progression |
With stateMachine, the server decides HP calculations and whether an attack is allowed, so a modified client cannot rewrite the results. Even when multiple players operate at the same time, the server processes their operations in order, so everyone sees the same result.
How to Choose
You choose with serverType in the Realtime namespace settings.
- If you only want to deliver your own messages to participants, choose
relay. - If you want to share the positions and state of objects, choose
sync. - If, in addition, you want the server to manage enemy behavior and game progression, choose
stateMachine.
For how to use relay, see Introduction to GS2-Realtime.
stateMachine Development Workflow
| Step | What you build | Page that explains it |
|---|---|---|
| 1. Write the rules | C# or GDScript that spawns enemies, validates operations, and handles the passage of time | Room Definition Reference, Writing Rules in GDScript |
| 2. Generate | The rules (GSL) and the sync schema for Unity / Godot | Generation and Registration |
| 3. Register | Registration with GS2-StateMachine and the Realtime namespace settings | Generation and Registration |
| 4. Display in the game | Prefabs (scenes in Godot), NetworkWorld, and the connection logic | Unity Client, Godot Client |
Rules written in C# or GDScript are converted to GSL and run inside the room. The code you write does not run on the server as is, so there are restrictions on the syntax you can use.
Page Guide
| What you want to do | Page |
|---|---|
Try sync end to end | Tutorial: Sync Player Characters |
Try stateMachine end to end | Tutorial: Build an Enemy Whose HP Is Managed by the Server |
| Move input-driven characters with prediction | Tutorial: Move Characters with Rollback Sync |
| Learn how syncing works (who can modify what, operation results, reconnection) | How Object Sync Works |
| Look up Unity settings and APIs | Unity Client |
| Look up Godot settings and APIs | Godot Client |
| Look up how to write rules and the limits | Room Definition Reference |
| Look up the C# definition format (states, Step, supported syntax) | C# Definition Reference |
| Write rules in GDScript | Writing Rules in GDScript |
| Migrate from Photon (PUN2) | Migration Guide from Photon |