Log LOD switches while you tune distances
Updated
A grove of trees with three levels of detail each: amber and detailed near, blue and coarse further out, a violet cone far away. The script logs every switch of the first tree with the camera’s distance.
Scroll to zoom out and in, and watch the trees swap levels and the log report each switch of the front tree. Drag to orbit the camera.
Log LOD switches while you tune distances
#pragma lifecycle(startup, update)
let group;let lod;let lastLevel;const cameraPosition = new THREE.Vector3();const groupPosition = new THREE.Vector3();
function startup() { group = findEntity('Tree LOD'); lod = group.getComponent(LODGroupComponent); for (const level of lod.lodLevels) { log('Level', level.entity.name, 'from', level.distance, 'm'); }}
function update() { const level = lod.currentLevel; if (level === lastLevel || !camera) return; lastLevel = level;
camera.getWorldPosition(cameraPosition); group.getWorldPosition(groupPosition); const distance = cameraPosition.distanceTo(groupPosition); log('Showing', level ? level.entity.name : 'nothing', 'at', distance.toFixed(1), 'm', level && !level.ready ? '(still loading)' : '');}How it works
Section titled “How it works”The script is explained step by step in Log LOD switches while you tune distances.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
LodMonitor.xrproj