Design the team logic for a team-based multiplayer mode in Unreal Engine — two or more teams, friendly fire disabled within a team, per-team score, and team-colored nameplates. The server must assign and balance teams; a client must never be able to decide on its own who is an ally or report kills it considers valid. Every client needs to read every player's team so it can color nameplates and run friend/foe checks, so each player's team affiliation must be visible to all clients. A player's team must survive their character dying and respawning, and survive a disconnect/rejoin so they return to the same side. Describe where you store team affiliation and per-team score, who assigns teams, how friend/foe and friendly-fire are resolved, and the trade-offs of your approach.
Store a replicated TeamId on each PlayerState; the GameMode assigns teams server-side. Use GenericTeamId for friend/foe checks, keep per-team scores on GameState, and gate damage and objectives through the server's team comparison.
- ✗Storing team on a non-replicated or client-only object so other clients can't read it
- ✗Letting clients decide friend/foe instead of the server-authoritative team comparison
- ✗Assigning teams outside the GameMode, breaking balance and rejoin logic
- →How would you handle a player rejoining and being placed back on their original team?
- →How would you implement team-only chat and team-colored nameplates?
Key classes
AGameMode— server-only: assignsTeamId, balances rosters, enforces rules.AGameState— replicated to everyone: team scores, match phase, round timer.APlayerState— per player: a replicatedTeamId, stats, name.IGenericTeamAgentInterface— UE's standard interface to query anFGenericTeamIdfrom a Pawn/Controller.
Data model
TeamId lives on PlayerState because PlayerState outlives Pawn respawns and is visible to every client. GameState holds team aggregates. Assignment and balance are solely the GameMode's responsibility.
Data flow
- A player connects →
GameModeassigns aTeamId(balanced by team size). - The
TeamIdis written toPlayerStateand replicated to all clients. - A damage event → the server compares instigator and target
TeamId; friendly fire is blocked by rule. - An objective is captured → the server adds points on
GameState. - Clients read replicated
TeamIds and score for nameplate colors and the scoreboard.
Replication considerations
TeamId on PlayerState is Replicated, so it is visible to everyone for coloring and checks. Friend/foe decisions are made only by the server. GameState replicates the score; GameMode exists only on the server and never replicates. Team chat is filtered on the server by recipients' TeamId.
Designer-facing config
Team count, size, balance rules, and friendly fire are DataAsset fields or GameMode config. Team colors are a DataTable. Spawn points are tagged by team.
Trade-offs
TeamIdonPlayerStatevs. onPawn: onPlayerStateit survives death and rejoin; onPawnit is lost on respawn.- UE's
GenericTeamIdvs. a custom system: the standard integrates with AI perception but is less flexible for complex alliances.