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