I mixed all the info with an AI tool here:Sure, I'd love to hear it. Maybe you've got a cool idea I haven't thought of.
Markdown (GitHub flavored):
# Patch ideas
Notes for an independent developer working on their own VaM project. They describe
engine behaviour of Virt-a-Mate 1.25 + EVO patch, the approaches that were investigated
against that build, and the measured results. The facts come from the decompiled EVO
assembly and from in-game measurements. Nothing here depends on a particular patch
project, its file layout or its build pipeline: the unit of integration is a
recompiled `Assembly-CSharp.dll`.
Status markers: **WORKS (measured)**, **REJECTED (measured)**.
---
## 1. Startup time: the built-in sound bundles
### 1.1 Why startup is slow
At startup the game loads a dependency closure that includes six sound bundles:
`s_fem`, `s_mus`, `s_mus_cyb`, `s_per`, `s_sfx`, `s_toy` — about 478 MB on disk.
The problem is not the file size but the import setting of their AudioClips:
they are `DecompressOnLoad` (`m_LoadType = 0`), so Unity expands the entire
Vorbis stream into PCM at the moment the AudioClip object is created. The decode
is single-threaded, roughly 100 MB/s.
| Bundle | Clips | `DecompressOnLoad` | PCM decoded at load | Content |
|---|---|---|---|---|
| `s_mus` | 23 | 7 (tracks 430–484 s long) | ~1070 MB | DJ mixes, category `Music` |
| `s_mus_cyb` | 39 | 39 (loops 7–53 s) | ~351 MB | cyberpunk tracks, `Music` |
| `s_fem` | 275 | 275 (1–6 s each) | ~420 MB | `FemaleBreath`, `FemaleMoan`, `FemaleScream`, `FemaleSexLong` |
| `s_sfx` | 11 | 11 | ~81 MB | UI sounds (`hifi_button`), `SoundFXClick`, `SoundFXSex`, `SoundFXWater` |
| `s_per` | 6 | 6 | ~35 MB | kisses, `PersonOral` |
| `s_toy` | 2 | 2 | ~13 MB | vibrators (`Toys`) |
| **Total** | **356** | | **~1970 MB** | |
This decoding accounts for roughly **19.6 s of the 21.5 s** spent creating the
`z_cor` assets at startup.
### 1.2 What works: cut only the startup dependency edges — WORKS (measured)
In `AssetBundleManager.LoadDependencies`, remove those six bundle names from the
dependency lists of the **startup bundles only** (`z_cor`, `a_vie`, `a_mis`).
The global dependency graph must stay untouched: an atom that genuinely needs
`s_sfx` (for example `a_apt`, `a_ols`) still resolves it normally.
The startup prefab references the clips through
`EmbeddedAudioClipManager.embeddedClips[].sourceClip`. With the edges cut, those
references stay unresolved at startup, so Unity never creates the AudioClip
objects and never performs the decode.
Measured result:
| Step | Before | After |
|---|---|---|
| `z_cor` asset creation | 21.5 s | 1.86 s |
| First frame | ~21.5 s | 4.25 s |
### 1.3 Consequences and traps
- **All built-in sounds stop working**: music, character breathing, UI clicks,
water, and so on — 332 entries in total. In the Audio Manager they remain as
dead entries in the "Embedded" category (`sourceClip == null`).
- **External audio is not affected.** Files loaded through `URLAudioClipManager`
(the "Scene Audio" tab) come from disk and still work. Do not remove the
`AudioManagers` object from the prefab: besides `EmbeddedAudioClipManager` it
carries `URLAudioClipManager` and the external-file decoder
(`HelloMeow.BassImporter`).
- If the dead list is removed with `AudioClipManager.RemoveAllClips()`, be aware
that this method ends with `SuperController.ValidateAllAtoms()`. Before
`InitAtoms()` the `atomsList` is still `null`, so the call throws a
`NullReferenceException`. If it throws inside the instantiation coroutine of
the CoreControl prefab, the coroutine dies before parenting the prefab to the
atom container: the CoreControl atom is never registered and the scene comes
up without its core (camera, navigation, scene plugins), with the log message
`Atom type CoreControl does not exist. Cannot add`. Call it at the very end of
`Start()`, after `InitAtoms()`.
- On any change to bundle loading, keep the engine's plugin security checks
intact. The `DynamicCSharp_Settings` asset bans `MVR.FileManagement` exactly
("Security Check Failed (NamespaceRestriction)"); `MVR.FileManagementSecure`
is not banned. Changing bundle contents or names must not disturb that setup.
### 1.4 Other startup costs — development convenience only
> **These items are only useful for development setups where a very fast start
> matters** (repeated restarts while iterating on a scene or a plugin). They are
> **not for end users**: each one trades away content or requires a manual step.
- **Package scan.** `SuperController.SyncToKeyFile()` → `FileManager.Refresh()`
runs at the end of `SuperController.Awake()` and blocks the main thread for
about 6.1 s on a ~25GB library. It can be skipped with a command-line switch;
the price is that session plugins and scene content living in `.var` packages
are not available. The scan is also available on demand ("Rescan Packages",
key sync in the options).
- **Embedded browser and hub.** The CoreControl prefab carries three
`BrowserGUI` objects and the hub objects (`HubBrowseController`,
`HubDownloader`). Deactivate them in the **prefab asset**, before
instantiation, then destroy the inactive shells of the instance. `Awake` only
runs on active objects, so the hub never creates its ~50 `JSONStorable`
objects, its `FileManager.RegisterRefreshHandler` or its permanent
`DownloadRoutine`. The browser canvases are inactive anyway, so no Chromium
instance is created and `zf_cef.dll` (~105 MB) stays out of the process.
Deactivating them in the asset matters: a later instantiation (hard reset)
then inherits the deactivated objects.
- **Direct scene load.** A `-scene <name>` command-line switch can skip the
start screen (`TopWorldUI`) and load a scene directly. Resolve the name against
`Saves\scene` (bare name gets `.json`, a name with a path separator is relative
to the game folder, an absolute path is used as-is), skip `DelayStart()`, and
run a plain coroutine that waits four frames before `StartScene()`, so the HUD
and the atom pool exist. Load in play mode.
- **Where a scene load actually spends its time.** With a character, a scene
load takes about 26 s: `OptimizeMemoryUsage` 1.0 s, Person asset load 7.5 s,
Person `AddAtom` 7.0 s, other atoms 4.5 s, restore of the appearance from
packages 5.7 s. The cost is Unity's deserialization of the `a_per` prefab
(4913 GameObjects: ~3920 inactive UI objects, ~993 active ones with ~1900
physics components) and the initialization of the DAZ character — not the
asset bundles. `LoadDependencies` only *maps* bundles; the assets are read
when a prefab refers to them. A prefab cached by `GetCachedPrefab` also avoids
paying the ~7 s asset load again when a scene is reloaded inside the game.
### 1.5 Negative results — development convenience only
> As above: relevant only when a very fast startup is worth sacrificing content
> or correctness. End users should never be exposed to these.
- Cutting 654 MB out of the scene-load closure (the eyes `p_eye_mat`, six hair
types `h_*_mat`, the skin types `m_*`) made the load only **0.2 s** faster:
those assets come from the appearance packages, not from the built-in bundles.
- Cutting `h_omr_mat` broke the hair of a scene whose hair came from a package
but referenced the built-in Omri scalp material.
---
## 2. Frame pacing, background pausing and the camera preview
Source of both items: the published `VideoRecorderHelper` plugin
[(https://hub.virtamate.com/resources/videorecorderhelper.55784/)].
They are independent of each other; only the first one is somebody else's idea.
### 2.1 Put the frame-rate and background settings into the game's options panel
**Attribution: this part is a copy of FrameRateControl by MacGruber** (plugin header:
v0.1 2019-09-22, v0.5 2021-01-16). Nothing here is a new idea — the direction is to
take functionality that already exists in that plugin and move it into the game's own
settings UI, so that no scene plugin has to be loaded to get it.
The three settings map directly to Unity fields:
| Setting | Effect |
|---|---|
| `pauseInBackground` | Pause the game when the window is not focused, by driving `Application.runInBackground`. |
| `useFrameRateCap` | `Application.targetFrameRate = Mathf.RoundToInt(targetFrameRate.val)` when enabled, `-1` when disabled. |
| `targetFrameRate` | The cap itself: default 30, range 20–144, whole numbers; a slider change is applied after a 0.3 s debounce. |
> **Warning — `Application.runInBackground` has to be handled together with
> `pauseInBackground`.** Switching it off as soon as the window loses focus also
> stops **scene loading**: if the game window is inactive while a scene is being
> loaded, the load simply does not advance. The game must keep running in the
> background for the whole load. The plugin uses an `isLoadingClock` grace period:
> it watches `SuperController.singleton.loadingIcon` and `loadingUI`, starts a
> ~1 s clock while either is active, and keeps
> `Application.runInBackground = !pauseInBackground.val || isLoadingClock > 0`.
> Any engine-level implementation must preserve that behaviour, and restore
> `runInBackground = true` when the setting is turned off or the plugin is disabled.
Interaction with VSync: enabling the frame cap forces VSync off
(`QualitySettings.vSyncCount = 0` and `UserPreferences.singleton.desktopVsync =
false`), because a fixed target frame rate and VSync fight each other; disabling
the cap restores `QualitySettings.vSyncCount = UserPreferences.singleton.desktopVsync
? 1 : 0`. The original plugin additionally exposes more VSync modes
(Off / On / Half / 1/3 / 1/4 via `vSyncCount` 0..4), but those are outside the
three settings named here. All of it is desktop-only: the plugin skips these
settings entirely when an XR device is active, and restores the default Unity
values when disabled.
Engine context, useful for integrating this properly: EVO already sets
`Application.targetFrameRate = 300` in `SuperController.DetermineVRRig()`, so an
implementation must read the live value at init rather than assume a default.
`UserPreferences` already has a persisted `desktopVsync` property with a UI toggle
and JSON save/load — that is the natural pattern for storing the new settings.
### 2.2 The camera preview keeps rendering after the camera is switched off — our own research
**Status: our finding, with a working but crude workaround in the plugin; the
proper engine-side fix has not been implemented and the root cause has not been
confirmed.** This is not inherited from FrameRateControl.
Every scene contains a `WindowCamera` atom that cannot be removed through the UI.
Switching the camera off through its own control does **not** stop all rendering:
the floating preview panel that follows the camera keeps rendering anyway.
Turning that preview off as well was observed to **almost double the FPS** in
desktop mode.
Evidence from the EVO decompile and the plugin:
- `CameraControl.SyncCameraOn(bool)` calls `SyncCameraOnAndUseAudioListener()`,
which only deactivates `cameraGroup` and `otherObjectToControl` (and updates the
audio listener). The preview objects are not in that list, which is consistent
with the observation that the preview survives the camera toggle.
- The plugin reaches those objects by string path from
`GlobalSceneOptions.singleton.atomContainer`:
`WindowCamera/reParentObject/object/rescaleObject/CameraGroup/MiniCamera`,
`WindowCamera/reParentObject/Display` and
`WindowCamera/reParentObject/DisplayControl`; it calls `SetActive(value)` on all
three and reads the current state from `MiniCamera.activeSelf`.
Why the plugin approach is coarse, and what a patch could improve:
- the path lookup is fragile and is applied once at plugin start (to restore a
saved value); there is no hook to the camera's own UI toggle and no re-evaluation
when a scene is loaded or unloaded;
- it is global for the whole session rather than being a property of the camera
atom;
- on scene unload a `Debug.Log` appears, complaining that a coroutine could not be
started — presumably one belonging to an object that was deactivated. Nothing
actually breaks, but it suggests the deactivation is too broad or happens at the
wrong point in the lifecycle.
Direction to investigate: make the preview chain follow `cameraOn` (or expose a
real setting on the camera atom) so that switching the camera off really stops all
of its rendering; re-evaluate on scene load/unload instead of once; replace the
path strings; and find which object's coroutine produces the message on unload so
it can be shut down cleanly. The decompile above is supporting evidence, not a
proven root cause.
---
## 3. HUD anchors and camera motion (weak-CPU-only issue)
**Scope.** This matters only on very weak CPUs such as the Xeon(R) E5-2680 v3. On
another system with a Ryzen 5 5600 the FPS drop while moving the camera is at most
about 5 %. It is the most complex direction here and the least useful for most
users.
### 3.1 Measurements
On the Xeon, simple scene, ~170 FPS maximum, `physicsRate 60`, cap 1. The angle
brackets are the built-in PerfMonitor report `<FPS, render, script, physics>`, the
three times in milliseconds:
| Variant | Rig held | Rig moving |
|---|---|---|
| FPS unlimited, UI present | `<170, 0.70, 1.25, 1.65>` | `<70, 0.85, 1.59, 3.9>` |
| FPS unlimited, UI hidden | `<182, 0.69, 1.42, 1.54>` | `<180, 0.70, 1.24, 1.55>` |
| FPS capped at 60, UI present | `<60, 0.8, 1.28, 4.56>` | `<60, 0.97, 1.68, 4.93>` |
| FPS capped at 60, UI hidden | `<60, 0.79, 1.13, 4.72>` | `<60, 0.79, 1.13, 4.67>` |
With the UI hidden, moving the rig costs nothing. Earlier measurements on the same
CPU gave ~180 FPS with the rig still, 46 FPS while moving with the full HUD open,
70 with `Canvas.enabled = false`, 180 with the HUD frozen in world and 180 with the
HUD object deactivated (`F1`). Roughly 110 of the 134 lost FPS is the
transform/matrix invalidation; about 24 is the drawing itself. The camera-preview
cost from Section 2.2 is separate and additive (116/100/51 → 171/162/61 with it
off).
**Important nuance about "UI complexity".** The HUD consists of three elements:
the label row and the button palette are constant and never change; only the main
menu varies, because it depends on the selected atom — a character has ~40 tabs,
a simple atom ~5. Opening the menu costs a lot (180 → 110 → 46 FPS as elements are
added), but the drop does not change between the 40-tab and the 5-tab version of
that menu. That is the argument for a structural fault in the anchor/follower
setup, not for the sheer number of widgets.
### 3.2 Engine evidence for the cause
The HUD is a world-space UGUI canvas. It is **not** parented under `navigationRig`:
the topmost node under the rig is `CameraRig`, and what follows the camera is a set
of `HUDAnchor` references applied by `MoveAndRotateAsHUDAnchor` in `LateUpdate`.
Component counts found in the subtree: 87 `MoveAndRotateAsHUDAnchor`,
23 `MoveAndRotateAs`, 14 `LookAtCamera`.
The writer chain is `SuperController.ProcessUIMove()` → `MoveMainHUD()` plus
`HUDAnchor.SetAnchorsToReference()`, then the late followers
`MoveAndRotateAsHUDAnchor.LateUpdate`, `LookAtCamera.Update` and
`MoveAndRotateAs` / `MoveAndRotateAsBatch`. Every rig write moves these transforms
and invalidates every `Graphic` in their subtrees: world matrices, culling and
sorting are recomputed. The cost tracks the widgets being invalidated, not the
pixel count — window size and MSAA have no effect.
Diagnostics must cover two roots: `SuperController.transform` (lower HUD, monitor
rig, main-menu shell; the lower HUD is reachable only by its literal path
`WorldScaleAdjust/HUD/LowerHUDPivot/LowerHUDFlip/...`) and
`GlobalSceneOptions.singleton.atomContainer`, where the per-atom options panels and
MVR plugin UIs live because VaM parents `MVRPluginManager` under the atom.
Already tested and rejected: adding a value comparison to the unconditional
`localScale` write in `MoveAndRotateAsHUDAnchor.LateUpdate`. The patch was built
and measured in game with no perceptible difference — Unity's `Transform` setters
already skip the dirty propagation when the assigned value is unchanged. Do not
repeat that experiment. Also ruled out by measurement: physics (fixed-step cost is
flat; the PerfMon `Physics` number rises only because more steps run per frame),
fill rate, MSAA, the `overlayUI` "Draw UI on Top" shader swap (it changes panel
material depth testing, not the render mode) and raycasting (disabling every
`GraphicRaycaster` removes the steady cost of having UI open, not the movement
penalty).
### 3.3 Direction A — make the whole HUD true 2D
**Status: attempted. The FPS goal was reached in measurement, but the approach was
halted because layout and scale fidelity could not be made general.** It also
carries a high risk of breaking third-party plugins that hook deeply into the UI.
- Turning canvases into `RenderMode.ScreenSpaceOverlay` is mechanically a one-line
change per canvas, but converting all of them at once produced a white screen
that required a restart. Changes must be stepwise and reversible (a key that
rolls the whole pass back, handled before anything else in `Update`).
- The round trip is destructive: Unity rewrites a root canvas's `RectTransform`
when the render mode changes, re-deriving anchors and discarding the world-unit
size. Snapshot anchors, pivot, `sizeDelta`, `anchoredPosition(3D)` and
`localScale` before the write and restore them after; restoring the enum alone
does not restore the layout.
- Root screen-space canvases cannot be kept as they were: Unity overwrites their
rect with the camera viewport every frame. Re-asserting the pose from
`LateUpdate` was measured and cannot work — there is no MonoBehaviour phase
after Unity's canvas update. The shape that works is one static screen-space
root, every VaM canvas re-parented under it as a **nested** canvas (Unity does
not drive a nested canvas's rect), and the HUD movers frozen.
- Scale must be computed per canvas from its own camera, distance and FOV:
`newScale = localScale.y * pixelHeight / (2 * distance * tan(fov / 2))`.
The apparent size of a world-space canvas is not its `sizeDelta` alone.
- Placement must be carried across in screen space — ask the camera with
`WorldToScreenPoint(rect.position)` and write `anchoredPosition3D` with anchors
at zero — because a root world-space canvas ignores anchors entirely.
Re-parenting also promotes inactive canvases to active (`activeSelf` survives,
`activeInHierarchy` does not), so inactive panels must be converted too; and a
naive per-frame mirror of the original parent's activity fights VaM's own
show/hide logic, so the original rule must be respected instead.
- Residual problems, the reason the approach was abandoned despite fixing FPS:
`MainUICanvas` and `MessageLogCanvas` are still driven as roots by Unity (scale
reset to 1.0, size reset to the screen); atom panels live under the selected
atom's controller rather than a stable path; `ScreenSpaceOverlay` breaks VR;
and a genuinely 2D UI draws over the whole screen rather than into the monitor
object, so the `overlayUI` depth sorting may behave differently.
### 3.4 Direction B — fix the HUD anchor structure
**Status: no research yet.** Keep the HUD in world space and VR-compatible, but
remove the per-rig-write invalidation in the anchor/follower structure. Starting
points: `HUDAnchor.SetAnchorsToReference()`, `MoveAndRotateAsHUDAnchor`, the
monitor UI anchor and `mainHUDAttachPoint`. The working hypothesis is a fault in
how this structure is built, not in the amount of UI that has to follow the
camera.
### 3.5 The workaround that confirms the diagnosis
Our `HUDControl` plugin has a detach / "Freeze HUD In World" path that simply
detaches the UI from the HUD, leaving it a stationary plane in the world — the same
arrangement VaM uses natively in VR. With the HUD detached from camera motion the
FPS drop disappears entirely, which confirms the cause. It is not a general fix,
because the HUD then stops following the view.