Skip to content

Multiplayer

namespace Griff.Scenes;
public sealed class Multiplayer : Component

Makes the scene a multiplayer game. Put it on any entity (a “Game” entity is tidy). Host one with a Host Game button or Game.Network.Host(), and others join with Join Game or Game.Network.Join("192.168.1.5"); in the editor, Play with Players starts several at once. The host runs the game; everyone sees the same world. Each player gets their own copy of the Player entity, at a PlayerSpawn, moved by their own keys or controller, and Griff’s components (movement, weapons, attacks, health, pickups, building, strategy orders) work for every player. Cameras, the HUD and menus stay on each machine and follow that player’s own character.

This is a component: its saved properties are on its component page.

public bool ColorPlayers { get; set; }

Paint each player’s character their own color (their team’s, in a team game) so everyone can tell them apart: its sprite, or the sprites with a Team Color if it has any.

public string? ExitScene { get; set; }

The scene to go back to when the connection to the host is lost or the host leaves, e.g. “Menu”. Empty restarts this one.

public bool FriendlyFire { get; set; }

Players on the same team can hurt each other.

public int MaxPlayers { get; set; }

The most players in one game, the host included.

public string? Player { get; set; }

The entity each player plays as: one in the scene (the host plays that one, everyone else a copy) or a prefab. Empty gives players no character, as in a strategy game where each player commands a Faction.

public int Port { get; set; }

The network port the host listens on. Joining players use it too unless their address names another.

public bool RememberPlayers { get; set; }

Keep each player’s character as they left it (where it was, its health, inventory and score) and give it back when someone with the same name joins again, even in a later game: for persistent worlds.

public bool ScoreKills { get; set; }

A point for the player who lands the blow that defeats another player’s character.

public float SendRate { get; set; }

How many times a second the host sends what changed. More is smoother, and uses more of the connection.

public float Smoothing { get; set; }

Seconds other players and moving things are shown behind the host, so they glide smoothly between updates instead of jumping. Your own character never waits: you move it yourself.

public string? Teams { get; set; }

Team names, e.g. “Blue, Red”, for team games: players join the team with the fewest, play at a spawn for their team, and can’t hurt each other unless FriendlyFire is on. In a strategy game they’re the Faction teams players take: “Player, Enemy”. Empty is everyone for themselves.

public float ViewDistance { get; set; }

How far from a player’s character (or camera) things are sent to them, in world units: for a big world with many players, like an MMO. 0 sends everything. Things with no picture (a score keeper) and tilemaps always go.

public const int DefaultPort

The port a game is hosted on unless something says otherwise.