ScriptEngine
The ScriptEngine
component is the core of OneJS. It manages interop between C# and JS (via Jint) and provides the DOM implementations needed by Preact. Below are the settings you can set on the component, divided into 3 categories: Interop, Assets, and Security.

Interop
Settings under Interop are generally about what features from C#/.Net you want to expose to Javascript.
- Assemblies: List of Assembly names you want to access from Javascript. (i.e.
"UnityEngine.CoreModule"
and"Unity.Mathematics"
) - Extensions: List of Extension names you want to access from Javascript. (i.e.
"UnityEngine.UIElements.PointerCaptureHelper"
) - Namespaces: You can map C# namespaces to JS module here. (i.e.
"UnityEngine.UIElements" => "UnityEngine/UIElements"
) - Static Classes: Map C# static classes to JS module. (i.e.
"Unity.Mathematics.math" => "math"
) - Objects: Map a MonoBehaviour component to JS module. Note you can drag a Component to the slot, but you can probably only do so by locking the
ScriptEngine
Inspector and opening a new Inspector Tab for the target MonoBahaviour. (i.e."MaterialManager" => "matman"
)
Assets
The settings under Assets mostly contain templates or default files for OneJS to use, such as tsconfig.json
and settings.json
. So You don't really need to touch any of that. The only thing you may want to add are the Style Sheets (USS).
Security
ScriptEngine
provides the following security settings for you to set in the Inspector.
- Allow Reflection
- Allow
GetType()
- Memory Limit
- Timeout
- Recursion Depth
These are some of the security settings exposed directly from Jint. To set more granular security measures such as Member Accessor & TypeResolver, you can do so during the OnPostInit
event (refer to the event API below).
ScriptEngine APIs
ScriptEngine
exposes some public APIs for you to use from code.
Properties
public Engine JintEngine; // Internal Jint Engine
public Dom DocumentBody; // Dom for document.body
Events
public event Action OnPostInit; // Happens after every ScriptEngine reload
public event Action OnReload; // Happens when ScriptEngine is just about to reload
Methods
public void RunScript(string scriptPath); // Run a script as is
public void ReloadAndRunScript(string scriptPath); // Reloads the ScriptEngine and then run a script
public void RegisterReloadHandler(Action handler); // Sub to the OnReload event and will automatically unsub during reload. Useful for the Live Reload workflow