Respawning Collectible - Getting Agent Type from callback but I need collectible_object_device

Hello! I am creating a level with coins for the player to pick up and I’d like to make it so the coins respawn in a Timer. I’m trying to do so in Verse and so far I have the following code

O

nBegin<override>()<suspends>:void=
    #Get the coins with the Tag
    TaggedTokens := GetCreativeObjectsWithTag(respawn_coin_tag{})
            for (FoundObject: TaggedTokens):
                if (Token := collectible_object_device[FoundObject]):
                    Token.CollectedEvent.Subscribe(RespawnCoin)

#Call an async function to respawn the coins
RespawnCoin(InCoin : agent):void=
        spawn{_RespawnCoin(InCoin)}

#Respawn the coins with an asynch function
_RespawnCoin(CoinToRespawn : agent)<suspends>:void=
        Sleep(10.0)
        if (RespawnedCoin := collectible_object_device[CoinToRespawn]) {
            RespawnedCoin.RespawnForAll()
            Print("Success")
        }
        else {
            Print("Fail")
        }

The issue I’m having right now is that I can get to the _RespawnCoin function but my code is always going to the fail stage. The condition on if (RespawnedCoin := collectible_object_device[CoinToRespawn]) always fails and I cannot call RespawnForAll() on an agent type object

I am new to verse so I don’t fully understand what I could be doing wrong here any help is appreciated

Thank you!

1 Like

Same problem here. The CollectedEvent sends the agents and that’s the reason why you can’t call “.RespawnForAll()”. Any workaround to know which Coin was collected?

If you guys switch to using Await() instead of Subscribe then you’ll be able to pass in the collectible device as an argument and then respawn it within the collection function.

2 Likes