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

Method BeginPlay

Source/UnrealEnginePython/Public/PyCharacter.cpp:17–90  ·  view source on GitHub ↗

Called when the game starts

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

ue_get_python_wrapperFunction · 0.85

Tested by

no test coverage detected