# How to setup a timer in a python script?

**URL:** <https://forums.unrealengine.com/t/how-to-setup-a-timer-in-a-python-script/488355>\
**Category:** Editor Scripting\
**Tags:** Python, timer, unreal-engine, question\
**Created:** [September 3, 2021, 1:03pm UTC](https://forums.unrealengine.com/t/how-to-setup-a-timer-in-a-python-script/488355 "2021-09-03T13:03:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a7883a09](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a7883a09](https://forums.unrealengine.com/u/anonymous_user_a7883a09)\
**Post date:** [September 3, 2021, 1:03pm UTC](https://forums.unrealengine.com/t/how-to-setup-a-timer-in-a-python-script/488355/1 "2021-09-03T13:03:24Z")

</div>

I’m trying to delay the execution of my code in a python script.

```
import unreal

timer_delegate = unreal.TimerDynamicDelegate()

def delayed_action():
    print('Do it!')

timer_delegate.bind_callable(delayed_action)

unreal.SystemLibrary.set_timer_delegate(timer_delegate, time=3, looping=False)

```

For some reason I get:

```
RuntimeWarning: SystemLibrary: No world was found for object (/Engine/Transiernt.TimerDynamicDelegate__PythonCallable_4) passed in to UEngine::GetWorldFromContextObject().

```

What’s the problem? Please, show a correct way to do it.

---

<div class="post-metadata">

**Author:** ![greg700000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@greg700000](https://forums.unrealengine.com/u/greg700000)\
**Post date:** [January 20, 2025, 6:50am UTC](https://forums.unrealengine.com/t/how-to-setup-a-timer-in-a-python-script/488355/2 "2025-01-20T06:50:13Z")

</div>

This aint the best approach but it works (This is for a forever loop).

This is my approach until I understand the python API properly:

```auto
import unreal
from threading import Timer

def hello():
    unreal.log_warning("Hello World")
    # Create a new timer that calls this function again after 5 seconds
    t = Timer(5.0, hello)
    t.start()

# Start the timer for the first time
hello()

```

---

<div class="post-metadata">

**Author:** ![greg700000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@greg700000](https://forums.unrealengine.com/u/greg700000)\
**Post date:** [January 21, 2025, 3:04am UTC](https://forums.unrealengine.com/t/how-to-setup-a-timer-in-a-python-script/488355/3 "2025-01-21T03:04:15Z")

</div>

Forget my previous answer, this is way better [Problems using python with Editor in UE4 - #5 by HenryMa96](https://forums.unrealengine.com/t/problems-using-python-with-editor-in-ue4/244763/5) (as it also point out an issue with my last answer and it also provide a nice link to python doc)
