Python for Unity Editor now available as a preview package!
Introduction
Python is the standard scripting language for Pipeline TDs (Technical Directors) in the film industry, and in general for content creation oriented workflows.
After working closely with different production studios and partners (animated films, games, automotive, theme park ride, production management tools, …) we are releasing a Preview package of Python for Unity which allows access from Python to the full C# API of UnityEditor, UnityEngine, as well as your own C# APIs added to your Unity projects, and running Python code from within C#.
Typical use cases are:
- Integration of existing pipeline tools written in Python and PySide.
- Integration of third-party software like Autodesk Shotgun (Preview integration package to come soon).
- Integration with third-party libraries like Pixar OpenTimelineIO (Experimental integration package to come soon)
- Scene debugging in Unity using the Python Console
This release is built primarily as a tool for pipeline TDs at studios. There is currently no intention to make Python a scripting language for Gameplay.
Installation
Because this package requires preliminary software installations and configurations, we have decided to not expose the package in the Unity Package Manager window, so Python for Unity requires some manual installation:
- First, follow the installation instructions in the manual
- Next, install Python for Unity itself: Edit your Unity manifest.json file (in the Packages folder of your project) so that it starts with
{
"dependencies": {
"com.unity.scripting.python": "2.0.1-preview.2",
Known issue: If Unity crashes on startup when you open a project that uses Python it might be an issue with Python 3 which would be earlier in the %PATH% on Windows. The current work around is to Uninstall Python 3, reinstall Python 2.7, then restart the Unity Hub before trying again (or reboot to make absolutely sure). We are still investigating this issue. We are also working on Python 3 support and embedded Python environment to facilitate the installation.
Bug fix release: [2.0.1-preview.2] - 2020-02-13
FIXES over 2.0.0-preview.6
- Improved handling of a Python installation that can’t find its home. Unity now displays an error rather than crashing.
- Fixed repeated registration of an OnUpdate callback.
- Prevented the Python top-level menu being added by default. Unpack the sample clients manually from the Package Manager instead.
- The tilde character (~) in Python path and site-packages is now interpreted as the user home directory on all platforms.
- In the Python Console, Ctrl-enter with no selection now executes the entire script (Cmd-enter on macOS).
- Fixed the year in 2.0.0-preview.6 release date. It’s already 2020 apparently!
Your first Python script:
Go to Window → General → Python Console
Type the following code in the bottom window and click on the Execute button:
import UnityEngine
print ("I can print using python")
UnityEngine.Debug.Log("hello Unity world")
Documentation is available here.
There is also a suite of examples showing Python code calling C# and C# running Python code that can be found in the Python package folder.
Platform
Python for Unity is Editor-only. It doesn’t work in standalone builds.
Our integration supports Windows, Mac and Linux Unity Editors.
We started with support of Python 2.7 as many film and animation studios have not ported all their tools to more recent libraries. Python 3 support is in the works.
Feedback
We have heard your feedback, and the next 2 priorities are currently:
- Python 3.7 (yes we know we are in 2020 and Python 2.7 is end of life, but we wanted at least one public version supporting 2.7)
- Embedded Python environment
Please send us more feedback in this sub-forum for what you’d like to see in the package.
To report bugs, use the bug reporter in the Editor with a stripped down version of the project in order for our development team to reproduce the issue.