@@ -10,6 +10,8 @@ UPythonComponent::UPythonComponent()
1010 bWantsBeginPlay = true ;
1111 PrimaryComponentTick.bCanEverTick = true ;
1212
13+ PythonTickForceDisabled = false ;
14+
1315 // pre-generate PyUObject (for performance)
1416 ue_get_python_wrapper (this );
1517}
@@ -22,16 +24,6 @@ void UPythonComponent::BeginPlay()
2224
2325 // ...
2426
25- const TCHAR *blob = *PythonCode;
26-
27- int ret = PyRun_SimpleString (TCHAR_TO_UTF8 (blob));
28-
29- UE_LOG (LogPython, Warning, TEXT (" Python ret = %d" ), ret);
30-
31- if (ret) {
32- unreal_engine_py_log_error ();
33- }
34-
3527 if (PythonModule.IsEmpty ())
3628 return ;
3729
@@ -42,7 +34,7 @@ void UPythonComponent::BeginPlay()
4234 }
4335
4436#if WITH_EDITOR
45- // todo implement autoreload with a dictionary of mule timestamps
37+ // todo implement autoreload with a dictionary of module timestamps
4638 py_component_module = PyImport_ReloadModule (py_component_module);
4739 if (!py_component_module) {
4840 unreal_engine_py_log_error ();
@@ -76,6 +68,15 @@ void UPythonComponent::BeginPlay()
7668 UE_LOG (LogPython, Error, TEXT (" Unable to set 'uobject' field in component wrapper class" ));
7769 }
7870
71+ // disable ticking if no tick method is exposed
72+ if (!PyObject_HasAttrString (py_component_instance, " tick" ) || PythonTickForceDisabled) {
73+ SetComponentTickEnabled (false );
74+ }
75+
76+ if (!PyObject_HasAttrString (py_component_instance, " begin_play" )) {
77+ return ;
78+ }
79+
7980 PyObject *bp_ret = PyObject_CallMethod (py_component_instance, " begin_play" , NULL );
8081 if (!bp_ret) {
8182 unreal_engine_py_log_error ();
@@ -93,6 +94,8 @@ void UPythonComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
9394 if (!py_component_instance)
9495 return ;
9596
97+ // no need to check for method availability, we did it in begin_play
98+
9699 PyObject *ret = PyObject_CallMethod (py_component_instance, " tick" , " f" , DeltaTime);
97100 if (!ret) {
98101 unreal_engine_py_log_error ();
0 commit comments