Once the trigger is activated, I want to retrieve the item from the item granter.

I want to make a player retrieve the item from the item granter once the trigger is activated.
But the trigger event needs a ?agent and the item granter needs an agent, and I can’t pass arguments to the function properly.
How can I do this?
The code is as follows.
Thank you in advance for your help.

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

sample_granter_device := class(creative_device):

@editable
ItemGranter:item_granter_device=item_granter_device{}

@editable
PlayerSpawners:[]player_spawner_device = array{}

@editable
Trigger:trigger_device = trigger_device{}

OnBegin<override>()<suspends>:void=
    Players := GetPlayspace().GetPlayers()
    for (Player : Players):
        Trigger.TriggeredEvent.Subscribe(ItemGrant)

ItemGrant(Player:agent):void = 
    ItemGranter.GrantItem(Player)

You need to change the argument type for Player from agent to ?agent.

ItemGrant(Player:?agent):void = 

You will then need to check the ?agent is valid, with something like:

ItemGrant(Player:?agent):void = 
   if(Checked_Player := Agent?):
       ItemGranter.GrantItem(Checked_Player)

More info on Optional:

1 Like

Thank you very much!
I read the page about Optional!
I’m very happy to learn about weak_map too!
I had a great time! Thanks for answering my question!