Teams and Classes: Organizing a Multiplayer Town

In this lesson you'll learn to

  • βœ“Student can configure teams and classes, use class_selector devices, and read a player's team from Verse.

Student can configure teams and classes, use class_selector devices, and read a player's team from Verse.

πŸ“– Reference & full walkthrough: Teams and Classes: Organizing a Multiplayer Town

🧩 Your capstone piece: Red/Blue plaza teams + Explorer/Builder classes for the town CTF event


Team-Based Games: Assigning Players to Teams in Verse

Have you ever played a game where you choose between being a hunter or a piece of furniture? That's Prop Hunt! For it to work, your island must know who is on which team. In this lesson we'll set up teams in the editor and write Verse that actually reads each player's team using the real Fortnite API.

What you'll learn

  • What a Team is and how UEFN tracks teams.
  • How to reach the team collection from Verse.
  • How to loop over every player and find their team.
  • How to detect when a player joins and welcome them.

How it works

A Team is a label the game gives a group of players β€” like "Hunters" and "Props." In the editor you place Team Settings & Inventory devices (one per team) and Class Selector devices (Verse type: class_and_team_selector_device) so players can pick a role. Those devices route each player onto the correct team.

Verse can then read those assignments. Every playspace has a team collection, reached with GetPlayspace().GetTeamCollection(). From it you can:

  • GetTeams() β€” get the list of all teams.
  • GetTeam[Player] β€” get the team a specific player is on. This is fallible (it can fail), so we call it with [] inside an if and handle failure.
  • GetTeamAttitude[TeamA, TeamB] β€” check if two teams are friendly or hostile.
flowchart TD PJ["Player joins"] --> CS["Class Selector device"] CS -->|"picks Hunter"| TH["Team Settings + Inventory (Red)"] CS -->|"picks Prop"| TP["Team Settings + Inventory (Blue)"] TH --> V["Verse reads GetTeam[Player]"] TP --> V

Let's build it

Place two Team Settings & Inventory devices (Hunters, Props) and a Class Selector in your level. Then drop in this Verse device and, in its Details panel, drag the Class Selector into the ClassSelector slot. It reports each player's team number at startup, welcomes anyone who joins mid-game, and re-reports whenever someone switches teams at the selector.

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# A device that reads team assignments from the playspace's team collection.
team_reporter_device := class(creative_device):

    # Drag your Class Selector device into this slot in the Details panel.
    @editable
    ClassSelector : class_and_team_selector_device = class_and_team_selector_device{}

    OnBegin<override>()<suspends>: void =
        # The team collection knows every team and who belongs to it.
        TeamCollection := GetPlayspace().GetTeamCollection()
        AllTeams := TeamCollection.GetTeams()
        Print("This island has {AllTeams.Length} teams.")

        # Report the current team for everyone already in the match.
        for (Player : GetPlayspace().GetPlayers()):
            ReportTeam(Player, TeamCollection)

        # When someone joins mid-game, welcome them and report their team.
        GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerJoined)

        # When a player switches teams at the Class Selector, re-report.
        ClassSelector.TeamSwitchedEvent.Subscribe(OnTeamSwitched)

    # Handler for new players. Runs each time PlayerAddedEvent fires.
    OnPlayerJoined(NewPlayer: player): void =
        Print("A new player joined the match!")
        ReportTeam(NewPlayer, GetPlayspace().GetTeamCollection())

    # Handler for team switches made at the Class Selector device.
    OnTeamSwitched(Agent: agent): void =
        Print("A player switched teams at the Class Selector!")
        ReportTeam(Agent, GetPlayspace().GetTeamCollection())

    # Look up which team a player is on and print its position in the list.
    # Takes agent (not just player) so team-switch events can reuse it.
    ReportTeam(Agent: agent, Teams: fort_team_collection): void =
        # GetTeam[] is fallible, so we call it inside an if with [] brackets.
        if (PlayerTeam := Teams.GetTeam[Agent]):
            AllTeams := Teams.GetTeams()
            # Find this team's index so we can name it (0 = first team).
            var Index : int = 0
            for (T : AllTeams):
                if (T = PlayerTeam):
                    Print("Player is on team number {Index + 1}.")
                set Index = Index + 1
        else:
            Print("Player is not on any team yet.")

Walk-through:

  1. GetTeamCollection() gives us the object that tracks all teams.
  2. GetTeams() returns the array of teams β€” its .Length tells us how many exist.
  3. GetTeam[Player] is fallible, so it lives inside if (...) with [] brackets; the else handles a player with no team.
  4. We compare each team with = (Verse equality is a single =) to find its index.
  5. PlayerAddedEvent().Subscribe(...) runs OnPlayerJoined whenever someone new enters.
  6. ClassSelector.TeamSwitchedEvent.Subscribe(...) fires whenever a player switches teams at the Class Selector β€” because the device is wired into the @editable slot, Verse can listen to it directly.

Try it yourself

  • Change the welcome Print to name the team ("Welcome, Hunter!") based on the index.
  • Use GetTeamAttitude[TeamA, TeamB] to print whether two players are allies or enemies.
  • Subscribe to PlayerRemovedEvent() and print a goodbye message.
  • Subscribe to the selector's ClassSwitchedEvent too, and print a message when a player picks a new class (not just a new team).

Recap

  • A Team groups players; UEFN tracks teams in a team collection.
  • Reach it with GetPlayspace().GetTeamCollection().
  • GetTeams() lists teams; GetTeam[Player] (fallible, use [] in an if) finds a player's team.
  • PlayerAddedEvent().Subscribe(...) reacts to players joining.
  • Team Settings & Inventory and Class Selector devices in the editor do the actual assigning; Verse reads and reacts.
  • The Class Selector's Verse type is class_and_team_selector_device β€” its TeamSwitchedEvent and ClassSwitchedEvent let your code react to picks.
πŸ”’

Keep going β€” free

You've read the intro. The rest of this lesson is free for members. Sign in to continue and track your progress.

Sign in free to continue this lesson
Pass the quiz above to chart this quest in your Journal.

Sources

/guides/using-teams-and-classes-to-organize-your-game
Source

Biloxi Studios original lesson

Guided course

Add this lesson to your free study plan.

🧭 The Keeper’s log

Quest complete? Chart your next heading from the 🧠 Center Village (Free) expedition.

β›΅ Take me there