Skip to content

Commit eb9f1cd

Browse files
author
Roberto De Ioris
authored
Merge pull request 20tab#193 from yakhira/master
Added end_play to cleanup python resources correctly.
2 parents b4eb1b5 + d545a7e commit eb9f1cd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Source/UnrealEnginePython/Private/PythonComponent.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ void UPythonComponent::BeginPlay()
100100

101101
}
102102

103+
void UPythonComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
104+
{
105+
if (!py_component_instance)
106+
return;
107+
108+
FScopePythonGIL gil;
109+
110+
if (PyObject_HasAttrString(py_component_instance, (char *)"end_play")) {
111+
PyObject *ep_ret = PyObject_CallMethod(py_component_instance, (char *)"end_play", NULL);
112+
113+
if (!ep_ret) {
114+
unreal_engine_py_log_error();
115+
}
116+
117+
Py_XDECREF(ep_ret);
118+
}
119+
120+
Super::EndPlay(EndPlayReason);
121+
122+
// ...
123+
}
103124

104125
// Called every frame
105126
void UPythonComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

Source/UnrealEnginePython/Public/PythonComponent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class UPythonComponent : public UActorComponent
1818

1919
// Called when the game starts
2020
virtual void BeginPlay() override;
21+
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
2122

2223
// Called every frame
2324
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

0 commit comments

Comments
 (0)