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#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

StepWhat you buildPage that explains it
1. Write the rulesC# that spawns enemies, validates operations, and handles the passage of timeRoom Definition Reference
2. GenerateThe rules (GSL) and the sync schema for UnityGeneration and Registration
3. RegisterRegistration with GS2-StateMachine and the Realtime namespace settingsGeneration and Registration
4. Display in UnityPrefabs, NetworkWorld, and the connection logicUnity Client

Rules written in C# are converted to GSL and run inside the room. The C# code itself does not run on the server, so there are restrictions on the C# you can use.

Page Guide

What you want to doPage
Try everything end to end firstTutorial: Build an Enemy Whose HP Is Managed by the Server
Look up Unity settings and APIsUnity 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
Migrate from Photon (PUN2)Migration Guide from Photon