Skip to content

Commit f72b079

Browse files
author
Roberto De Ioris
committed
added args to PyActor blueprint methods
1 parent 8e74245 commit f72b079

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Roberto De Ioris ([email protected])

Source/UnrealEnginePython/Public/PyActor.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,38 @@ void APyActor::PyOnActorClicked(AActor *touched_actor, FKey button_pressed)
157157
Py_DECREF(ret);
158158
}
159159

160-
void APyActor::CallPythonActorMethod(FString method_name)
160+
void APyActor::CallPythonActorMethod(FString method_name, FString args)
161161
{
162162
if (!py_actor_instance)
163163
return;
164164

165-
PyObject *ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
165+
PyObject *ret = nullptr;
166+
if (args.IsEmpty()) {
167+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
168+
}
169+
else {
170+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
171+
}
172+
166173
if (!ret) {
167174
unreal_engine_py_log_error();
168175
return;
169176
}
170177
Py_DECREF(ret);
171178
}
172179

173-
bool APyActor::CallPythonActorMethodBool(FString method_name)
180+
bool APyActor::CallPythonActorMethodBool(FString method_name, FString args)
174181
{
175182
if (!py_actor_instance)
176183
return false;
177184

178-
PyObject *ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
185+
PyObject *ret = nullptr;
186+
if (args.IsEmpty()) {
187+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
188+
}
189+
else {
190+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
191+
}
179192
if (!ret) {
180193
unreal_engine_py_log_error();
181194
return false;
@@ -190,12 +203,18 @@ bool APyActor::CallPythonActorMethodBool(FString method_name)
190203
return false;
191204
}
192205

193-
FString APyActor::CallPythonActorMethodString(FString method_name)
206+
FString APyActor::CallPythonActorMethodString(FString method_name, FString args)
194207
{
195208
if (!py_actor_instance)
196209
return FString();
197210

198-
PyObject *ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
211+
PyObject *ret = nullptr;
212+
if (args.IsEmpty()) {
213+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
214+
}
215+
else {
216+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
217+
}
199218
if (!ret) {
200219
unreal_engine_py_log_error();
201220
return FString();

Source/UnrealEnginePython/Public/PyActor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class APyActor : public AActor
3333
FString PythonClass;
3434

3535
UFUNCTION(BlueprintCallable, Category = "Python")
36-
void CallPythonActorMethod(FString method_name);
36+
void CallPythonActorMethod(FString method_name, FString args);
3737

3838
UFUNCTION(BlueprintCallable, Category = "Python")
39-
bool CallPythonActorMethodBool(FString method_name);
39+
bool CallPythonActorMethodBool(FString method_name, FString args);
4040

4141
UFUNCTION(BlueprintCallable, Category = "Python")
42-
FString CallPythonActorMethodString(FString method_name);
42+
FString CallPythonActorMethodString(FString method_name, FString args);
4343

4444
private:
4545
PyObject *py_actor_instance;

0 commit comments

Comments
 (0)