Skip to content

Commit 429afbd

Browse files
Iakhin, RuslanIakhin, Ruslan
authored andcommitted
Added end_play function to free resources correctly when play stops
1 parent b4eb1b5 commit 429afbd

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎Source/UnrealEnginePython/Private/PythonComponent.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ 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+
PyObject *ep_ret = PyObject_CallMethod(py_component_instance, (char *)"end_play", NULL);
111+
112+
if (!ep_ret) {
113+
unreal_engine_py_log_error();
114+
}
115+
116+
Py_XDECREF(ep_ret);
117+
118+
Super::EndPlay(EndPlayReason);
119+
120+
// ...
121+
}
103122

104123
// Called every frame
105124
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)