Skip to content

Commit 6abf75b

Browse files
committed
fixed 20tab#542
1 parent 4faf897 commit 6abf75b

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

Source/UnrealEnginePython/Private/UObject/UEPyCapture.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ for a queue of UMovieSceneCapture objects
2929
struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture>
3030
{
3131

32-
static TWeakPtr<FInEditorMultiCapture> CreateInEditorMultiCapture(TArray<UMovieSceneCapture*> InCaptureObjects)
32+
static TWeakPtr<FInEditorMultiCapture> CreateInEditorMultiCapture(TArray<UMovieSceneCapture*> InCaptureObjects, PyObject *py_callable)
3333
{
3434
// FInEditorCapture owns itself, so should only be kept alive by itself, or a pinned (=> temporary) weakptr
3535
FInEditorMultiCapture* Capture = new FInEditorMultiCapture;
3636
Capture->CaptureObjects = InCaptureObjects;
37+
Capture->py_callable = py_callable;
38+
if (Capture->py_callable)
39+
Py_INCREF(Capture->py_callable);
3740
for (UMovieSceneCapture *SceneCapture : Capture->CaptureObjects)
3841
{
3942
SceneCapture->AddToRoot();
@@ -55,6 +58,10 @@ struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture>
5558
SceneCapture->RemoveFromRoot();
5659
}
5760
OnlyStrongReference = nullptr;
61+
{
62+
FScopePythonGIL gil;
63+
Py_XDECREF(py_callable);
64+
}
5865
}
5966

6067
void Dequeue()
@@ -124,6 +131,22 @@ struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture>
124131

125132
bool PlaySession(float DeltaTime)
126133
{
134+
135+
136+
if (py_callable)
137+
{
138+
GEditor->RequestEndPlayMap();
139+
FScopePythonGIL gil;
140+
ue_PyUObject *py_capture = ue_get_python_uobject(CurrentCaptureObject);
141+
PyObject *py_ret = PyObject_CallFunction(py_callable, "O", py_capture);
142+
if (!py_ret)
143+
{
144+
unreal_engine_py_log_error();
145+
}
146+
Py_XDECREF(py_ret);
147+
}
148+
149+
127150
GEditor->RequestPlaySession(true, nullptr, false);
128151
return false;
129152
}
@@ -276,6 +299,7 @@ struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture>
276299
{
277300

278301
FEditorDelegates::EndPIE.RemoveAll(this);
302+
279303
// remove item from the TArray;
280304
CaptureObjects.RemoveAt(0);
281305

@@ -309,13 +333,16 @@ struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture>
309333

310334
TSubclassOf<AGameModeBase> CachedGameMode;
311335
TArray<UMovieSceneCapture*> CaptureObjects;
336+
337+
PyObject *py_callable;
312338
};
313339

314340
PyObject *py_unreal_engine_in_editor_capture(PyObject * self, PyObject * args)
315341
{
316342
PyObject *py_scene_captures;
343+
PyObject *py_callable = nullptr;
317344

318-
if (!PyArg_ParseTuple(args, "O:in_editor_capture", &py_scene_captures))
345+
if (!PyArg_ParseTuple(args, "O|O:in_editor_capture", &py_scene_captures, &py_callable))
319346
{
320347
return nullptr;
321348
}
@@ -348,7 +375,7 @@ PyObject *py_unreal_engine_in_editor_capture(PyObject * self, PyObject * args)
348375
}
349376

350377
Py_BEGIN_ALLOW_THREADS
351-
FInEditorMultiCapture::CreateInEditorMultiCapture(Captures);
378+
FInEditorMultiCapture::CreateInEditorMultiCapture(Captures, py_callable);
352379
Py_END_ALLOW_THREADS
353380

354381
Py_RETURN_NONE;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unreal_engine as ue
2+
from unreal_engine.classes import AutomatedLevelSequenceCapture, World
3+
from unreal_engine.structs import SoftObjectPath
4+
5+
level_sequence_mappings = {
6+
'/Game/SequenceForDefault001': '/Game/Default001',
7+
'/Game/SequenceForVR001': '/Game/VR001'
8+
}
9+
10+
def setup_sequence(capture):
11+
ue.open_editor_for_asset(ue.load_object(World, level_sequence_mappings[capture.LevelSequenceAsset.AssetPathName]))
12+
13+
captures = []
14+
for sequence_asset in level_sequence_mappings:
15+
capture = AutomatedLevelSequenceCapture()
16+
capture.LevelSequenceAsset = SoftObjectPath(AssetPathName=sequence_asset)
17+
captures.append(capture)
18+
19+
ue.in_editor_capture(captures, setup_sequence)

0 commit comments

Comments
 (0)