@@ -607,6 +607,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
607607 { " set_name" , (PyCFunction)py_ue_set_name, METH_VARARGS, " " },
608608
609609 { " bind_event" , (PyCFunction)py_ue_bind_event, METH_VARARGS, " " },
610+ { " unbind_event" , (PyCFunction)py_ue_unbind_event, METH_VARARGS, " " },
610611 { " delegate_bind_ufunction" , (PyCFunction)py_ue_delegate_bind_ufunction, METH_VARARGS, " " },
611612
612613 { " get_py_proxy" , (PyCFunction)py_ue_get_py_proxy, METH_VARARGS, " " },
@@ -3044,6 +3045,45 @@ PyObject *py_ue_ufunction_call(UFunction *u_function, UObject *u_obj, PyObject *
30443045 Py_RETURN_NONE;
30453046}
30463047
3048+ PyObject *ue_unbind_pyevent (ue_PyUObject *u_obj, FString event_name, PyObject *py_callable, bool fail_on_wrong_property)
3049+ {
3050+ UProperty *u_property = u_obj->ue_object ->GetClass ()->FindPropertyByName (FName (*event_name));
3051+ if (!u_property)
3052+ {
3053+ if (fail_on_wrong_property)
3054+ return PyErr_Format (PyExc_Exception, " unable to find event property %s" , TCHAR_TO_UTF8 (*event_name));
3055+ Py_RETURN_NONE;
3056+ }
3057+
3058+ if (auto casted_prop = Cast<UMulticastDelegateProperty>(u_property))
3059+ {
3060+ UPythonDelegate *py_delegate = FUnrealEnginePythonHouseKeeper::Get ()->FindDelegate (u_obj->ue_object , py_callable);
3061+ if (py_delegate != nullptr )
3062+ {
3063+ FMulticastScriptDelegate multiscript_delegate = casted_prop->GetPropertyValue_InContainer (u_obj->ue_object );
3064+ multiscript_delegate.Remove (py_delegate, FName (" PyFakeCallable" ));
3065+
3066+ // re-assign multicast delegate
3067+ casted_prop->SetPropertyValue_InContainer (u_obj->ue_object , multiscript_delegate);
3068+ }
3069+ }
3070+ else if (auto casted_prop_delegate = Cast<UDelegateProperty>(u_property))
3071+ {
3072+ FScriptDelegate script_delegate = casted_prop_delegate->GetPropertyValue_InContainer (u_obj->ue_object );
3073+ script_delegate.Unbind ();
3074+
3075+ // re-assign multicast delegate
3076+ casted_prop_delegate->SetPropertyValue_InContainer (u_obj->ue_object , script_delegate);
3077+ }
3078+ else
3079+ {
3080+ if (fail_on_wrong_property)
3081+ return PyErr_Format (PyExc_Exception, " property %s is not an event" , TCHAR_TO_UTF8 (*event_name));
3082+ }
3083+
3084+ Py_RETURN_NONE;
3085+ }
3086+
30473087PyObject *ue_bind_pyevent (ue_PyUObject *u_obj, FString event_name, PyObject *py_callable, bool fail_on_wrong_property)
30483088{
30493089
0 commit comments