# How to use TriggeredEvent

**URL:** <https://forums.unrealengine.com/t/how-to-use-triggeredevent/2574151>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, UEFN, fortnite\
**Created:** [June 24, 2025, 6:44pm UTC](https://forums.unrealengine.com/t/how-to-use-triggeredevent/2574151 "2025-06-24T18:44:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hedde\_gedronke](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hedde\_gedronke](https://forums.unrealengine.com/u/Hedde_gedronke)\
**Post date:** [June 24, 2025, 6:44pm UTC](https://forums.unrealengine.com/t/how-to-use-triggeredevent/2574151/1 "2025-06-24T18:44:42Z")

</div>

Hello I am trying to add a way to equip a pet if the player triggers an trigger, (so not by pressing a button) but i do not have enough knowledge in verse to understand what the problem is.

 ![Schermafbeelding 2025-06-24 204147](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/a/f/aaf2aa09d072ad2cb6cdbfe24ce61415657df5c6.png)

```auto

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

agent_data := class:
    var AgentPets : []pet_data = array{}
    var CurrentPetProp : ?creative_prop = false
    
huds_data := class<concrete>:
    @editable
    SuccessHud : hud_message_device = hud_message_device{}
    @editable
    WrongHud : hud_message_device = hud_message_device{}
    @editable
    TriggerHud : trigger_device = trigger_device{}
    @editable
    TriggerSwitch : trigger_device = trigger_device{}

   

pet_data := class<concrete>:
    @editable
    PetName : string = ""
    @editable
    PetPrice : int = 0
    @editable
    ConditionalButton : conditional_button_device = conditional_button_device{}
    @editable
    PetPropAsset : creative_prop_asset = DefaultCreativePropAsset
    @editable
    PetPurchaseButtons : []button_device = array{}
    @editable
    PetEquipButtons : []button_device = array{}

    var HudData : huds_data = huds_data{}
    var MaybeMainDevice : ?pet_system = false

    OnBegin():void=
        for(PetPurchaseButton : PetPurchaseButtons):
            PetPurchaseButton.InteractedWithEvent.Subscribe(OnPurchaseButtonClicked)

        for(PetEquipButton : PetEquipButtons):
            PetEquipButton.InteractedWithEvent.Subscribe(OnEquipButtonClicked)
        HudData.TriggerSwitch.TriggeredEvent.Subscribe(OnTriggerSwitchTriggered)
            
    

    OnPurchaseButtonClicked(Agent:agent):void=
        if(MainDevice := MaybeMainDevice?, AgentDataMap := MainDevice.AgentDataMap[Agent]):
            CanBuy := CheckIfPlayerCanBuy(Agent)
            HaveIt := CheckIfPlayerHavePet(Agent)
            if(HaveIt = false):
                if(CanBuy = true):
                    ConditionalButton.SetItemCountRequired(0, PetPrice)
                    ConditionalButton.Activate(Agent)
                    set AgentDataMap.AgentPets += array{Self}
                    HudData.SuccessHud.Show(Agent)
                    HudData.TriggerHud.Trigger(Agent)
                    EquipPet(Agent)
                else:
                    HudData.WrongHud.Show(Agent)
            else:
                HudData.SuccessHud.Show(Agent)
                EquipPet(Agent)
                
                

    OnEquipButtonClicked(Agent:agent):void=
        HudData.SuccessHud.Show(Agent)
        EquipPet(Agent)    
    OnTriggerSwitchTriggered(MaybeAgent:?agent):void=
        HudData.SuccessHud.Show(Agent)
        EquipPet(Agent) 
    
    CheckIfPlayerCanBuy(Agent:agent):logic=
        AgentGold := ConditionalButton.GetItemCount(Agent, 0)
        if(AgentGold >= PetPrice):
            return true

        return false

    CheckIfPlayerHavePet(Agent:agent):logic=
        if(MainDevice := MaybeMainDevice?, AgentDataMap := MainDevice.AgentDataMap[Agent]):
            for(AgentPet : AgentDataMap.AgentPets):
                if(AgentPet.PetName = PetName):
                    return true
        return false

    
    EquipPet(Agent:agent):void=
        if(MainDevice := MaybeMainDevice?, AgentDataMap := MainDevice.AgentDataMap[Agent]):
            RemovePet(Agent)
            if(FC := Agent.GetFortCharacter[]):
                var PlayerPos : vector3 = FC.GetTransform().Translation
                set PlayerPos.X += 100.0

                if(CreativeProp := SpawnProp(PetPropAsset, PlayerPos, IdentityRotation())(0)?):
                    set AgentDataMap.CurrentPetProp = option{CreativeProp}

    RemovePet(Agent:agent):void=
        if(MainDevice := MaybeMainDevice?, AgentDataMap := MainDevice.AgentDataMap[Agent]):
            if(PetProp := AgentDataMap.CurrentPetProp?):
                PetProp.Dispose()
                set AgentDataMap.CurrentPetProp = false

pet_system := class(creative_device):

    @editable
    PetsData : []pet_data = array{}
    @editable
    HudsData : huds_data = huds_data{}

    var AgentDataMap : [agent]agent_data = map{}

    OnBegin<override>()<suspends>:void=
        for(PetData : PetsData):
            set PetData.HudData = HudsData
            set PetData.MaybeMainDevice = option{Self}
            PetData.OnBegin()

        for(AllPlayers : GetPlayspace().GetPlayers(), Player := player[AllPlayers]):
            OnPlayerJoined(Player)

        GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerJoined)

        spawn{AsyncPetFollow()}

    OnPlayerJoined(Agent:agent):void=
        if:
            not AgentDataMap[Agent]
            set AgentDataMap[Agent] = agent_data{}

    AsyncPetFollow()<suspends>:void=
        FollowDistance : float = 75.0
        WaitDistance : float = 50.0
        SleepTime : float = 0.2

        loop:
            Sleep(0.0)
            for(AllPlayers : GetPlayspace().GetPlayers(), Player := player[AllPlayers], FC := Player.GetFortCharacter[], AgentData := AgentDataMap[Player], PetProp := AgentData.CurrentPetProp?):
                PetLoc : vector3 = PetProp.GetTransform().Translation
                PlayerLoc : vector3 = FC.GetTransform().Translation
                DistanceToPlayer : float = Distance(PetLoc, PlayerLoc)
                PlayerBack : vector3 = FC.GetTransform().Rotation.GetLocalForward() * -1.0
                PlayerRight : vector3 = FC.GetTransform().Rotation.GetLocalRight()

                if(Direction := (PlayerLoc - PetLoc).MakeUnitVector[]):
                    DistanceToTravel : float = DistanceToPlayer - WaitDistance
                    var LocationToTravel : vector3 = PetLoc + (Direction * DistanceToTravel)
                    var NewPos : vector3 = vector3{X:=PlayerLoc.X + (PlayerRight.X * FollowDistance) + (PlayerBack.X * FollowDistance) + 20.0, Y := PlayerLoc.Y + (PlayerRight.Y * FollowDistance) + (PlayerBack.Y * FollowDistance), Z := PlayerLoc.Z - 40.0}

                    PlayerRotation := FC.GetTransform().Rotation

                    spawn{PetProp.MoveTo(NewPos, PlayerRotation, SleepTime)}

```

The TriggerHud is used to turn a switch on and the TriggerSwitch would be used with the switch to equip the pet when player rejoins so that they shouldn’t press the button again.

---

<div class="post-metadata">

**Author:** ![Dee\_Kay\_Bee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dee\_Kay\_Bee](https://forums.unrealengine.com/u/Dee_Kay_Bee)\
**Post date:** [June 25, 2025, 9:31am UTC](https://forums.unrealengine.com/t/how-to-use-triggeredevent/2574151/2 "2025-06-25T09:31:22Z")

</div>

You need to confirm that the optional MaybeAgent is valid and then you need to access the agent from the optional. Once you do this, then you can use that agent as the variable for the functions. eg:

```auto
OnTrggerSwitchTriggered(MaybeAgent : ?Agent): void = 

if (Agent := MaybeAgent?):
    HudData.SeccessHud.Show(Agent)
    EquipPet(Agent)

```

---

<div class="post-metadata">

**Author:** ![ok\_studios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ok\_studios](https://forums.unrealengine.com/u/ok_studios)\
**Post date:** [June 28, 2025, 1:53pm UTC](https://forums.unrealengine.com/t/how-to-use-triggeredevent/2574151/3 "2025-06-28T13:53:46Z")

</div>

Also, I might add, when you are new to Verse, it might be helpful not to rely so much on the colon equal operator. That operator is a shortcut and hides the data type you are working with. In the beginning, it helps to spell out the data type to lessen confusion about what types you are actually working with.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/a/2cacc1b007854b3a37adaaf65502c832a900cbd2.jpeg "Why the Colon Equals Operator May Not Be the Best For Beginning Students of Verse Programming.") ](https://www.youtube.com/watch?v=IM9YiBqrK2A)
