Skip to content

Instantly share code, notes, and snippets.

@rondreas
Created March 15, 2021 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondreas/f47ed90159d005f290264191fa522e82 to your computer and use it in GitHub Desktop.
Save rondreas/f47ed90159d005f290264191fa522e82 to your computer and use it in GitHub Desktop.
Example of Timer in Unreal
"""
Start a timer to call the function "hey" every half second.
Have yet to figure out how to kill this...
"""
import unreal
@unreal.uclass()
class MyTimedUtility(unreal.EditorUtilityObject):
@unreal.ufunction(override=True)
def run(self):
self.timer_handle = unreal.SystemLibrary.set_timer(
object = self,
function_name="hey",
time=0.5,
looping=True,
)
@unreal.ufunction()
def hey(self):
print("Hey")
my_timed_utility = MyTimedUtility()
my_timed_utility.run()
@KingMoo1213
Copy link

You can kill the timer using:
unreal.SystemLibrary.clear_and_invalidate_timer_handle

(In this case)
unreal.SystemLibrary.clear_and_invalidate_timer_handle(self.timer_handle)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment