@@ -15,7 +15,7 @@ UPythonComponent::UPythonComponent()
1515 PythonTickForceDisabled = false ;
1616 PythonDisableAutoBinding = false ;
1717
18-
18+ bWantsInitializeComponent = true ;
1919}
2020
2121void UPythonComponent::InitializePythonComponent () {
@@ -77,26 +77,44 @@ void UPythonComponent::InitializePythonComponent() {
7777
7878 ue_bind_events_for_py_class_by_attribute (this , py_component_instance);
7979
80- if (!PyObject_HasAttrString (py_component_instance, (char *)" begin_play " )) {
80+ if (!PyObject_HasAttrString (py_component_instance, (char *)" initialize_component " )) {
8181 return ;
8282 }
8383
84- PyObject *bp_ret = PyObject_CallMethod (py_component_instance, (char *)" begin_play " , NULL );
85- if (!bp_ret ) {
84+ PyObject *ic_ret = PyObject_CallMethod (py_component_instance, (char *)" initialize_component " , NULL );
85+ if (!ic_ret ) {
8686 unreal_engine_py_log_error ();
8787 }
88- Py_XDECREF (bp_ret );
88+ Py_XDECREF (ic_ret );
8989
9090}
9191
92+ void UPythonComponent::InitializeComponent ()
93+ {
94+ Super::InitializeComponent ();
95+ InitializePythonComponent ();
96+ }
97+
98+
9299// Called when the game starts
93100void UPythonComponent::BeginPlay ()
94101{
95102 Super::BeginPlay ();
96103
97- // ...
104+ if (!py_component_instance)
105+ return ;
98106
99- InitializePythonComponent ();
107+ FScopePythonGIL gil;
108+
109+ if (!PyObject_HasAttrString (py_component_instance, (char *)" begin_play" )) {
110+ return ;
111+ }
112+
113+ PyObject *bp_ret = PyObject_CallMethod (py_component_instance, (char *)" begin_play" , NULL );
114+ if (!bp_ret) {
115+ unreal_engine_py_log_error ();
116+ }
117+ Py_XDECREF (bp_ret);
100118
101119}
102120
0 commit comments