GitHub - shiena/Unity-PythonNet
Repository navigation
Unity-PythonNetPublic
About
zenn.dev/shiena/articles/unity-pythonTopics
csharp python pythonnet unity unity3dResources
Readme MIT license ActivityStars
41 starsWatchers
1 watchingForks
5 forks Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
49 Commits
View commit history for this file.
Folders and files
| Name | Name | Last commit message | Last commit date |
|---|---|---|---|
| Assets | Assets | ||
| Documents~ | Documents~ | ||
| Packages | Packages | ||
| ProjectSettings | ProjectSettings | ||
| .gitignore | .gitignore | ||
| LICENSE | LICENSE | ||
| README.md | README.md | ||
Repository files navigation
Unity-PythonNet
Development Environment
- Windows
- Unity6000.3.5f1 (.NET Framework or both .NET Standard 2.1 and Microsoft.CSharp is required at Api Compatibility Level)
- Python.NET 3.0.5
- Python Embeddable Package 3.11.3
What is this?
This is a sample project that integrates Unity and Python.NET. Pressing the Plot button will display an image of a graph drawn using matplotlib in Python.
Project Structure
+ Assets/
+ Scenes/
+ SampleScene.unity : Main scene using Unity UI
+ MainView.unity : Main scene uning UI Toolkit
+ Scripts/
+ PythonLifeCycle.cs : Python.NET initializer
+ PlotRandom.cs : Call python script from C# using Python.NET for Unity UI
+ UIEventHandler.cs : Call python script from C# using Python.NET for UI Toolkit
+ Plugins/
+ Microsoft.CSharp.dll : Need for .NET Standard 2.1
+ StreamingAssets/
+ python-3.11.3-embed-amd64/ : python runtime
+ myproject/
+ plot_random.py : python script for graph plot
+ requirements.txt : a list of items to be installed using pip install
How to add python packages
cd Assets\StreamingAssets\python-3.11.3-embed-amd64\ .\Scripts\pip.exe install matplotlib .\Scripts\pip.exe freeze > myproject\requirements.txt
Editor Settings: Enter Play Mode Options
Both Domain Reload enabled and disabled are supported with fast Play/Stop.
Domain Reload Enabled
| Pros | Cons |
|---|---|
| Fast Play mode stop | Slightly slower Play mode start |
| Python code changes are reflected | - |
| Clean Python state on each Play | - |
Domain Reload Disabled
| Pros | Cons |
|---|---|
| Fast Play mode start | Python global state is preserved |
| Fast Play mode stop | - |
| Python code changes are reflected (via module reload) | - |
Settings: Edit → Project Settings → Editor → Enter Play Mode Options
Known Issues
PythonEngine.PythonPathis not applied when changing a differentPythonEngine.PythonPathafter callingPythonEngine.Initialize()/PythonEngine.Shutdown().- Restart Unity if you want to set a different
PythonEngine.PythonPath.
- Restart Unity if you want to set a different