Download

how to enable delay in python script instead of time.sleep(t)

Hi , I would like to call a function after specific duration. My python script runs at start of project.
The need is that I need to call some functions once a file has been created at specific location. All of this during editor time, not during gameplay.

ex:
filename-> dataConfig.ini
location-> content/dataConfig.ini

lets say the solution would be:
print(“function has started”)
after the file has been created by external program
then print(“file has been created”)

But, python in unreal pauses for the duration and then resumes. I dont want unreal to pause.
/////////////////////////////////////
import time

print " at 0 seconds"
time.sleep(5)
print “after 5 seconds”
//////////////////////////////////////////

another approach i tried was to use threading . This doesnt work either.

//////////////////////////////////////////
import threading

def testFunc():
print “function started”
t=threading.Timer(5.0,testFunc)
t.start()
//////////////////////////////////////////

I’m using PySide which is a Qt framework Python bindings.
It offer a QTimer class which you can implement the singleShot method.

//////////////////////////////////////////

import unreal
from PySide import QtCore
QtCore.QTimer.singleShot(1000,lambda:unreal.log(‘hello,world’))

//////////////////////////////////////////

Unlike using time.sleep , it would not freeze the unreal engine.