@@ -61,7 +61,7 @@ bool FUnrealEnginePythonModule::PythonGILAcquire() {
6161 return true ;
6262}
6363
64- static void UESetupPythonInterpreter (bool verbose) {
64+ void FUnrealEnginePythonModule:: UESetupPythonInterpreter (bool verbose) {
6565
6666#if PY_MAJOR_VERSION >= 3
6767 wchar_t *argv[] = { UTF8_TO_TCHAR (" UnrealEngine" ), NULL };
@@ -77,11 +77,11 @@ static void UESetupPythonInterpreter(bool verbose) {
7777
7878 PyObject *py_path = PyDict_GetItemString (py_sys_dict, " path" );
7979
80- char *zip_path = TCHAR_TO_UTF8 (*FPaths::Combine (* FPaths::GameContentDir (), UTF8_TO_TCHAR ( " ue_python.zip " )) );
80+ char *zip_path = TCHAR_TO_UTF8 (*ZipPath );
8181 PyObject *py_zip_path = PyUnicode_FromString (zip_path);
8282 PyList_Insert (py_path, 0 , py_zip_path);
8383
84- char *scripts_path = TCHAR_TO_UTF8 (*FPaths::Combine (* FPaths::GameContentDir (), UTF8_TO_TCHAR ( " Scripts " )) );
84+ char *scripts_path = TCHAR_TO_UTF8 (*ScriptsPath );
8585 PyObject *py_scripts_path = PyUnicode_FromString (scripts_path);
8686 PyList_Insert (py_path, 0 , py_scripts_path);
8787
@@ -110,17 +110,41 @@ static void setup_stdout_stderr() {
110110void FUnrealEnginePythonModule::StartupModule ()
111111{
112112 // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
113- FString PyHome ;
114- if (GConfig->GetString (UTF8_TO_TCHAR (" Python" ), UTF8_TO_TCHAR (" Home" ), PyHome , GEngineIni)) {
113+ FString IniValue ;
114+ if (GConfig->GetString (UTF8_TO_TCHAR (" Python" ), UTF8_TO_TCHAR (" Home" ), IniValue , GEngineIni)) {
115115#if PY_MAJOR_VERSION >= 3
116- wchar_t *home = (wchar_t *)*PyHome ;
116+ wchar_t *home = (wchar_t *)*IniValue ;
117117#else
118- char *home = TCHAR_TO_UTF8 (*PyHome );
118+ char *home = TCHAR_TO_UTF8 (*IniValue );
119119#endif
120120
121121 Py_SetPythonHome (home);
122122 }
123123
124+ if (GConfig->GetString (UTF8_TO_TCHAR (" Python" ), UTF8_TO_TCHAR (" ScriptsPath" ), IniValue, GEngineIni)) {
125+ ScriptsPath = IniValue;
126+ }
127+
128+ if (GConfig->GetString (UTF8_TO_TCHAR (" Python" ), UTF8_TO_TCHAR (" RelativeScriptsPath" ), IniValue, GEngineIni)) {
129+ ScriptsPath = FPaths::Combine (FPaths::GameContentDir (), IniValue);
130+ }
131+
132+ if (GConfig->GetString (UTF8_TO_TCHAR (" Python" ), UTF8_TO_TCHAR (" ZipPath" ), IniValue, GEngineIni)) {
133+ ZipPath = IniValue;
134+ }
135+
136+ if (GConfig->GetString (UTF8_TO_TCHAR (" Python" ), UTF8_TO_TCHAR (" RelativeZipPath" ), IniValue, GEngineIni)) {
137+ ZipPath = FPaths::Combine (FPaths::GameContentDir (), IniValue);
138+ }
139+
140+ if (ScriptsPath.IsEmpty ()) {
141+ ScriptsPath = FPaths::Combine (*FPaths::GameContentDir (), UTF8_TO_TCHAR (" Scripts" ));
142+ }
143+
144+ if (ZipPath.IsEmpty ()) {
145+ ZipPath = FPaths::Combine (*FPaths::GameContentDir (), UTF8_TO_TCHAR (" ue_python.zip" ));
146+ }
147+
124148 Py_Initialize ();
125149
126150 PyEval_InitThreads ();
@@ -211,14 +235,14 @@ void FUnrealEnginePythonModule::RunStringSandboxed(char *str) {
211235
212236 Py_EndInterpreter (py_new_state);
213237 PyThreadState_Swap (_main);
214- }
238+ }
215239
216240void FUnrealEnginePythonModule::RunFile (char *filename) {
217241 FScopePythonGIL gil;
218242 char *full_path = filename;
219243 if (!FPaths::FileExists (filename))
220244 {
221- full_path = TCHAR_TO_UTF8 (*FPaths::Combine (* FPaths::GameContentDir (), UTF8_TO_TCHAR ( " Scripts " ), * FString ( " / " ) , UTF8_TO_TCHAR (filename)));
245+ full_path = TCHAR_TO_UTF8 (*FPaths::Combine (ScriptsPath , UTF8_TO_TCHAR (filename)));
222246 }
223247#if PY_MAJOR_VERSION >= 3
224248 FILE *fd = nullptr ;
@@ -261,7 +285,7 @@ void FUnrealEnginePythonModule::RunFileSandboxed(char *filename) {
261285 char *full_path = filename;
262286 if (!FPaths::FileExists (filename))
263287 {
264- full_path = TCHAR_TO_UTF8 (*FPaths::Combine (* FPaths::GameContentDir (), UTF8_TO_TCHAR ( " Scripts " ), * FString ( " / " ) , UTF8_TO_TCHAR (filename)));
288+ full_path = TCHAR_TO_UTF8 (*FPaths::Combine (ScriptsPath , UTF8_TO_TCHAR (filename)));
265289 }
266290
267291 PyThreadState *_main = PyThreadState_Get ();
0 commit comments