Unity
The unity plugin makes Wraith’s tools work in Unity games, on Mono or IL2CPP, with the built-in render pipeline, URP or HDRP. It goes through the game’s C# runtime and Unity’s own engine calls, so it works without knowing anything about the game.
Wraith loads it in every Unity game.
What it does
Section titled “What it does”- Camera. The free camera moves the game’s main camera, so the free camera and orbiting work without a plugin for the game.
- Posing. Posing lists the 32 characters nearest the camera. Anything with a skinned mesh is one, with the mesh’s bones as its skeleton. A body, its hair and clothes share a skeleton, so they’re one character, named after the model they’re under. New ones show up within a second or so. Their meshes’ blend shapes, like a face’s blinks and smiles, are on the Shapes tab, each listed under its mesh’s name.
- Game speed. Game speed goes through Unity’s time scale, so only gameplay changes and 0 pauses. UI and audio carry on, and the game’s own pause menus and slow motion still work underneath it.
- Ticks. Plugins’ ticks run on Unity’s main thread, where Unity’s engine calls work.
- Scene. A Scene panel in the Workbench shows the game’s GameObjects and lets you change them. See below.
Some games draw with a camera of their own rather than Unity’s, like Tales of Berseria. The free camera can’t move those through this plugin, so they need a plugin of their own.
The Scene panel
Section titled “The Scene panel”In the Workbench, the Unity tab has Scene in it, and other plugins can add tabs beside it. It’s like Unity’s own Hierarchy and Inspector. The game’s C# classes are in the Workbench’s own Classes tab.
The top half is every GameObject as a tree, inactive ones greyed out. Type in the filter to list the ones with that in their name instead. Pick one to see it in the bottom half:
- Tick the box by its name to turn it on or off.
- Transform has its local position, rotation in degrees, and scale. Drag them, or double-click to type.
- It has handles in the game too, to move, rotate or scale it, picked under Transform, along its own axes or the world’s. Open the overlay with
Insertto drag them. Otherwise they’re greyed out, and clicks go to the game. - Each component has its own fields, inherited ones too. Numbers, bools, enums, strings, vectors, quaternions and colours can be changed. Strings are set once you leave the box.
Right-click the tree for Orbit the camera round it, which hands the camera to the free camera, also on Enter, and Copy (Ctrl+C), which copies it and everything under it, one a line: its name, whether it’s on, and its components. Right-click a component for Show class, which opens it in Classes.
It only asks Unity anything while it’s open. The tree’s asked again every couple of seconds, a bit each frame so the game doesn’t stutter, and the picked object five times a second. Refresh on the right-click menu asks now.
For plugin authors
Section titled “For plugin authors”Add "unity" to your depends, then use its Unity.Unity service for the main camera and finding objects. Its schema is schemas/unity.sal in the plugin, in the Unity namespace, and the service is Unity.unity() in scripts, with Unity imported from wraith. See Sharing between plugins. For C# in general, like finding classes and calling methods, see C# games.
Unity’s main thread
Section titled “Unity’s main thread”Unity’s own methods and engine calls only work on its main thread. The plugin drives Wraith’s ticks from there, so threads.onTick runs on Unity’s main thread, once a frame as the main camera’s about to render, before the free camera moves it. You don’t need to depend on unity for that.
import { Wraith } from "wraith";
const managed = Wraith.managed();
const sub = Wraith.threads().onTick(() => { managed.invoke("UnityEngine.Time", "set_timeScale", 0, [{ kind: "number", number: 0.5 }]);});local Wraith = require("wraith").Wraith
local managed = Wraith.managed()
local sub = Wraith.threads():onTick(function() managed:invoke("UnityEngine.Time", "set_timeScale", 0, { { kind = "number", number = 0.5 } })end)fn tick(self: *Plugin) void { // On Unity's main thread _ = self;}
// in startself.sub = try sdk.threads.onTick(self, tick);var managed = Managed.Instance;
sub = Threads.Instance.OnTick(() =>{ managed.Invoke("UnityEngine.Time", "set_timeScale", 0, [new Managed.Value { Kind = Managed.ValueKind.Number, Number = 0.5 }]);});Nothing ticks till the game’s runtime is going. The service’s mainCamera() gives the main camera, a UnityEngine.Camera object, or 0 if there’s none. Use it in onTick.
Finding objects
Section titled “Finding objects”findObjectsOfType(className) is Unity’s FindObjectsOfType, from any thread. Give it a component class, like UnityEngine.Light or one of the game’s own.
import { Wraith, Unity } from "wraith";
const unity = Unity.unity();
for (const light of unity.findObjectsOfType("UnityEngine.Light")) { Wraith.log().info(`${light.name} ${light.position.x}`);}local wraith = require("wraith")local Wraith, Unity = wraith.Wraith, wraith.Unity
local unity = Unity.unity()
for _, light in ipairs(unity:findObjectsOfType("UnityEngine.Light")) do Wraith.log():info(light.name .. " " .. light.position.x)endconst schema = @import("schema");
const unity = sdk.salamander.service(schema.Unity.Unity, "unity") orelse return;for (unity.findObjectsOfType("UnityEngine.Light")) |light| { log.info("{s}", .{light.name});}var unity = Unity.Unity.Instance;var log = Log.Instance;
foreach (var light in unity.FindObjectsOfType("UnityEngine.Light")){ log.Info($"{light.Name} {light.Position.X}");}Finding them all means Unity looks through everything it has, which is slow. So each class’s answer is kept for about a second, and asked again on Unity’s main thread while anyone’s still asking. The first time you ask for a class it comes back empty, till the main thread’s asked Unity, usually the next frame.
Each one has:
| Field | What |
|---|---|
object |
The component’s C# object |
native |
Unity’s own object for it, which stays the same while it’s around |
transform, transform_native |
Its Transform, the same way |
name |
Its GameObject’s name |
position |
Where it was when Unity was last asked |
What Unity’s destroyed since is left out. Use object and transform on Unity’s main thread, from onTick. To keep one for later ticks, hold it, and check its m_CachedPtr field is still native before using it.
Game speed
Section titled “Game speed”The plugin provides game speed through Unity’s time scale. When the game sets the time scale, the plugin keeps what it asked for and puts ours on top. Reading it back gives the game its own, so a script that saves and restores it doesn’t stack ours up.
wraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
