# how to call a agent in a ?agent function

**URL:** <https://forums.unrealengine.com/t/how-to-call-a-agent-in-a-agent-function/1608169>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [January 12, 2024, 6:43am UTC](https://forums.unrealengine.com/t/how-to-call-a-agent-in-a-agent-function/1608169 "2024-01-12T06:43:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KingqGrove](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KingqGrove](https://forums.unrealengine.com/u/KingqGrove)\
**Post date:** [January 12, 2024, 6:43am UTC](https://forums.unrealengine.com/t/how-to-call-a-agent-in-a-agent-function/1608169/1 "2024-01-12T06:43:18Z")

</div>

so i tried to spawn a prop with a trigger event which is a ?agent but the spawn prop doesnt work with a ?agent, i tried adding a button i thought i can activate the button with the trigger but i cant, i tried to wrap the function to call a agent type function in a ?agent type function but i cant do it, the code works when i interact with the button

```auto
onTriggerActivatedWrapper(Agent: ?agent): void =
        if(not PlayersMap[Agent]):
            
            Print("Invalid or undefined agent triggered the event.")
        else:
            
            onButtonActivated(Agent)
        
    onButtonActivated(Agent:agent): void =
        if(CP := PlayersMap[Agent]):
            if(CP.Team = 3):
                onTriggerActivated(Agent)

    
              
    onTriggerActivated(Agent: agent): void =
        if (CP := PlayersMap[Agent]):
            if (CP.gold >= CostOfProp):
                    CP.setGoldPerSecond(10)
                    set CP.gold -= CostOfProp  
                    
                    SpawnedProp := SpawnProp(Prop, V3, IdentityRotation())
            else:
                    
                    Print("Not enough gold to purchase the prop.")

```
