You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] Modification to do if you want a SofaUnity25.12 build with Python scenes #255
If you are trying to do a unity build with SofaUnity for sofapython scene usage you must :
in the build go to this file : YourBuild\YourBuild_Data\Plugins\x86_64\python3\site-packages\Sofa\ __int__.py
then go to line 160-170 and replace sys.stdout.flush()
by
if sys.stdout is not None:
sys.stdout.flush()
if sys.stderr is not None:
sys.stderr.flush()
I applied the fix described here in the Sofa init.py shipped with SofaUnity v25.12, but Unity Editor still shuts down silently when SofaPython3.dll is loaded. This is on the Editor side (not a build), same symptom as @BinhTran17 reported in discussion #216.
Environment:
Windows 11
Unity 6000.0.51f1 (URP)
SofaUnity-URP v25.12 (public release 2026-03-20)
Python 3.13.12 (user install, no admin rights needed)
What I've tried on top of the flush fix:
Copied python313.dll and python3.dll into Assets/SofaUnity/Core/Plugins/Native/x64/ (verified SofaPython3.dll links against python313.dll via binary strings)
Patched Sofa/init.py with os.add_dll_directory() pointing to Native/x64/ (since the original code looks for <SOFA_ROOT>/bin/ which doesn't exist in SofaUnity's layout)
Renamed SofaImGui.cp313-win_amd64.pyd, SofaGLFW.cp313-win_amd64.pyd, and Sofa/Gui.cp313-win_amd64.pyd to .DISABLED to avoid OpenGL context conflicts with Unity
Set PYTHONHOME and PYTHONPATH env variables in a launch .bat
Also tried python313._pth alongside python313.dll
Verified sys.stdout/stderr handling with a sitecustomize.py
Symptom: Unity Editor closes as soon as SofaPython3 is loaded (either via checkbox in SofaContext Plugin List, or when selecting a .py scene). No crash dump generated. Editor.log shows the loading of the other SOFA plugins (InfinyToolkit.dll, BeamAdapter.dll are the last loaded) then nothing — no # Sofa Log: Initializing with python version 3.13.12 message ever appears, meaning Py_Initialize() is never reached or crashes before writing anything.
XML .scn scenes work perfectly, including the LiverInteraction demo. Only Python integration is broken.
Is there any additional setup step required, or is this a known regression in v25.12? Any minimal working example demonstrating Python scene loading in Unity Editor with v25.12 would help enormously.
Hi,
you should not copy new dll in the x64 folder nor change the sofa.ini files.
All the python files and dll that are in there are made to work together inside the Unity environment and some variables are already passed to SofaPython3 to find the good SOFA sites packages that are in /x64/python3/site-packages/
What you need to check is to remove any path in your environment paths that would point to another version of SOFA and SofaPython3
Also the package has been done using python 3.13.3 this might be the problem.
Activity
PierreFonda3D commentedon Jun 3, 2026
Important note for the build you must check the SofaPython3 option :
azizsnd commentedon Sep 2, 2026
Hi @PierreFonda3D @epernod,
I applied the fix described here in the Sofa init.py shipped with SofaUnity v25.12, but Unity Editor still shuts down silently when SofaPython3.dll is loaded. This is on the Editor side (not a build), same symptom as @BinhTran17 reported in discussion #216.
Environment:
Windows 11
Unity 6000.0.51f1 (URP)
SofaUnity-URP v25.12 (public release 2026-03-20)
Python 3.13.12 (user install, no admin rights needed)
What I've tried on top of the flush fix:
Copied python313.dll and python3.dll into Assets/SofaUnity/Core/Plugins/Native/x64/ (verified SofaPython3.dll links against python313.dll via binary strings)
Patched Sofa/init.py with os.add_dll_directory() pointing to Native/x64/ (since the original code looks for <SOFA_ROOT>/bin/ which doesn't exist in SofaUnity's layout)
Renamed SofaImGui.cp313-win_amd64.pyd, SofaGLFW.cp313-win_amd64.pyd, and Sofa/Gui.cp313-win_amd64.pyd to .DISABLED to avoid OpenGL context conflicts with Unity
Set PYTHONHOME and PYTHONPATH env variables in a launch .bat
Also tried python313._pth alongside python313.dll
Verified sys.stdout/stderr handling with a sitecustomize.py
Symptom: Unity Editor closes as soon as SofaPython3 is loaded (either via checkbox in SofaContext Plugin List, or when selecting a .py scene). No crash dump generated. Editor.log shows the loading of the other SOFA plugins (InfinyToolkit.dll, BeamAdapter.dll are the last loaded) then nothing — no # Sofa Log: Initializing with python version 3.13.12 message ever appears, meaning Py_Initialize() is never reached or crashes before writing anything.
XML .scn scenes work perfectly, including the LiverInteraction demo. Only Python integration is broken.
Is there any additional setup step required, or is this a known regression in v25.12? Any minimal working example demonstrating Python scene loading in Unity Editor with v25.12 would help enormously.
Thank you very much for your work.
epernod commentedon Sep 13, 2026
Hi,
you should not copy new dll in the x64 folder nor change the sofa.ini files.
All the python files and dll that are in there are made to work together inside the Unity environment and some variables are already passed to SofaPython3 to find the good SOFA sites packages that are in /x64/python3/site-packages/
What you need to check is to remove any path in your environment paths that would point to another version of SOFA and SofaPython3
Also the package has been done using python 3.13.3 this might be the problem.
Best regards