Skip to content

Commit

Permalink
added ImportModules options
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto De Ioris committed Sep 7, 2018
1 parent 408b688 commit 5a19bf8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/UnrealEnginePython/Private/UnrealEnginePython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ void FUnrealEnginePythonModule::StartupModule()
Py_SetPythonHome(home);
}

TArray<FString> ImportModules;

FString IniValue;
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("ProgramName"), IniValue, GEngineIni))
{
Expand Down Expand Up @@ -316,6 +318,12 @@ void FUnrealEnginePythonModule::StartupModule()
ZipPath = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
}

if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("ImportModules"), IniValue, GEngineIni))
{
const TCHAR* separators[] = { TEXT(" "), TEXT(";"), TEXT(",") };
IniValue.ParseIntoArray(ImportModules, separators, 3);
}

FString ProjectScriptsPath = FPaths::Combine(*PROJECT_CONTENT_DIR, UTF8_TO_TCHAR("Scripts"));
if (!FPaths::DirectoryExists(ProjectScriptsPath))
{
Expand Down Expand Up @@ -480,6 +488,19 @@ void FUnrealEnginePythonModule::StartupModule()
#endif
}


for (FString ImportModule : ImportModules)
{
if (PyImport_ImportModule(TCHAR_TO_UTF8(*ImportModule)))
{
UE_LOG(LogPython, Log, TEXT("%s Python module successfully imported"), *ImportModule);
}
else
{
unreal_engine_py_log_error();
}
}

// release the GIL
PyThreadState *UEPyGlobalState = PyEval_SaveThread();
}
Expand Down

0 comments on commit 5a19bf8

Please sign in to comment.