How to wait a second using Sleep

Noticed there was a Sleep(1.0) command but how do I use it in the code to wait one second?

Getting this error in my function below, “This invocation calls a function that has the ‘suspends’ effect, which is not allowed by its context.”

Here’s the code, I’m still learning about the effects but confused how to get it all to work.

    OnAgentExitsVehicle(Player : agent): void= 
        Sleep(1.0)
        Print("OnAgentExitsVehicle")

Ok ended up solving my issue with a spawn to a function. Not sure if it’s the best solution as I had to create another function but it works :sweat_smile:

#in another function and it subscribes to the event
if(set DirtbikeAssignedToPlayer[Player] = DirtbikeGranter):
                DirtbikeGranter.AgentExitsVehicleEvent.Subscribe(OnAgentExitsVehicle)


    RestPlayerToBike(Player: agent, DirbikePlayerWasOn: vehicle_spawner_dirtbike_device)<suspends>:void=
        Print("HI")
        Sleep(1.0)
        DirbikePlayerWasOn.AssignDriver(Player)
        
            

    OnAgentExitsVehicle(Player : agent): void= 
       
        Print("OnAgentExitsVehicle")
        
        if(DirbikePlayerWasOn := DirtbikeAssignedToPlayer[Player]):
            DirbikePlayerWasOn.DestroyVehicle()
            
            spawn {RestPlayerToBike(Player, DirbikePlayerWasOn)}
1 Like

Typically, in Unreal, you’re better off setting a timer that fires an event when the timout in question happens.
You can chain multiple events, one after another, this way, too.
Set timer one second → call first event → first event sets another timer → calls second event.
The main challenge for this is when objects die, the timer must no longer reference those objects.

Came across this issue today, and found the solve with the addition of the <suspends>specifier after the parentheses of my custom function.

Hope this helps another uefn/verse beginner in the future!