Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load the UnrealEnginePython through Unreal's native python command line, and import the 'unreal_engine' module #643

Open
nasheetzaman opened this issue Jan 12, 2019 · 7 comments

Comments

@nasheetzaman
Copy link

I have the UnrealEnginePython plugin installed to my project, but can't seem to find a way to import the module independent of its Python Console.

I am working on some external scripts that need to 'import unreal_engine' before anything else can work.

Here's what I get in the Output Log if I try to import:
LogPython: import unreal_engine
LogPython: Error: Traceback (most recent call last):
LogPython: Error: File "", line 1, in
LogPython: Error: ImportError: No module named unreal_engine

I was going to try to append the path using sys.path.append(path to unreal_engine.py), but can't find the source file (if there is one). Is there another way to load the .uplugin?

@dfb
Copy link
Contributor

dfb commented Jan 13, 2019

You can load the module from inside the editor or inside a packaged game, but not outside of UE4 - the module is effectively built into UE4.

@nasheetzaman
Copy link
Author

@dfb Thanks for the response. Bummer though.

Follow up question: is there a way to programatically open the UnrealEngine Python Console window after Unreal is launched, and then send it a script to execute?

@dfb
Copy link
Contributor

dfb commented Jan 14, 2019

There's probably a way to accomplish what you're after, yes. The console is really just if you want to do interactive stuff, so if you're not doing something interactive, you can launch your code in other ways.

For example, on startup, the module Content/Scripts/ue_site.py gets loaded automatically if it exists. In that module you can put whatever code you want.

Another alternative would be to create a new button or widget in the editor (you can use Python to create new widgets and add them to the editor) and then use the button to trigger your code to run - see the Slate API for more info.

It really just comes down to what you're trying to accomplish and what you want to trigger your code to run (i.e. what makes sense from a workflow perspective - is it stuff you want to happen when the editor loads, is it stuff you want to run when you initiate some action in the editor, etc.).

@nasheetzaman
Copy link
Author

Thanks, I'll look into that. I wrote an 'import_camera' function using unreal_engine which works fine when I execute it in the Python Console. Where I'm stuck is, I have the Shotgun Studio plugin for Unreal also (https://docs.unrealengine.com/en-us/Editor/Content/Using-Unreal-Engine-with-Autodesk-Shotgun), and I wanted to give Shotgun Loader the option to execute 'import_camera' (in addition to the 'import into content browser' shown in the screenshot). I think what I might need to do is put a command into ue_site.py to launch the console before the Shotgun plugin is loaded. This may be beyond the current limitations of Python in Unreal, so I'm looking into the C++ API now as well.

The reason I started using UnrealEnginePython was because I couldn't find any other straightforward way to create a new LevelSequence -- the native unreal.LevelSequenceFactoryNew().create_new() didn't work as I expected and just returns a bool value. I was excited to see this plugin, so I hope there are plans to make it into an importable module in the future. And if anyone happens to know another way to create a LevelSequence, that would be helpful too.

@kakyoism
Copy link

To continue the thread, is it possible to run 20tab python scripts from command line using UE4Editor-Cmd.exe 's -run=pythonscript option? A few questions regarding that:

  1. Can I enable both the built-in Unreal Python Scripting plugin and the 20tab plugin?
  2. Is it possible to launch a 20tab Python script from the builtin Python script?

I need a fully automated workflow that can be done through command line. The UE builtin satisfies that but lack a lot of features and usability that 20tab has.

@dfb
Copy link
Contributor

dfb commented Apr 28, 2019

The two versions of Python are separate - you are almost better off thinking of them as two separate languages because they really are very separate and isolated.

Probably the best bet is to do some experimentation. For example, see if your ue_site.py gets imported when you do a UE4Editor-cmd.exe -run script that does nothing but sleeps (i.e. I know of no way to directly call UEPy from UE4 Python, but if your normal UEPy ue_site.py file gets loaded, then that might be good enough).

Similarly, when you just launch UE4Editor normally, ue_site.py does load, so you could use that as a place to kick off some tasks of some sort. If there's not a convenient place to process command line parameters, then your workflow could instead write parameters to e.g. a text file at a known location, and on startup your ue_site.py reads that file and acts on them.

@ChristinaRika
Copy link

For some reasons, I want to just use UnrealEnginePython in cmd, just use command like "UE4-Editor.exe XX.uproject -run=pythonscript", but I don't know how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants