@@ -14,11 +14,11 @@ APyCharacter::APyCharacter()
1414
1515
1616// Called when the game starts
17- void APyCharacter::BeginPlay ()
17+ void APyCharacter::PreInitializeComponents ()
1818{
1919
2020
21- Super::BeginPlay ();
21+ Super::PreInitializeComponents ();
2222
2323 // ...
2424
@@ -79,9 +79,50 @@ void APyCharacter::BeginPlay()
7979
8080 ue_bind_events_for_py_class_by_attribute (this , py_character_instance);
8181
82- if (!PyObject_HasAttrString (py_character_instance, (char *)" begin_play" )) {
82+ if (!PyObject_HasAttrString (py_character_instance, (char *)" pre_initialize_components" )) {
83+ return ;
84+ }
85+
86+ PyObject *pic_ret = PyObject_CallMethod (py_character_instance, (char *)" pre_initialize_components" , NULL );
87+ if (!pic_ret) {
88+ unreal_engine_py_log_error ();
89+ return ;
90+ }
91+ Py_DECREF (pic_ret);
92+ }
93+
94+ void APyCharacter::PostInitializeComponents ()
95+ {
96+ Super::PostInitializeComponents ();
97+
98+ if (!py_character_instance)
99+ return ;
100+
101+ FScopePythonGIL gil;
102+
103+ if (!PyObject_HasAttrString (py_character_instance, (char *)" post_initialize_components" ))
104+ return ;
105+
106+ PyObject *pic_ret = PyObject_CallMethod (py_character_instance, (char *)" post_initialize_components" , NULL );
107+ if (!pic_ret) {
108+ unreal_engine_py_log_error ();
83109 return ;
84110 }
111+ Py_DECREF (pic_ret);
112+ }
113+
114+ // Called when the game starts
115+ void APyCharacter::BeginPlay ()
116+ {
117+ Super::BeginPlay ();
118+
119+ if (!py_character_instance)
120+ return ;
121+
122+ FScopePythonGIL gil;
123+
124+ if (!PyObject_HasAttrString (py_character_instance, (char *)" begin_play" ))
125+ return ;
85126
86127 PyObject *bp_ret = PyObject_CallMethod (py_character_instance, (char *)" begin_play" , NULL );
87128 if (!bp_ret) {
@@ -358,6 +399,41 @@ void APyCharacter::SetupPlayerInputComponent(class UInputComponent* input)
358399{
359400 Super::SetupPlayerInputComponent (input);
360401
402+ if (!py_character_instance)
403+ return ;
404+
405+ FScopePythonGIL gil;
406+
407+ // no need to check for method availability, we did it in begin_play
408+
409+ PyObject *ret = PyObject_CallMethod (py_character_instance, (char *)" setup_player_input_component" , (char *)" O" , ue_get_python_wrapper (input));
410+ if (!ret) {
411+ unreal_engine_py_log_error ();
412+ return ;
413+ }
414+ Py_DECREF (ret);
415+ }
416+
417+ void APyCharacter::EndPlay (const EEndPlayReason::Type EndPlayReason)
418+ {
419+ if (!py_character_instance)
420+ return ;
421+
422+ FScopePythonGIL gil;
423+
424+ if (PyObject_HasAttrString (py_character_instance, (char *)" end_play" )) {
425+ PyObject *ep_ret = PyObject_CallMethod (py_character_instance, (char *)" end_play" , (char *)" i" , (int )EndPlayReason);
426+
427+ if (!ep_ret) {
428+ unreal_engine_py_log_error ();
429+ }
430+
431+ Py_XDECREF (ep_ret);
432+ }
433+
434+ Super::EndPlay (EndPlayReason);
435+
436+ // ...
361437}
362438
363439
0 commit comments