Skip to content

Commit

Permalink
update threading script to allow passback of data
Browse files Browse the repository at this point in the history
  • Loading branch information
getnamo committed Oct 22, 2018
1 parent 6cdf958 commit 9bc8c59
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Content/Scripts/upythread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@
#internal, don't call directly
def backgroundAction(args=None):
#ue.log(args)

action = args[0]
actionArgs = None

if len(args) >1:
callback = args[1]
actionArgs = args[1]

if len(args) >2:
callback = args[2]

#call the blocking action
result = action()
if actionArgs:
result = action(actionArgs)
else:
result = action()

#return the result if we have a callback
if callback:
if result is not None:
if result:
ue.run_on_gt(callback, result)
else:
ue.run_on_gt(callback)

#run function on a background thread, optional callback when complete on game thread
def run_on_bt(actionfunction, callback=None):
t = Thread(target=backgroundAction, args=([actionfunction, callback],))
def run_on_bt(actionfunction, functionArgs=None, callback=None):
t = Thread(target=backgroundAction, args=([actionfunction, functionArgs, callback],))
t.start()

0 comments on commit 9bc8c59

Please sign in to comment.