Has anyone else seen this and/or know how to fix it?
My script is barebones. It’s an editor utility widget that has one button that fires a custom python node in it that just prints hello.
That all works. <and yes, the script is added as a “startup script” and is in a directory that’s added to the python “additional paths” option>
The issue is that if i leave that widget window open when i close/restart unreal, it corrupts the python node. To fix that, you basically have to close the widget window and close/restart unreal again, then open the widget window. This obviously sucks, so I’d like to know what I’m doing wrong?
I took a quick look at this issue and found a couple things
The editor is restoring windows/tabs before the python module executes its startup scripts
The python module executes its startup script in the first TICK, whereas it appears that this would not be a problem if the startup scripts were executed during FPythonScriptPlugin.InitializePython, as this comes before the windows are restored.
Why does the python plugin defer **startup **scripts to the first tick? They aren’t startup scripts any more when it does that, they are runonce scripts, and those are useless for being able to depend on for blueprint function libraries that may be utilized by editor utility scripts.
This seems to me like a pretty fundamental design failure not to ensure the python blueprint functions are usable in the most basic form of editor scripting(editor utility scripts)
I copied the PythonScriptPlugin from the engine folder to project, and moved the startup script execution to the bottom of FPythonScriptPlugin.InitializePython, so it executes the startup scripts during the actual startup, and the busted editor utility script issue was fixed. I don’t know if there is some other issue that deferring that functionality to the tick was meant to fix, but the way it ships is inadequate to depend on for these types of tool blueprints.
Hi, sorry for digging it up. I tried to move the startup script execution initially in FPythonScriptPlugin:::Tick() in PythonScriptPlugin.cpp, which I suppose is :
// Run start-up scripts now
TArray<FString> PySysPaths;
{
FPyScopedGIL GIL;
PySysPaths = PyUtil::GetSystemPaths();
}
for (const FString& PySysPath : PySysPaths)
{
const FString PotentialFilePath = PySysPath / TEXT("init_unreal.py");
if (FPaths::FileExists(PotentialFilePath))
{
// Execute these files in the "public" scope, as if their contents had been run directly in the console
// This allows them to be used to set-up an editor environment for the console
FPythonCommandEx InitUnrealPythonCommand;
InitUnrealPythonCommand.FileExecutionScope = EPythonFileExecutionScope::Public;
RunFile(*PotentialFilePath, *InitUnrealPythonCommand.Command, InitUnrealPythonCommand);
}
}
for (const FString& StartupScript : GetDefault<UPythonScriptPluginSettings>()->StartupScripts)
{
ExecPythonCommand(*StartupScript);
}
at the very bottom of FPythonScriptPlugin::InitializePython(), but it didn’t change anything. The node still fails on restart.