@@ -11,13 +11,30 @@ APyPawn::APyPawn()
1111
1212}
1313
14+ void APyPawn::PostInitializeComponents ()
15+ {
16+ Super::PostInitializeComponents ();
17+
18+ if (!py_pawn_instance)
19+ return ;
20+
21+ FScopePythonGIL gil;
22+
23+ if (!PyObject_HasAttrString (py_pawn_instance, (char *)" post_initialize_components" ))
24+ return ;
25+
26+ PyObject *pic_ret = PyObject_CallMethod (py_pawn_instance, (char *)" post_initialize_components" , NULL );
27+ if (!pic_ret) {
28+ unreal_engine_py_log_error ();
29+ return ;
30+ }
31+ Py_DECREF (pic_ret);
32+ }
1433
1534// Called when the game starts
16- void APyPawn::BeginPlay ()
35+ void APyPawn::PreInitializeComponents ()
1736{
18- Super::BeginPlay ();
19-
20- // ...
37+ Super::PreInitializeComponents ();
2138
2239 if (PythonModule.IsEmpty ())
2340 return ;
@@ -77,6 +94,27 @@ void APyPawn::BeginPlay()
7794
7895 ue_bind_events_for_py_class_by_attribute (this , py_pawn_instance);
7996
97+ if (!PyObject_HasAttrString (py_pawn_instance, (char *)" pre_initialize_components" ))
98+ return ;
99+
100+ PyObject *pic_ret = PyObject_CallMethod (py_pawn_instance, (char *)" pre_initialize_components" , NULL );
101+ if (!pic_ret) {
102+ unreal_engine_py_log_error ();
103+ return ;
104+ }
105+ Py_DECREF (pic_ret);
106+ }
107+
108+ // Called when the game starts
109+ void APyPawn::BeginPlay ()
110+ {
111+ Super::BeginPlay ();
112+
113+ if (!py_pawn_instance)
114+ return ;
115+
116+ FScopePythonGIL gil;
117+
80118 if (!PyObject_HasAttrString (py_pawn_instance, (char *)" begin_play" ))
81119 return ;
82120
@@ -88,7 +126,6 @@ void APyPawn::BeginPlay()
88126 Py_DECREF (bp_ret);
89127}
90128
91-
92129// Called every frame
93130void APyPawn::Tick (float DeltaTime)
94131{
@@ -109,6 +146,29 @@ void APyPawn::Tick(float DeltaTime)
109146}
110147
111148
149+ void APyPawn::EndPlay (const EEndPlayReason::Type EndPlayReason)
150+ {
151+ if (!py_pawn_instance)
152+ return ;
153+
154+ FScopePythonGIL gil;
155+
156+ if (PyObject_HasAttrString (py_pawn_instance, (char *)" end_play" )) {
157+ PyObject *ep_ret = PyObject_CallMethod (py_pawn_instance, (char *)" end_play" , (char *)" i" , (int )EndPlayReason);
158+
159+ if (!ep_ret) {
160+ unreal_engine_py_log_error ();
161+ }
162+
163+ Py_XDECREF (ep_ret);
164+ }
165+
166+ Super::EndPlay (EndPlayReason);
167+
168+ // ...
169+ }
170+
171+
112172void APyPawn::CallPythonPawnMethod (FString method_name)
113173{
114174 if (!py_pawn_instance)
0 commit comments