GetPlayspace

method
(CreativeObject: creative_object_interface).GetPlayspace<native><public>()<transacts>: fort_playspace

Returns the `fort_playspace` that `CreativeObject` belongs to.

Module
/Fortnite.com/Devices
Declared in
Devices
Source
fortnite

Used in

# INITIALIZATION: This runs ONCE when the island starts.
    # Think of this as the "Pre-Game Lobby" setup.
    # OnBegin is the real entry-point for creative_device subclasses.
    OnBegin<override>()<suspends> : void =
        # Subscribe to the game's elimination event through the experience.
        # GetPlayspace() returns the current fort_playspace, which exposes
        # PlayerRemovedEvent — fired whenever a player is eliminated or leaves.
        # note: UEFN does not expose a single global OnElimination event;
        # PlayerRemovedEvent on the playspace is the closest real equivalent
        # for reacting to a player leaving active play.
        Playspace := GetPlayspace()
        Playspace.PlayerRemovedEvent().Subscribe(OnPlayerRemoved)

    # EVENT: This is the "Elimination" listener.
    # The game fires this event when a player is removed from the playspace.
    OnPlayerRemoved(RemovedPlayer : player) : void =
        # LOGIC: Who died? Where should they go?
        # For simplicity, send every removed player to SpawnPad1 and
        # trigger the flash sequence so they know they are ready to go.
        # In a real game, you would track per-player state for richer logic!

        # Respawn the player at SpawnPad1.
        # player_spawner_device.Activate() respawns the player
        # the next time that spawn pad is used; to force immediate
        # teleport we move the player to the pad's transform.
        # note: player does not expose Set_location directly; we use
        # TeleportTo on the fort_character wrapped in a guard check.
        if (FortCharacter := RemovedPlayer.GetFortCharacter[]):
            PadTransform := SpawnPad1.GetTransform()
            if (FortCharacter.TeleportTo[PadTransform.Translation, PadTransform.Rotation]):
                false

        # Make the light flash by playing the cinematic sequence!
        # The sequence should be set up in the editor to flash your
        # chosen light from red back to off over ~1 second.
        FlashSequence.Play()
# OnBegin is the "Action!" command.
    # It runs automatically when the player spawns into the island.
    # The <suspends> tag means this function can pause and wait for things (like players) to happen.
    OnBegin<override>()<suspends> : void =
        # First, we need to find the player.
        # GetPlayspace().GetPlayers() returns all current players.
        # We grab the first one if available.
        Players := GetPlayspace().GetPlayers()
        if (ValidPlayer := Players[0]):
            
            # If we found a player, let's start the show!
            # Tell the timer to start ticking for this player.
            # This is the moment the UI pops up on the player's screen.
            MyTimer.Start(ValidPlayer)
            
            # Optional: Print a message to the debug log so you know it worked.
            Logger.Print("Countdown has started! Good luck, soldier.")
            
        else:
            # If no player is found, log an error.
            # This shouldn't happen in normal gameplay, but it's good to know if something is broken.
            Logger.Print("Error: No player found to start the countdown!", ?Level := log_level.Error)
var KillerAgent : ?agent = false

    # 3. The "OnBegin" Event.
    # This function runs exactly once when the match starts.
    OnBegin<override>()<suspends> : void =
        # Get all players currently in the game via the fort_playspace.
        # GetPlayspace() returns the active playspace for this island.
        Playspace := GetPlayspace()
        AllPlayers := Playspace.GetPlayers()

        # Check if there are any players.
        if (AllPlayers.Length > 0):
            # Store the first player's agent reference in our variable.
            # AllPlayers[0] returns an ?agent (optional), so we unwrap it with 'if'.
            if (FirstPlayer := AllPlayers[0]):
                set KillerAgent = option{FirstPlayer}

                # Print a message to the debug log (Output Log in UEFN).
                # This confirms OnBegin ran successfully.
                Print("Match Started! Targeting a player.")

                # Arm the trap: tell the Anvil prop mover to activate.
                # Enable() makes the prop mover start its movement sequence.
                Anvil.Enable()
                Print("Anvil Armed! Waiting for target...")
        else:
            Print("No players found. Trap remains dormant.")
OnStartTimerFinished(InAgent : agent) : void =
        # When the timer ends, we check who is in the game.
        Players := GetPlayspace().GetPlayers()
        for (Player : Players):
            # Get the player's display name and measure its length.
            Name := Player.GetDisplayName[]
            NameLength := Name.Length

            # SIMULATE ROUND LOGIC:
            # For this demo, if the player's name has an even number of letters,
            # they lose Round 1. (Just a fun, random way to pick a loser.)
            IsLoser : logic = if (Mod[NameLength, 2] = 0) then true else false

            # UPDATE THE MAP:
            # If they are a loser, set their status to true. Otherwise, false.
            if (IsLoser):
                set PlayerStatus[Player] = true
            else:
                set PlayerStatus[Player] = false

            # APPLY THE HANDICAP FOR NEXT ROUND:
            # We immediately toggle the cinematic sequence to show who "lost".
            if (PlayerStatus[Player]):
                # If True, play the sequence (e.g. sequence drives a red light ON)
                HandicapLight.Play()
            else:
                # If False, stop the sequence (light OFF / normal state)
                HandicapLight.Stop()
stealth_trigger: trigger_device = trigger_device{}

    # This function runs when the actor is created (when the map loads).
    OnBegin<override>()<suspends>: void =
        # 1. Get the HUD Controller.
        # This is like finding the main breaker box for the screen.
        HudController := GetPlayspace().GetHUDController()
        
        # 2. Identify the Build Menu.
        # This is the specific "name tag" for the build menu UI element.
        BuildMenuId := creative_hud_identifier_build_menu{}
        
        # 3. Listen for the trigger.
        # When someone enters the box, we hide the menu.
        # When they leave, we show it.
        stealth_trigger.TriggeredEvent.Subscribe(OnTriggered)
welcome_message_device := class(creative_device):

    # This runs once when the island loads.
    OnBegin<override>()<suspends> : void =
        # 1. Get the player's screen (The Player UI).
        # We find the first player in the game.
        # GetPlayspace() returns all active players on this island.
        Players := GetPlayspace().GetPlayers()

        # Guard against an empty lobby before continuing.
        if (Player := Players[0], FortPlayer := player[Player], PlayerUI := GetPlayerUI[FortPlayer]):

            # 3. Create a new text_block Widget.
            # This is our "sticker" with text.
            MyText := text_block:
                DefaultText := StringToMessage("Welcome to my Island!")

            # 4. Add the widget to the player's UI.
            # This makes it appear on screen!
            # slot controls layer order; use default_z_order (0) here.
            PlayerUI.AddWidget(MyText, player_ui_slot{ZOrder := 0})

            # 5. Wait for 3 seconds.
            # The game pauses here for a moment.
            Sleep(3.0)

            # 6. Remove the widget from the UI.
            # This makes the sticker disappear.
            PlayerUI.RemoveWidget(MyText)
HealingAppleScript()<suspends> : void =
        # We find all players on the island.
        # GetPlayspace gives us the current game session.
        # GetPlayers gives us everyone in it.
        Players := GetPlayspace().GetPlayers()

        # We check if there are any players.
        if (Players.Length > 0):
            # We pick the first player we find.
            # In a real game, you might loop through all of them.
            if (Player := Players[0]):
                # We tell the device to give an Apple to the player.
                # SpawnItemForPlayer gives the item directly to that player.
                # The Apple heals 5 health points when eaten.
                AppleDevice.SpawnItemForPlayer(Player)

        # We wait a little bit.
        # Then we try again later.
        # This makes it a loop!
        Sleep(5.0)
        HealingAppleScript()
# OnBegin is the built-in Verse lifecycle function that runs when the
    # creative_device starts. It's like hitting "Start" on the console.
    OnBegin<override>()<suspends> : void =
        # 1. Get all current players in the game.
        # This is like the lobby populating with players.
        Players := GetPlayspace().GetPlayers()

        # 2. We need to match each player to a Player Reference.
        # Imagine you have 4 Player References bound via @editable above.
        # We'll loop through them and assign each player by index.
        #
        # Think of it like assigning seat numbers in a classroom.
        # Player A gets Seat 1, Player B gets Seat 2, etc.
        InitializePlayerLinks(Players)

        # 3. Subscribe to the elimination event on the playspace so we
        # know whenever someone is knocked out.
        GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)

    # This function links players to their respective Player Reference devices.
    InitializePlayerLinks(Players : []player) : void =
        # Loop through each Player Reference slot we have available.
        for (Index -> Ref : PlayerRefs):
            # Guard: only assign if a player exists at this index.
            if (Player := Players[Index]):
                # Register this player with their assigned reference device.
                # Register tells the Player Reference device which player
                # it is responsible for tracking.
                Ref.Register(Player)
                # Note: Register is the real API on player_reference_device
                # for assigning a player at runtime in UEFN Verse.

    # This function is called when a player leaves the playspace
    # (which includes being eliminated in most game modes).
    # It's triggered by the PlayerRemovedEvent subscription above.
    OnPlayerRemoved(RemovedPlayer : player) : void =
        # Walk through every Player Reference device we have.
        for (Ref : PlayerRefs):
            # GetAgent() returns an ?agent — the agent currently
BuildToolGiver := class(creative_device):

    # This runs once when the island starts.
    OnBegin<override>()<suspends>: void =
        # Get the playspace so we can find players.
        Playspace := GetPlayspace()

        # Wait until at least one player is present.
        Players := Playspace.GetPlayers()
        if (Players.Length = 0):
            return

        # Find the player who started the game.
        Player := Players[0]

        # A fort_character is needed to access inventory components.
        # GetFortCharacter[] is a failable expression, so we use 'if'.
        if (FortCharacter := Player.GetFortCharacter[]):

            # We need to talk to the player's build hotbar.
            # This gets the special "sleeve" for building tools.
            # GetInventoryComponent[] is failable, so we use 'if'.
            if (BuildHotbar := FortCharacter.GetInventoryComponent[fort_inventory_build_hotbar_component]):

                # Now let's add some building materials!
                # We use AddItem to put items in the hotbar.

                # Add 100 Wood
                # note: wood_item_definition is the asset tag for the Wood resource in UEFN's Content Browser.
                BuildHotbar.AddItem(WoodItemDefinition, 100)

                # Add 100 Stone
                # note: stone_item_definition is the asset tag for the Stone resource in UEFN's Content Browser.
                BuildHotbar.AddItem(StoneItemDefinition, 100)

                # Add 100 Metal
                # note: metal_item_definition is the asset tag for the Metal resource in UEFN's Content Browser.
                BuildHotbar.AddItem(MetalItemDefinition, 100)

                Print("Player got their build tools!")
PlayerAvatarDevice := class(creative_device):

    # This function runs when the game starts.
    OnBegin<override>()<suspends>: void =
        # Get all players currently on the island.
        AllPlayers := GetPlayspace().GetPlayers()

        # Loop over every player and show their avatar UI.
        for (Player : AllPlayers):
            ShowAvatarUI(Player)

        Print("Avatar shown!")

    # Helper function: build and display the avatar widget for one player.
    ShowAvatarUI(Player : player): void =
        # GetFortCharacter[] fails if the player has no character yet,
        # so we use 'if' to safely unwrap the optional result.
        if (FortChar := Player.GetFortCharacter[]):
            # Create a simple text widget as a stand-in for the avatar icon.
            # note: Verse has no built-in PlayerAvatarIcon widget at runtime;
            # the real avatar image binding is done in the UEFN Widget Editor
            # using the HUDPlayerInfoViewModel Brush binding (see tutorial body).
            AvatarLabel := text_block:
                DefaultText := "Avatar: {FortChar.GetDisplayName()}"
                # note: GetDisplayName() returns the player's display name string.

            # Wrap the label in a canvas so it can be positioned on screen.
            AvatarCanvas := canvas:
                Slots := array:
                    canvas_slot:
                        Widget := AvatarLabel
                        Anchors := anchors:
                            Minimum := vector2{X := 0.05, Y := 0.05}
                            Maximum := vector2{X := 0.05, Y := 0.05}
                        Offsets := margin{Top := 0.0, Left := 0.0,
                                          Bottom := 0.0, Right := 0.0}
                        Alignment := vector2{X := 0.0, Y := 0.0}
                        SizeToContent := true

            # Add the widget to this specific player's HUD.