Build a Godot 4 (OpenXR) VR app and verify it headlessly on a Windows host
(no editor, no headset needed during the build/verify loop). Deliver a real,
running project verified by execution — not a description. (Sibling of
blender-headless; different engine, same headless-verify discipline.)
When to Use
- The user wants a Godot 4 VR/AR or OpenXR app (headset target like Pimax Crystal — works on either Pimax runtime once the action-map/tracker binding is right; see the reference).
- You must headless-verify a Godot 4 scene without the editor: import → headless run → non-headless screenshot.
- You hit Godot 4.7 parse/runtime errors on render / particles / physics / XR APIs — the reference holds the working forms.
Environment (Windows)
- Godot 4.7.x win64 standard build (standard, not .NET — it has OpenXR compiled in) from the godotengine releases page; use the
_consoleexe for scriptable runs. Reuse an existing install (confirm with--version) before downloading. - Headless build/verify needs no OpenXR runtime installed. For in-visor testing on a Pimax Crystal: the first-party runtime ships inside Pimax Play (
C:\Program Files\Pimax\, Pimax OpenXR 0.1.0). Pimax Crystal controllers work in Godot on BOTH Pimax OpenXR 0.1.0 and PimaxXR (Unofficial) 0.4.4 once the action map + tracker binding are correct (seereferences/xr-controller-troubleshooting.md); SteamVR unverified. - Put the project on a local drive with room to grow (assets + import cache).
- In Hermes's bash terminal on Windows, argument path conversion is off: pass drive-letter paths (
C:/...) to native binaries (Godot, Blender, python) — MSYS/c/...forms work for bash builtins (cd,ls) only.
Workflow (in order)
- Scaffold
project.godot:config/features=PackedStringArray("4.7","Forward Plus")(do NOT include"OpenXR"— it triggers a false-positive editor warning; runtime OpenXR is driven by[xr] openxr/enabled=true, not the feature tag),[rendering] renderer/rendering_method="forward_plus", an[xr]block withopenxr/enabled=true,openxr/always_in_xr=true,shaders/enabled=true, and a 1600x900 viewport. - Build the scene procedurally in code — primitives only, no external assets (that is the default here). One
main.gdon the root node builds: Environment (glow/bloom + fog), a directional "moon" light,OmniLight3Dpoint lights for the glow, and the geometry (trees, props, a focal glowing centerpiece). - XR root:
XROrigin3D→ childrenXRCamera3D+ twoXRController3D, eachtracker="left_hand"/"right_hand"(the tracker namesOpenXRInterface::find_tracker()registers withXRServer),pose="grip"(or"aim"),show_when_tracked=true. ⚠️XRController3Dhas NO auto-detect: an emptytracker→get_tracker("")→ null → the node never binds (frozen pose,hand=0, invisible hands). Settrackerexplicitly to"left_hand"/"right_hand". Neverpose="default"(unreliably bound → controllers silently stop tracking). Seereferences/xr-controller-troubleshooting.md. - Grab without a plugin: native
XRController3D+ a world-space ray (get_world_3d().direct_space_state.intersect_ray(PhysicsRayQueryParameters3D.create(from,to))). The GodotVR XR-Interaction plugin is unavailable (no such repo exists in the GodotVR org — its maintained grab toolkit isgodot-xr-tools, but the native ray grab avoids the dependency) — do not block on it. - Fallback camera + self-screenshot so the scene is checkable without a headset: in
_ready, if no XR session, add aCamera3Dpointed at the scene; if the run was given a marker arg (e.g.--preview), wait ~12 frames thenget_viewport().get_texture().get_image().save_png(path)andget_tree().quit(). - Headless-verify (OpenXR OFF — see gate below) until 0 script errors; confirm the startup self-test print shows the
XROrigin3Dwith itsXRCamera3D+ both controllers. - GPU screenshot: run NON-headless with the marker arg and
--xr-mode off(on any machine with an OpenXR runtime installed, the runtime may init without a headset and silently blank the window) → PNG, then vision-check it (real geometry/lighting, not a blank/solid-color frame). Confirm the run exited and left no orphangodotprocess (see the reference's process-hygiene note). - Re-enable OpenXR for delivery (
openxr/enabled=true; leave"OpenXR"out ofconfig/features). The in-visor feel is the user's final check.
Pitfalls
- OpenXR +
--headlessstalls in the main loop, AFTER_ready— scene load and every_readyrun and print normally, then the engine enters the main loop, detects the HMD, and hangs to timeout (no display/form factor). So a short-timeout headless run IS a valid no-headset check that a code edit landed:timeout 20 <bin> --headless --path <proj> 2>&1 | grep -iE "Parse Error|SCRIPT ERROR|not found in base|ready"surfaces scene-load parse errors and your_readyprints (e.g.[LeftHand] ready (tracker=… pose=…)) before the stall — use it to confirm a change took effect (and it is the only reliable way to catch native-method parse errors, since--importdoes not parse scene scripts against the native API). Use a full run with OpenXR OFF for real 0-error / self-test verification, then re-enable OpenXR for delivery. Do not chase a ticking "headless VR" main loop — it won't run past session start without a display. --headlessnever renders. Any visual check must run NON-headless (marker arg) so a window opens and GPU draws; the scene saves its own PNG.- Godot 4.7 renamed/changed several 3.x-era APIs — the "obvious" form throws parse/runtime errors. Check
references/godot-47-api.mdbefore writing render/particles/physics/XR code; it lists the working forms and the errors they prevent. write_filerefuses overwrite even after a full read. Back up the target to scratch first (it is user-authored content and the replacement write can fail or be interrupted — restore from the backup if it does), thenrm -fthe original and write to the fresh path (same workaround works for re-writing scene.tscn/.gd).- Don't trust import alone. Run the project headless after import — most errors here were runtime (wrong API shape), which
--importdoes not surface. - Headless-verify passing ≠ controllers work. A clean headless run + screenshot proves the scene runs and renders; it can't see the visor, so it says nothing about whether controllers track in it. When the user reports "no hands / can't interact," go straight to
references/xr-controller-troubleshooting.md— do not re-tune the scene or chase a headless VR run. - "No hands" on Pimax Crystal is the binding layer (case A), NOT the runtime. Verified in-visor: with the case A fixes in place, the same project works on both Pimax OpenXR 0.1.0 (Pimax Play built-in) and PimaxXR (Unofficial) 0.4.4. The case A fixes: (1)
XRController3D.trackermust be set explicitly to"left_hand"/"right_hand"(no auto-detect — empty never binds), and (2) the OpenXR action map must be trimmed to only the profiles the runtime recognizes — for Crystal keep onlyoculus/touch_controller, drop the other three stock profiles (generic, pico4, hand) and everygrip_surface/pose(OpenXR 1.1 palm-pose) binding. One unsupported path fails the wholexrSuggestInteractionProfileBindingscall (XR_ERROR_PATH_UNSUPPORTED) → no controller binds, on any runtime. Noopenxr/default_action_mappin needed — the engine default is alreadyres://openxr_action_map.tres(probe-verified); just keep the edited file at that path. (Early "no hands" on PiOpenXR/SteamVR predated the binding fix; the runtime switch that once seemed to fix it was coincidental. SteamVR was never re-tested after the fix — unverified.) - "feature
OpenXRnot supported by this version" is a 4.7.2 editor false-positive when"OpenXR"is inconfig/features(the build has OpenXR; it initializes at runtime). Dismissable ("Open anyway"), but you can avoid it by leaving"OpenXR"out ofconfig/features— runtime OpenXR is driven by[xr] openxr/enabled=true, not the feature tag. Confirm OpenXR actually loaded via theRunning on OpenXR runtime: …Output line, not the feature list. - Long/AFK builds: one small patch per response, then verify before the next — a response that hits the output-length cap is discarded whole (no partial action runs), so a batched multi-patch response stops the entire run and waits on the user.
- Wrap every non-headless run in
timeout <N>— the scene self-quits on the marker arg, but a run that doesn't leaves a windowed Godot holding the user's machine; the orphan check after istasklist | grep -ic godot= 0 (seereferences/godot-47-api.md). To kill a survivor,taskkill /PID <pid> /F— MSYSkill <pid>cannot reach a native Windows process at all, and when argument path conversion is off the double-slash form//PIDis passed through literally and rejected. - Regenerated
.glb/.gltfassets are NOT re-imported by ordinary runs. The import cache (.godot/imported/*.scn) survives, and a normal--preview/headless run silently uses the STALE cached import — so after regenerating any imported asset you must runtimeout N <bin> --path <proj> --headless --importand confirm the.scnmtimes moved (or that the storedsource_md5matches the sourcemd5sum). Symptom: asset fixed and regenerated on disk, but screenshots still show the old broken geometry, and all further "fixes" debug phantom bugs (this cost a full investigation cycle in the forest project). -sstandalone scripts: a script error beforequit()runs the SceneTree forever — a windowed black Godot lingers on the user's machine. Standalone debug scripts must reachquit()even on failure (check results before the onlyquit()call, or run with--headlessundertimeoutso a stall is bounded).- Prove a visual fix quantitatively before reporting it to the user. A subtle change on a small object in a full-scene capture looks like "no change" — to the user and to your own vision check (twice reporting a working water mirror on weak evidence cost two user round-trips). A/B it: capture with the feature on and off, pixel-diff the region (PIL: mean/max abs diff + % pixels moved); a large region delta is proof, a faint tint is not. When the feature hides behind other geometry, measure geometry (vertex positions/distances) — the only reliable evidence a screenshot cannot give.
- User reports "no change" after a code fix → suspect a stale process before suspecting the fix. Script changes apply only on a fresh launch; an app left running from the last test keeps showing old behavior. Confirm the code on disk is the final version (no leftover debug lines) and that a clean capture run works, then have the user fully quit and relaunch before re-debugging the fix itself.
- In-visor mirror pool: a ReflectionProbe often contributes NOTHING (water shows glow wash but no reflected shapes — a probe at head height can't see low objects, and in-visor it frequently renders dark). The approach that works is the GEOMETRIC MIRROR TWIN: parent an inverted copy of each reflected object under a
_mirror_rootNode3D (scale(1,-1,1), at the waterline) so the reflection is real geometry seen through the TRANSLUCENT water (roughness ~0.15, alpha ~0.5); the twin is only visible in the style that uses it (hidden under opaque water/ground otherwise). Verified in-visor (user-confirmed). If you do use a probe instead, 4.7 has three silent killers (all defaults!):blend_distancedefaults to 1.0 m andmax_distanceto 0.0 (older 4.x used 100) — a reflective surface farther than 1 m from the probe receives nothing from it; set both explicitly (e.g. blend 30, max 10). Second: a flat water surface only mirrors content ABOVE the probe's own height (reflected rays always point upward from the probe) — a probe at head height can never show mushrooms/rocks/low crystals; put it just above the water (~0.4 m). Third: the water albedo sets contrast (metal: reflection = reflected radiance × albedo) — a bright albedo makes a featureless pale disc in a dark scene; a deep dark-teal albedo makes the reflected glow shapes pop (night-pond look). Also: a strong point light directly above a near-mirror makes a wide specular wash that buries the mirror image (lower its energy). 4.7 exposes NO cubemap API on the probe (nocubemapproperty, no getter) — to verify the probe actually reflects, place a bright test sphere ABOVE probe height and look for its mirrored dot on the water. And capture water from standing eye-height close-ups (add a dedicated eye-height mode, e.g.--preview-close <azimuth_deg> <distance_m>— the camera stands ~1.55 m up, a couple of metres out, looking at the water), never the high overview camera. - Mystery bright lines / streaks / "UV seams" crossing objects → suspect the XR controller visuals before hunting scene geometry. The classic culprit is the aim beam: a 3 m emissive box pointing forward from each hand crosses every object the user points at and reads exactly like a mismatched-UV hairline on a textured rock (two hands → two lines). It renders in windowed captures too — a plain
--previewscreenshot showed it (despiteshow_when_tracked=true). Fix: short beam (≈0.5 m, hand scale), dim (emission ≈0.2), brighten (≈2.5) only while hovering a grabbable; the grab RAY (raycast) length is separate from the visual beam length. - Prove which asset causes a visual artifact by hiding, one class per capture — not by eyeballing. Tag nodes
set_meta("hides", "<tag>")at every creation site; add a--hide <tag1>,<tag2>CLI flag that frees every tagged node before the screenshot. A class is guilty only if hiding it makes the artifact disappear. - Runtime node names of repeated classes are unreliable — match on meta tags. Nodes added at runtime get renamed/deduped, so name matching (even a prefix) hits only the FIRST instance of a class (1 of 19 mushrooms). Tag at creation, match
n.get_meta("hides", ""); tag every instance of a logical class, including unnamed twins/duplicate meshes (the style-2 ground twin needed its own tag). GDScript working forms:var stack: Array = get_children().duplicate()(:=infers Variant from an untyped Array) andfor i in kill.size(): (kill[i] as Node).free(). - Bloom blowout is not geometry. A 0.2 m emissive cap (emission 2+, bloom 0.5, HDR threshold 0.9) renders as a glowing disc several times its geometry in captures — when a "giant glowing box/disc" appears, check
emission_energy_multiplier× glow settings before concluding the mesh is broken. - One texture appearing on several objects at once, or a surface texture that crawls as the head moves = a space bug, not per-object geometry (screen/camera-space artifacts move with the view and stay synchronized across surfaces). Check in order: (a) a shader sampling its noise in a camera-dependent space — in the
fragment()functionVERTEXis view space (model/object space only invertex()), soMODEL_MATRIX * VERTEXAND raw_fbm3(VERTEX*…)in the fragment both crawl with the head — synchronized across every object sharing the shader (4.7 has noWORLD_MATRIX). True world-space noise:wp = MODEL_MATRIX * v_local, wherev_localis avaryingset toVERTEXinvertex();INV_VIEW_MATRIX * VERTEXin the fragment is ALSO world space (it is the form the forest ground shader shipped with and it is correct). Verified in-visor: this is the difference between a texture that crawls as you turn your head and one that sits still. (b) glow bleed — a bright non-emissive surface (a ground washed by point lights) exceedsglow_hdr_threshold, so its mottled pattern is additively smeared onto nearby rocks/mushrooms/trees; levers: raiseglow_hdr_threshold(0.9→~1.4 keeps emissive-1.5+ objects glowing while lit non-emissive surfaces stop blooming), tightenglow_bloom(~0.35–0.4), and dim light energy until the ground sits below the threshold. Verify with close-up captures of the affected objects, not the overview camera. - Blender 5.3's glTF exporter writes "invalid" GLBs that Godot renders fine. Every exported GLB declares the index accessor
componentType5123 (uint32) while the index bufferView holds 2-byte indices — do not treat this as corruption when a file looks broken on disk (Godot infers the index type from the bufferView size). When a mesh renders wrong (spikes, streaks, stray far geometry), scan triangles directly withscripts/scan_glb.py <file.glb>(flags degenerate triangles and edges longer than N× the bbox extent); a clean scan means the geometry is fine and the artifact is elsewhere (shaders, bloom, controller visuals).
References
references/godot-47-api.md— confirmed 4.7.2 API forms (Environment glow, GPUParticles3D, RigidBody3D, raycast, XR session state, XRController3D) + theXROrigin3Dscene structure + the error→fix table that actually fired during the build + the exact verification commands.references/xr-controller-troubleshooting.md— controllers don't show / no interaction in the visor: the decisive diagnostic (which of 3 failure cases), the case A two-sub-fix detail (explicittracker+ trimmed action map — the real Pimax Crystal fix, works on both Pimax runtimes), OpenXR runtime selection on Windows (registry / env override / restart / verify line), and the benign warnings to ignore.references/style-swap-system.md— runtime-swappable graphics styles on one scene (e.g. B-button cycle): the typed-entry registry +_set_stylewalk, the hidden-twinMeshInstance3Dpattern for alternate geometry with per-object transforms, the per-style ENV table,--style Nverification, and the Blender-side canonical-asset pipeline.scripts/scan_glb.py— re-runnable GLB triangle scanner (degenerate + over-long-edge flags; tolerates the Blender 5.3 uint32/uint16 index quirk). Run it before blaming imported geometry for a visual artifact.
