MCPcopy Create free account
hub / github.com/20tab/UnrealEnginePython / py_ue_set_timer

Function py_ue_set_timer

Source/UnrealEnginePython/Private/UEPyTimer.cpp:78–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78PyObject *py_ue_set_timer(ue_PyUObject *self, PyObject * args) {
79
80 ue_py_check(self);
81
82 float rate;
83 PyObject *py_callable;
84 PyObject *py_loop = nullptr;
85 float first_delay = -1;
86 if (!PyArg_ParseTuple(args, "fO|Of:set_timer", &rate, &py_callable, &py_loop, &first_delay)) {
87 return NULL;
88 }
89
90 if (!PyCallable_Check(py_callable))
91 return PyErr_Format(PyExc_Exception, "object is not a callable");
92
93 bool loop = false;
94 if (py_loop && PyObject_IsTrue(py_loop))
95 loop = true;
96
97 UWorld *world = ue_get_uworld(self);
98 if (!world)
99 return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
100
101 FTimerDelegate timer_delegate;
102 UPythonDelegate *py_delegate = NewObject<UPythonDelegate>();
103 py_delegate->SetPyCallable(py_callable);
104 // fake UFUNCTION for bypassing checks
105 timer_delegate.BindUFunction(py_delegate, FName("PyFakeCallable"));
106
107 // allow the delegate to not be destroyed
108 py_delegate->AddToRoot();
109 self->python_delegates_gc->push_back(py_delegate);
110
111 FTimerHandle thandle;
112 world->GetTimerManager().SetTimer(thandle, timer_delegate, rate, loop, first_delay);
113
114 ue_PyFTimerHandle *ret = (ue_PyFTimerHandle *)PyObject_New(ue_PyFTimerHandle, &ue_PyFTimerHandleType);
115 if (!ret) {
116 world->GetTimerManager().ClearTimer(thandle);
117 return PyErr_Format(PyExc_Exception, "unable to allocate FTimerHandle python object");
118 }
119 ret->thandle = thandle;
120 ret->py_callable = py_callable;
121 // will be decref'ed on clear
122 Py_INCREF(ret->py_callable);
123 ret->world = world;
124
125 return (PyObject *)ret;
126}
127

Callers

nothing calls this directly

Calls 3

ue_get_uworldFunction · 0.85
FNameClass · 0.50
SetPyCallableMethod · 0.45

Tested by

no test coverage detected