Info

This post was originally intended for a Patreon audience.

Ideas for Making unity-python Better

When it comes to tools, I normally spend my time working on Rumor. However, in the past few months I’ve received several requests for help from developers on my unity-python plugin for Unity. I’ve gotten some ideas from helping and, especially because of Ornate_Owl, I’ve learned a lot about what kind of useful improvements I could make.

The future improvements I mention in this post would be amazing, but I currently don’t have the time right now to work on these. Instead, this post is mostly an update on where the library is now and where I’m thinking about taking it. For that reason, this post is public since it contains information I’d like anyone using the library to know.

Recent Changes

It used to be that I viewed the unity-python project as mostly a re-packaging of IronPython for Unity, but now I’m noticing some significant areas that could use a lot of work.

For example, here are some of the recent improvements:

  • Log output from running python scripts is now automatically redirected to the Unity logging system. There is a non-trivial amount of work to figure out how to make this work and it is useful for developers, especially in the case of non-exception error messages.
  • Fixed a problem where not all UnityEngine/UnityEditor types could be imported. Unity spreads all of its code for the UnityEngine namespace into many different assemblies, so this is also a non-trivial task.

There are also several simple things that a developer may want to know how to do that don’t have an example. For example, how do you run a Python script with StartCoroutine? I’d like to add more examples to the library that cover a larger number of use cases.

There are some harder to obtain goals with the that I’d like to tackle at some point, such as…

Including Python Libraries in Builds

When you build a unity project that uses unity-python, you have to copy the Python Lib/ folder manually. There are a few reasons I haven’t made this situation better:

  • Including the Lib/ folder in StreamingAssets is insecure. A lot of bad things can happen, as any python script the program depends on can be changed to do malicious things instead.
  • Including the Lib/ folder in Resources doesn’t work. As far as I know, IronPython is only able to load the Python library from a location on disk.

I would like to tell IronPython to load the libraries from memory, but I haven’t figured out how to do so yet.

Simplify Adding Python Packages

Right now, unity-python comes with the same packages that are come with IronPython. Developers often seem to have problems adding other packages to the project and it’s definitely not as easy as using pip. In addition, the installed package might depend on some C# assembly that isn’t included in the build. It would be nice if there was some GUI interface to select and install packages along with the correct DLLs.