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

Function py_ue_bind_axis

Source/UnrealEnginePython/Private/UEPyInput.cpp:377–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375}
376
377PyObject *py_ue_bind_axis(ue_PyUObject *self, PyObject * args) {
378
379 ue_py_check(self);
380
381 char *axis_name;
382 PyObject *py_callable;
383 if (!PyArg_ParseTuple(args, "sO:bind_action", &axis_name, &py_callable)) {
384 return NULL;
385 }
386
387 if (!PyCallable_Check(py_callable)) {
388 return PyErr_Format(PyExc_Exception, "object is not a callable");
389 }
390
391 UInputComponent *input = nullptr;
392
393 if (self->ue_object->IsA<AActor>()) {
394 input = ((AActor *)self->ue_object)->InputComponent;
395 }
396 else if (self->ue_object->IsA<UActorComponent>()) {
397 input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent;
398 }
399 else {
400 return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
401 }
402
403 if (!input) {
404 return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
405 }
406
407 UPythonDelegate *py_delegate = NewObject<UPythonDelegate>();
408 py_delegate->SetPyCallable(py_callable);
409 py_delegate->AddToRoot();
410
411 // allow the delegate to not be destroyed
412 self->python_delegates_gc->push_back(py_delegate);
413
414 FInputAxisBinding input_axis_binding(FName(UTF8_TO_TCHAR(axis_name)));
415 input_axis_binding.AxisDelegate.BindDelegate(py_delegate, &UPythonDelegate::PyInputAxisHandler);
416 input->AxisBindings.Add(input_axis_binding);
417
418 Py_INCREF(Py_None);
419 return Py_None;
420
421}
422
423PyObject *py_ue_bind_key(ue_PyUObject *self, PyObject * args) {
424

Callers

nothing calls this directly

Calls 2

FNameClass · 0.50
SetPyCallableMethod · 0.45

Tested by

no test coverage detected