Download

Python Scripting Feedback Thread

So I’ve been playing with the Python scripting workflow quite a lot the last couple of days and thought it might be useful to give some feedback.
Doesn’t look there’s a thread for it already so here’s one to get us started!
[HR][/HR]The Good

  • Being able to automate importing CAD with Python is a brilliant idea.
  • Existing functionality works very well.
  • The [FONT=courier new]unrealPython module is well organised and the API itself is well commented for inspection with [FONT=courier new]help().
  • The progress bar integration for sub-functions such as deleting assets is a nice touch.

The Bad

  • Why have Epic made their own Python plugin instead of joining forces with the existing, open-source, much more powerful plugin?

  • Some functions prone to crashing the editor, mostly due to issues around deleting actors or assets.

  • Need a way to check if ObjectInstance is null.

  • Python 2. Why?

  • No documentation on splitting large scripts into multiple modules.

  • No web documentation on the API. This would be very easy to autogenerate.

  • Pythonic indexing doesn’t work with ArrayProperties (e.g. x-1] for last element).

The Ugly (feature requests!)

  • The Construct -> Process -> Import workflow for CAD doesn’t seem to work as well as it does for .udatasmith files.

  • Can’t manipulate meshes (e.g.) merge before importing into the level. This means that to merge large assemblies you have to first build the static mesh assets for each, import all the subparts into a level, merge the actors into a new asset, delete the leftover actors and delete the old mesh assets. This is laborious and prone to error and crashes.

  • Using command line interface for running scripts is not optimal; they should be a proper asset which can be run from the context menu or something.

  • Being able to create custom slate windows / buttons for entering arguments and running would be ideal; the third-party Python plugin does this very well.

  • Long running scripts (e.g. importing hundreds of assemblies) give no progress of indication.

  • Add a hook for manually setting the progress bar percentage?

  • No development environment -> no autocompletion.

[HR][/HR]
Hope that list doesn’t sound too negative, the headline is that the Python scripting is awesome!

Well, it’s about to get a bit better. Rumors exist of a documented API and for sure you’ll have 2-pass import for CAD formats. That means we’ll first load the assembly tree and you can make whatever changes you want before we load the actual meshes (the part that takes so long). @ThomasC_Epic @pfbreton to take a look at this. We also have a place already for feature requests in this forum, so you might want to post there too.

Awesome news, can’t wait for 4.20! Overall the python scripting is already excellent, can’t wait to see where it goes from here.

Let us know if you find specifics. Our goal is the editor should never crash via Python.

I’ve answered this question elsewhere: https://forums.unrealengine.com/unre…why-python-2-7

We have Sphinx generation working for 4.20. I’m not 100% sure if it will be hosted online yet, but you’ll definitely be able to generate it locally.

My bad. I’ll put in a bug for that. Edit: Fixed for 4.20.

Yeah, we have plans to add support for menu extensions and UI creation in Python (likely via UMG), however this won’t be coming in 4.20.

4.20 adds unreal.ScopedSlowTask to let you report long-running progress like this.

4.20 generates a stub unreal.py file (when developer mode is enabled in the plugin settings) that can be used with external IDEs for auto-complete (we also use it for Sphinx generation).

Thanks very much for the comprehensive reply Jamie, sounds like all my prayers will be answered! Keep up the great work guys.

Regarding crashes from Python, they are almost entirely a result of an “ObjectInstance is null” error when accessing an object.
For example I have a script which runs a loop which each cycle

  1. imports a .cgr using Datasmith into a level
  2. merge the meshes into a new actor and set a folder path
  3. delete the leftover actors and clean up unneeded static mesh assets.

I ran into quite a lot of crashes and issues that hinted at some sort of weird memory corruption (object variables becoming null or pointing at other objects between lines). I think it’s probably related to repeatedly deleting and creating new actors.

I’ll wait until 4.20 and see if it still occurs before I put effort into making a minimal script that reproduces the problem…