init_unreal.py is not automatically running

I’m having trouble getting a Python plugin to load so I can call custom modules within the editor. It appears Unreal Engine isn’t running my `init_unreal.py` file. I can confirm that when running it via Python remote execution, the `init_unreal` code correctly adds the path to `sys.path`, allowing module imports. Additionally, editing `init_unreal.py` to point to the plugin directory and moving it to the `[Project]/Content/Python/` folder also enables automatic execution and module imports.

I would prefer to have Unreal automatically run the init_unreal.py inside the `[Plug-in]/Content/Python/` folder for cleanliness. Any suggestions on what I might be doing wrong?

Steps to Reproduce
Windows

  1. Make a plugin.
  2. Add init_unreal.py to [Plug-in]/Content/Python/
  3. Edit init_unreal.py to append its directory to sys.path
  4. Put your Custom Module into [Plug-in]/Content/Python/
  5. Launch Editor
  6. Try to import your custom module.
  7. Get error saying could not find module.

Is your plugin marked as containing content? Only plugins with content have mount roots that we can run Python files from:

“CanContainContent”: true,

Yes, it is set to contain content.

[Image Removed]

I haven’t been able to reproduce this with the given steps, though I’m not sure what you’re doing with sys.path in step 3. Any Content/Python folders are automatically added to sys.path, so you shouldn’t need to do anything there to be able to import a module from the Content/Python folder of a plugin.

My test layout looks like this:

  • [Plug-in]/Content/Python/init_unreal.py
  • [Plug-in]/Content/Python/my_module/__init__.py

I’m able to run “import my_module” from either init_unreal.py or via the output log without any errors.

hmm, that is how I am structuring my plugin as well.

[Plug-in]/Content/Python/:[Image Removed]This is my .uplugin file, do you see any issues in here:

{
	"FileVersion": 3,
	"Version": 1,
	"VersionName": "0.1",
	"FriendlyName": "Cyclops UE",
	"Description": "Cyclops Render Plugin",
	"Category": "tool",
	"CreatedBy": "Tcool",
	"CreatedByURL": "",
	"DocsURL": "",
	"MarketplaceURL": "",
	"SupportURL": "",
	"CanContainContent": true,
	"IsBetaVersion": true,
	"IsExperimentalVersion": true,
	"Installed": false,
	"Plugins": [
		{
			"Name": "PythonScriptPlugin",
			"Enabled": true
		}
	]
}

That seems correct. The plugin itself is enabled for the project? (I assume it must be, otherwise it wouldn’t work at all).

If you’re able to reproduce this in a clean project, then can you please provide that so I can investigate further?

Hey Jamie,

Sorry for the delayed reply, here is the project with the plugin in it.

  1. open project
  2. open output log
  3. send this python command: `import cyclops`
  4. Error will occur.

The expected outcome is:

  1. open project
  2. open output log
  3. send this python command: `from cyclops.hello_world_tool import hello
  4. “Hello, Unreal Engine!” will be printed into the log.

Let me know if you have any questions.

Tucker

In the given zip, CyclopsUE.uplugin is in FWProduction/Plugins/CyclopsUE/Content. CyclopsUE.uplugin needs to be at FWProduction/Plugins/CyclopsUE for UE to recognize that as a plugin.

With that fixed, ‘import cyclops’ works fine. ‘from cyclops.hello_world_tool import hello’ still doesn’t, as it needs to be ‘from cyclops.tools.hello_world_tool import hello’ to match the folder layout.

Ah perfect, I thought I had the structure correct. Thank you!

oh yea that was a typo omitting the tools. Good catch!