# Execute function every frame (Like in Unity)

**URL:** <https://forums.unrealengine.com/t/execute-function-every-frame-like-in-unity/829048>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 28, 2023, 1:11am UTC](https://forums.unrealengine.com/t/execute-function-every-frame-like-in-unity/829048 "2023-03-28T01:11:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![minatore](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/minatore/32/642918_2.png) [@minatore](https://forums.unrealengine.com/u/minatore)\
**Post date:** [March 28, 2023, 1:11am UTC](https://forums.unrealengine.com/t/execute-function-every-frame-like-in-unity/829048/1 "2023-03-28T01:11:50Z")

</div>

Hi guys. I wanted to create a game that when someone reaches a certain value in the Z axis, something happens.

This is what i did:

```auto

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces}

TestingDevice1 := class(creative_device):

    OnBegin<override>():void=

        ShowText()
                
    ShowText() : void =
        Playspace : fort_playspace = GetPlayspace()
        AllPlayers : []player = Playspace.GetPlayers()

        if(Player: player = AllPlayers[0]):
            if(FortniteCharacter : fort_character = Player.GetFortCharacter[]):
                Transform := FortniteCharacter.GetTransform()
                if(Transform.Translation.Z > 3500.0):
                    Print("Player is over Z: 3500.0")

```

So obvioulsy this runs only when the game is started, but it doesn’t happen every time someone goes at Z: 3500.0. Is there a function like “Update” from Unity to execute instructions every frame? Is there an alternative?

P.S. I’m very noob and english isn’t my first language so I’m sorry for any mistake

---

<div class="post-metadata">

**Author:** ![DiG3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig3/32/1036114_2.png) [@DiG3](https://forums.unrealengine.com/u/DiG3)\
**Post date:** [March 28, 2023, 2:39am UTC](https://forums.unrealengine.com/t/execute-function-every-frame-like-in-unity/829048/2 "2023-03-28T02:39:22Z")

</div>

Hi,  
you can replicate a function that executes every frame with a `loop` that calls `Sleep(0.0)`.  
When you pass `0.0` to `Sleep`, you suspend the coroutine execution until the next simulation frame.

```auto
    Tick()<suspends>:void=
        loop:
            # Your code here.
            Sleep(0.0)
    
    OnBegin<override>()<suspends>:void=
        spawn{Tick()}

```

---

<div class="post-metadata">

**Author:** ![Kamyker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kamyker/32/1194621_2.png) [@Kamyker](https://forums.unrealengine.com/u/Kamyker)\
**Post date:** [March 28, 2023, 7:59am UTC](https://forums.unrealengine.com/t/execute-function-every-frame-like-in-unity/829048/3 "2023-03-28T07:59:21Z")

</div>

Btw, it’s 30 fps (ticks per second). You won’t be able to make smooth movement there.
