Skip to main content

MechanicsDSL Logo

mechanicsdsl-unity

Physically accurate simulation components for Unity and Unreal Engine, compiled from DSL notation.

Active Unity 3 Components MIT License Core Package

Overview

mechanicsdsl-unity provides Unity MonoBehaviour components generated from MechanicsDSL DSL specifications. All components bypass PhysX with Lagrangian equations of motion, include Noether-based energy monitoring, and expose parameters in the Unity Inspector for real-time tuning.


Components

Classical Mechanics

Component System Conserved Gizmos
PendulumComponent Simple pendulum Energy (Noether) Pivot, rod, bob
DoublePendulumComponent Double pendulum (chaotic) Energy (Noether) Full double pendulum
CoupledPendulumsComponent Coupled pendulums Energy (Noether) Both pendulums + spring

Utilities

Component Description
ConservationMonitor On-screen HUD for energy drift across any MechanicsDSL component
PhaseSpaceTrail Renders θ vs ω phase portrait as a LineRenderer trail
MechanicsDSLMath Generic RK4, symplectic Euler, angle wrap, bob position helpers

Editor

Script Description
PendulumComponentEditor Live state readout (θ, ω, t, E, |ΔE/E₀|) + Reset button
DoublePendulumComponentEditor Dual-angle live readout + Reset button

Repository Structure

mechanicsdsl-unity/
├── Runtime/
│   ├── Components/
│   │   ├── PendulumComponent.cs
│   │   ├── DoublePendulumComponent.cs
│   │   └── CoupledPendulumsComponent.cs
│   ├── Utilities/
│   │   ├── ConservationMonitor.cs
│   │   ├── PhaseSpaceTrail.cs
│   │   └── MechanicsDSLMath.cs
│   └── com.mechanicsdsl.unity.runtime.asmdef
├── Editor/
│   ├── PendulumComponentEditor.cs
│   ├── DoublePendulumComponentEditor.cs
│   └── com.mechanicsdsl.unity.editor.asmdef
├── Tests/Runtime/
│   ├── TestPendulumEOM.cs
│   ├── TestDoublePendulumEOM.cs
│   └── MechanicsDSL.Tests.Runtime.asmdef
├── Samples~/
│   ├── SimplePendulum/README.md
│   └── DoublePendulum/README.md
├── docs/
│   ├── getting_started.md
│   ├── components_reference.md
│   └── adding_systems.md
└── package.json                (UPM manifest)

Installation

Via UPM (Unity Package Manager):

  1. Open Window → Package Manager
  2. Click + → Add package from git URL
  3. Enter: https://github.com/MechanicsDSL/mechanicsdsl-unity.git

Quick Start

  1. Add MechanicsDSL → Classical → Pendulum to any GameObject
  2. Create a Sphere child and drag to Bob Transform
  3. Press Play — the sphere is driven by MechanicsDSL-generated Lagrangian equations

The Inspector shows live θ, ω, E, and |ΔE/E₀| during Play Mode. Click Reset to return to initial conditions without stopping.


Running Tests

Window → General → Test Runner → PlayMode → Run All

Tests cover energy conservation (5–10 s), reset/initial conditions, equilibrium stability, and bob Transform updates.


Generating New Components

pip install mechanicsdsl-core
mechanicsdsl-unity generate my_system.msl --target unity --out Assets/Physics/

The mechanicsdsl-unity CLI compiles any .msl spec (or core preset) through mechanicsdsl-core and writes engine code that integrates the derived equations of motion with RK4:

pip install mechanicsdsl-unity
mechanicsdsl-unity targets
mechanicsdsl-unity generate double_pendulum --target unity  -o Assets/Generated/
mechanicsdsl-unity generate double_pendulum --target godot  -o scripts/
mechanicsdsl-unity generate double_pendulum --target unreal -o Source/MyGame/
mechanicsdsl-unity generate double_pendulum --target csharp -o lib/
mechanicsdsl-unity generate --all-presets --target unity -o Assets/Generated/
mechanicsdsl-unity inspect double_pendulum
Target Output What you get
unity <Cls>Component.cs MonoBehaviour: Inspector parameters, sub-steps, pause, GetState/SetState, live energy and energyDrift, OnStateUpdate event
csharp <Cls>Dynamics.cs engine-free .NET class (C# 5 syntax) for Godot C#, MonoGame, Stride, servers
godot <system>_dynamics.gd Godot 4 GDScript Node: @export parameters, state_updated signal, energy_drift
unreal <Cls>Dynamics.h, <Cls>Component.h/.cpp UE5 Blueprint-spawnable UActorComponent + engine-free C++17 dynamics

How generated code is checked

The standalone C# is compiled (csc or the .NET SDK, warnings as errors), run for 1000 RK4 steps and compared with a Python RK4 reference to 1e-12. The Unity component is compiled against a minimal UnityEngine stub, and the Unreal component against a minimal Unreal API stub with g++ -Wall -Wextra -Werror, then ticked to check energy drift. GDScript expressions are evaluated numerically against SymPy. These checks do not replace testing inside the real editors, which the test suite cannot run.

See docs/adding_systems.md for the full workflow.


Contributing

See CONTRIBUTING.md.

License

MIT License; see LICENSE.

Metadata

Release files for mechanicsdsl-unity 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mechanicsdsl-unity 0.2.0
File Size Uploaded Provenance Actions
mechanicsdsl_unity-0.2.0.tar.gz 45.2 kB With provenance Details for mechanicsdsl_unity-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mechanicsdsl-unity 0.2.0
File Interpreter ABI Platform Actions
mechanicsdsl_unity-0.2.0-py3-none-any.whl Python 3 none any Details for mechanicsdsl_unity-0.2.0-py3-none-any.whl

Total release size: 71.9 kB

Release files / mechanicsdsl_unity-0.2.0.tar.gz

Download URL mechanicsdsl_unity-0.2.0.tar.gz
Size 45.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c02b8c0b78bf9235e566ae1e8490979386ebca5b1b5d0af367e7dfea30dc9bb7
BLAKE2b-256 checksum
How to use checksums
3ae4871d53059b75c40523b25d0516181c513d4faabe903f8e6781c5b170508a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / mechanicsdsl_unity-0.2.0-py3-none-any.whl

Download URL mechanicsdsl_unity-0.2.0-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de371806b4ee507730bf9f541906072da69a6f7ec9b158bfc13df1a422154481
BLAKE2b-256 checksum
How to use checksums
55e29f3f5fb0ac139113bae649f49271eb0359b461e916839d531fd5c6772d30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for mechanicsdsl-unity 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mechanicsdsl_unity-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page