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

serverTypeWhat the server doesWhat you build in the gameSuited for
relayRelays messages to specified players or to everyoneThe message format and the handling after receiving itGames that want to design their own communication freely
syncDelivers object state to everyone and manages who can modify itPrefabs for display and the logic that operates themGames that want to share positions and state
stateMachineIn addition to sync, creates and updates objects with the rules you registerEverything in sync, plus rules written in C# or GDScriptGames 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

StepWhat you buildPage that explains it
1. Write the rulesC# or GDScript that spawns enemies, validates operations, and handles the passage of timeRoom Definition Reference, Writing Rules in GDScript
2. GenerateThe rules (GSL) and the sync schema for Unity / GodotGeneration and Registration
3. RegisterRegistration with GS2-StateMachine and the Realtime namespace settingsGeneration and Registration
4. Display in the gamePrefabs (scenes in Godot), NetworkWorld, and the connection logicUnity 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 doPage
Try sync end to endTutorial: Sync Player Characters
Try stateMachine end to endTutorial: Build an Enemy Whose HP Is Managed by the Server
Move input-driven characters with predictionTutorial: 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 APIsUnity Client
Look up Godot settings and APIsGodot Client
Look up how to write rules and the limitsRoom Definition Reference
Look up the C# definition format (states, Step, supported syntax)C# Definition Reference
Write rules in GDScriptWriting Rules in GDScript
Migrate from Photon (PUN2)Migration Guide from Photon