Python for Unity

Hello everyone,

I’ve just published a plugin system for Unity, using python as scripting language.

This project implements a full plugin system with python as scripting language. You can create your own python scripts and run them on Unity. You can:

  • Run python scripts
  • Run Unity Code from python scripts
  • Use your own project classes inside the python scripts

I hope this will be helpful to someone

Regards

4 Likes

Hey @Maeslezo

This looks great!
Are you planning to maintain and extend this project? Would be great to see a kanban board, so we know what works and what doesn’t work yet.

I also have a question:
When using a scripting language for game specific logic, you often want to wait some time or for something.
So, is it possible to mimic coroutines with your Python integration? so something like:

DoSomething()
Wait(1)
DoSomethingElse()
WaitForCertainCondition()
DoTheFinalThing()

Thank you!

I am not planning to maintain and extend the project right now, because I have too much on my plate, but I’d love to accept PRs and/or re-take the project when I have more time.

I was able to run async code as you mention, so I know is doable , but I think not in this version.
The next feature I’d really want to add is virtual environments, so you don’t have to rely on the main python installation

Hi @Maeslezo ! Currently trying to build an app that utilizes a python library librosa in a py script. So, I was wondering if I could use this? To possibly call the py script on unity C# and run the py script on build standalone win 64 app?

1 Like

Hi @SirVon1299 !

So there are two different issues here.

This framework, Python for Unity is a full plugin system with python as scripting language
This means that the whole system is designed to use different custom plugins that the application users can write and use in your application, loading all the plugins and running them inside the application

In your case, if you want to use a python library, such as librosa, I suggest to use pythonnet directly, which is the library that I use under the hood
https://github.com/pythonnet/pythonnet

With this library you can use a python library in your c# code:
https://github.com/pythonnet/pythonnet#embedding-python-in-net

Using pythonnet into Unity has some caveats, so you can take my project as a example.
You can start here:
https://github.com/Maesla/PythonForUnity/tree/main/Assets/Microkernel/Python Engine System/Runtime
https://github.com/Maesla/PythonForUnity/blob/main/Assets/Microkernel/Python Engine System/Tests/Editor/PythonEngineSytemTests.cs

So, in summary, yes, you can use my project for building a build standalone win 64 that uses a python library but:

Hello,

I am very interested in what you have done. I would like to use it only for running a python script which convert .STL files into .OBJ files.

For this, I need to use the “aspose-3d” python library and execute 2 lines of code.

python code:

import aspose.threed as a3d
scene = a3d.Scene.from_file("test.stl")
scene.save("test.obj")

What do I need to make it work with your package. Since there are many addons, plugins etc, I don’t know what to extract to take the strict necessary things without installing additional packages will not be used.

Thank you in advance.

If you want to use strictly the core functionality, I recommend just use directly pythonnet. My system is built on top of it
https://github.com/pythonnet/pythonnet

If you have doubts how to make it work, you can download and use my project as template
You can take a look at the python engine tests

Thank you for your answer. I am gonna have a look at this.

And very nice job for your package, it is pretty nice.

1 Like

hello I am having issues importing nltk library, for some reason during runtime the libraries are erased. I mostly wanna do this so I can build my project as a webgl, thank you so much