Documentation

C# Scripting

Experimental managed C# scripting via Mono/.NET runtime embedding.

Warning

C# scripting is experimental and has a minimal API surface. It is intended for movement/transform tests and simple Rigidbody control.

Overview

Modularity can host managed C# scripts via the .NET runtime. This is an early, minimal integration intended for movement/transform tests and simple Rigidbody control.

The managed API surface is tiny for now: position/rotation/scale, basic Rigidbody velocity/forces, settings, and console logging.

Managed project files are under Scripts/Managed (separate from Assets/Scripts used for native scripts).

Setup

  1. Build the managed project (this now happens automatically when you compile a C# script): dotnet build Scripts/Managed/ModuCPP.csproj
  2. In the Inspector, add a Script component and set:
    • Language = C#
    • Assembly Path = Scripts/Managed/bin/Debug/netstandard2.0/ModuCPP.dll (or point at a .cs file in Scripts/Managed/)
    • Type = ModuCPP.SampleInspector
  3. Enter play mode. The sample script will auto-rotate the object.

Requirements

  • The ModuCPP.runtimeconfig.json produced by dotnet build must sit next to the DLL.
  • The managed host currently expects the script assembly to also contain ModuCPP.Host (use the provided Scripts/Managed/ModuCPP.csproj as the entry assembly).
  • Requires Mono runtime support in the engine build plus dotnet to compile the managed project. If runtime setup is missing, the engine will fail to initialize managed scripts and report the error in the inspector.

Hook Exports

Managed hooks are discovered by method name (Script_Begin or Begin, Script_TickUpdate or TickUpdate, etc.) with signatures that accept a context pointer and optional delta time.

Mono Embedding

This project uses Mono embedding for managed (C#) scripts.

Expected Layout (Vendored)

src/ThirdParty/mono/text
include/mono-2.0/
lib/ (or lib64/) with mono-2.0-sgen library
etc/mono/ (config files)
lib/mono/4.5/ (framework assemblies)

Runtime Override

You can override the runtime location at runtime with:

MODU_MONO_ROOT=/path/to/mono

Build Notes

  • The CMake cache variable MONO_ROOT controls where headers/libs are found.
  • Managed scripts target netstandard2.0 and are built with dotnet build.