Use the /collab command on Discord to gain access to the OneJS private repo. The repo offers early access to the latest features and fixes that may not yet be available on the Asset Store. An early preview of OneJS V2 is available on branch onejs-v2. It brings major performance improvements, zero-allocation interop, and a new esbuild workflow.
VERSION
Doc Menu

Requirements

  • Unity.Mathematics
  • Unity Version 2021.3+ (for stable UI Toolkit)
  • Unity Version 2022.1+ (if you need to use UI Toolkit's Vector API)

Also Live Reload requires Run in Background to be turned ON in Player settings (under Resolution and Presentation). Depending on your Unity version or platform, this may or may not be ON by default. So it never hurts to double-check.

Quick Start

After downloading and importing OneJS from the Asset Store. You can just

  • Drag and drop the ScriptEngine prefab onto a new scene.
  • Enter Play mode.

In the console, if you see [index.js]: OneJS is good to go., then OneJS is all set. You can now move on to Tutorial 101 for a step-by-step guide on writing your first script.

If you are already experienced with Unity, Typescript, and (P)React, you can also just skip to the included sample scenes to see how Preact and UI Toolkit work together. (The script(s) responsible for the sample scenes are located under {ProjectDir}/OneJS/Samples.)

More Info

OneJS uses {ProjectDir}/OneJS as its working directory (NOTE: {ProjectDir} is not your Assets folder; it is one level above the Assets folder). So, you can safely check the OneJS folder into Version Control. When building for standalone, the scripts from {ProjectDir}/OneJS will be automatically bundled up and be extracted to {persistentDataPath}/OneJS at runtime. Refer to the Deployment page for more details on that.

The first time ScriptEngine runs, it will set up a few things automatically under {ProjectDir}/OneJS. These are:

  • A default tsconfig.json
  • A default .vscode/settings.json
  • A default index.js script (that just logs something to the console)
  • ScriptLib folder containing all the Javascript library files (and TS definitions) that are used by OneJS.
  • Samples folder containing some sample code you can look at.

These folders and files will be auto-generated if deleted. Sometimes it maybe helpful to manually delete them when upgrading major OneJS versions.

VSCode

{ProjectDir}/OneJS is the folder to open when using VSCode. Typescript (.ts and .tsx) is the recommended language to use with OneJS. To have VSCode continuously transpile TS to JS in watch mode, use Ctrl + Shift + B or Cmd + Shift + B and choose tsc: watch - tsconfig.json.

Do make sure that you have Typescript installed on your system (i.e. via npm install -g typescript)

You can, of course, just use plain .js and .jsx files as well. But do note that by default OneJS only support CommonJS modules (i.e. require() and module.exports). So if you want to use ES modules (i.e. import/export statements), Typescript is the way to go.

The default .vscode/settings.json will enable Explorer File Nesting for you, as well as some PowerShell settings for better usage on Windows.