Verse Libraryverse

02 3 Spawning The Device

Dynamically spawns a campfire prop device at the current location of every player shortly after the game begins.

extracted-snippets/community/learning/tutorials/vv19/fortnite-spawn-devices-dynamically-using-verse-and-a-bit-of-cursed-tricks/02-3-spawning-the-device.verse

# Source URL: https://dev.epicgames.com/community/learning/tutorials/vv19/fortnite-spawn-devices-dynamically-using-verse-and-a-bit-of-cursed-tricks
# Local doc:  epic-docs/community/learning/tutorials/vv19/fortnite-spawn-devices-dynamically-using-verse-and-a-bit-of-cursed-tricks.md
# Section:    3. Spawning the device
using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }

# The device that spawns... campfire devices.
campfire_spawner := class(creative_device):

    # Contains the campfire prop-device we've created (BP_MyCampfireDevice)
    @editable
    CampfireProp<public>: creative_prop_asset = DefaultCreativePropAsset

    # Spawns the campfire device at the desired location
    SpawnCampfire(Position:vector3):void=
        SpawnProp(CampfireProp, Position, IdentityRotation())

    # At the start of the game, spawn a campfire device for each player
    OnBegin<override>()<suspends>:void=
        Sleep(5.0) # Wait so we let the player move to see if it really works
        # Spawn a campfire for each player
        for (Player : GetPlayspace().GetPlayers()):
            if (Char := Player.GetFortCharacter[]):
                SpawnCampfire(Char.GetTransform().Translation)

Comments

    Sign in to vote, comment, or suggest an edit.Sign in