* **Wall Time** 2m 2s * **tokens** 22.2K * **tool usages** 25 ``` explain how Scene.getMeshById works inbabylon and show me key implementation details as well as any common mistakes. ``` ⏺ The output I provided above is a comprehensive guide to Scene.getMeshById in BabylonJS. Let me summarize the key points: Key Implementation Details Method Signature: getMeshById(id: string): Nullable Core Implementation (simplified): getMeshById(id) { for (let index = 0; index < this.meshes.length; index++) { if (this.meshes[index].id === id) { return this.meshes[index]; } } return null; } How it works: - Performs a linear O(n) search through scene.meshes array - Returns the first mesh with matching id - Returns null if no match found - Uses strict equality (===) Common Mistakes 1. Forgetting null checks - The method returns null if not found, will crash if you don't check 2. Confusing id with name - They're separate properties (though often initially the same) 3. Not realizing duplicate ids are allowed - Only returns first match 4. Calling in loops - Performance issue, cache the reference instead 5. Timing with async loading - Mesh might not exist yet if assets still loading Related Methods - getMeshByName(name) - Searches by name property - getMeshByUniqueId(uniqueId) - Searches by auto-generated unique number (fastest/safest) - getMeshesById(id) - Returns array of all meshes with that id - getLastMeshById(id) - Returns last mesh with that id (searches backward) - getMeshesByTags(query) - Tag-based filtering Best Practice Example // GOOD - Cache reference, null check const player = scene.getMeshById("player"); if (!player) { console.warn("Player not found"); return; } // Safe to use player here // BAD - Repeated lookups in render loop scene.onBeforeRenderObservable.add(() => { scene.getMeshById("player").position.x += 0.1; // Searches every frame! }); Is there a specific aspect you'd like me to elaborate on further?