Skip to content

Commit 5a19bf8

Browse files
author
Roberto De Ioris
committed
added ImportModules options
1 parent 408b688 commit 5a19bf8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ void FUnrealEnginePythonModule::StartupModule()
262262
Py_SetPythonHome(home);
263263
}
264264

265+
TArray<FString> ImportModules;
266+
265267
FString IniValue;
266268
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("ProgramName"), IniValue, GEngineIni))
267269
{
@@ -316,6 +318,12 @@ void FUnrealEnginePythonModule::StartupModule()
316318
ZipPath = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
317319
}
318320

321+
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("ImportModules"), IniValue, GEngineIni))
322+
{
323+
const TCHAR* separators[] = { TEXT(" "), TEXT(";"), TEXT(",") };
324+
IniValue.ParseIntoArray(ImportModules, separators, 3);
325+
}
326+
319327
FString ProjectScriptsPath = FPaths::Combine(*PROJECT_CONTENT_DIR, UTF8_TO_TCHAR("Scripts"));
320328
if (!FPaths::DirectoryExists(ProjectScriptsPath))
321329
{
@@ -480,6 +488,19 @@ void FUnrealEnginePythonModule::StartupModule()
480488
#endif
481489
}
482490

491+
492+
for (FString ImportModule : ImportModules)
493+
{
494+
if (PyImport_ImportModule(TCHAR_TO_UTF8(*ImportModule)))
495+
{
496+
UE_LOG(LogPython, Log, TEXT("%s Python module successfully imported"), *ImportModule);
497+
}
498+
else
499+
{
500+
unreal_engine_py_log_error();
501+
}
502+
}
503+
483504
// release the GIL
484505
PyThreadState *UEPyGlobalState = PyEval_SaveThread();
485506
}

0 commit comments

Comments
 (0)