MCPcopy Create free account
hub / github.com/20tab/UnrealEnginePython / BeginPlay

Method BeginPlay

Source/UnrealEnginePython/Public/PyPawn.cpp:16–87  ·  view source on GitHub ↗

Called when the game starts

Source from the content-addressed store, hash-verified

14
15// Called when the game starts
16void APyPawn::BeginPlay()
17{
18 Super::BeginPlay();
19
20 // ...
21
22 if (PythonModule.IsEmpty())
23 return;
24
25 FScopePythonGIL gil;
26
27 py_uobject = ue_get_python_wrapper(this);
28 if (!py_uobject) {
29 unreal_engine_py_log_error();
30 return;
31 }
32
33 PyObject *py_pawn_module = PyImport_ImportModule(TCHAR_TO_UTF8(*PythonModule));
34 if (!py_pawn_module) {
35 unreal_engine_py_log_error();
36 return;
37 }
38
39#if WITH_EDITOR
40 // todo implement autoreload with a dictionary of module timestamps
41 py_pawn_module = PyImport_ReloadModule(py_pawn_module);
42 if (!py_pawn_module) {
43 unreal_engine_py_log_error();
44 return;
45 }
46#endif
47
48 if (PythonClass.IsEmpty())
49 return;
50
51 PyObject *py_pawn_module_dict = PyModule_GetDict(py_pawn_module);
52 PyObject *py_pawn_class = PyDict_GetItemString(py_pawn_module_dict, TCHAR_TO_UTF8(*PythonClass));
53
54 if (!py_pawn_class) {
55 UE_LOG(LogPython, Error, TEXT("Unable to find class %s in module %s"), *PythonClass, *PythonModule);
56 return;
57 }
58
59 py_pawn_instance = PyObject_CallObject(py_pawn_class, NULL);
60 if (!py_pawn_instance) {
61 unreal_engine_py_log_error();
62 return;
63 }
64
65 py_uobject->py_proxy = py_pawn_instance;
66
67 PyObject_SetAttrString(py_pawn_instance, (char *)"uobject", (PyObject *)py_uobject);
68
69
70 // disable ticking if not required
71 if (!PyObject_HasAttrString(py_pawn_instance, (char *)"tick") || PythonTickForceDisabled) {
72 SetActorTickEnabled(false);
73 }

Callers 1

py_ue_playFunction · 0.45

Calls 3

ue_get_python_wrapperFunction · 0.85

Tested by

no test coverage detected