Skip to content

Commit 24aea14

Browse files
author
Roberto De Ioris
committed
added CallPythonComponentMethodObject
1 parent 513b42e commit 24aea14

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎Source/UnrealEnginePython/Public/PythonComponent.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,40 @@ FString UPythonComponent::CallPythonComponentMethodString(FString method_name, F
371371
return ret_fstring;
372372
}
373373

374+
UObject *UPythonComponent::CallPythonComponentMethodObject(FString method_name, UObject *arg)
375+
{
376+
if (!py_component_instance)
377+
return nullptr;
378+
379+
FScopePythonGIL gil;
380+
381+
PyObject *ret = nullptr;
382+
if (!arg) {
383+
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), NULL);
384+
}
385+
else {
386+
PyObject *py_uobject = (PyObject *)ue_get_python_wrapper(arg);
387+
if (!py_uobject) {
388+
unreal_engine_py_log_error();
389+
return nullptr;
390+
}
391+
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), (char *)"O", py_uobject);
392+
}
393+
394+
if (!ret) {
395+
unreal_engine_py_log_error();
396+
return nullptr;
397+
}
398+
399+
if (ue_is_pyuobject(ret)) {
400+
ue_PyUObject *py_obj = (ue_PyUObject *)ret;
401+
return py_obj->ue_object;
402+
}
403+
return nullptr;
404+
}
405+
406+
407+
374408
void UPythonComponent::CallPythonComponentMethodStringArray(FString method_name, FString args, TArray<FString> &output_strings)
375409
{
376410
if (!py_component_instance)

‎Source/UnrealEnginePython/Public/PythonComponent.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class UPythonComponent : public UActorComponent
5555
UFUNCTION(BlueprintCallable, Category = "Python")
5656
int CallPythonComponentMethodInt(FString method_name, FString args);
5757

58+
UFUNCTION(BlueprintCallable, Category = "Python")
59+
UObject *CallPythonComponentMethodObject(FString method_name, UObject *arg);
60+
5861
UFUNCTION(BlueprintCallable, Category = "Python")
5962
void SetPythonAttrInt(FString attr, int Integer);
6063

0 commit comments

Comments
 (0)