# Always provide the scene parameter to all babylon.js functions

**URL:** <https://forum.babylonjs.com/t/always-provide-the-scene-parameter-to-all-babylon-js-functions/57358>\
**Category:** Tutorials and tips\
**Created:** [March 23, 2025, 2:14pm UTC](https://forum.babylonjs.com/t/always-provide-the-scene-parameter-to-all-babylon-js-functions/57358 "2025-03-23T14:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [March 23, 2025, 2:14pm UTC](https://forum.babylonjs.com/t/always-provide-the-scene-parameter-to-all-babylon-js-functions/57358/1 "2025-03-23T14:14:00Z")

</div>

**Hey!**

I just want to share a small tip that can save you a ton of time.

I never explicitly provided the optional `scene` parameter when creating objects on the scene—until now…

Since introducing a new scene (both scenes are initialized asynchronously) their contexts started to mix.

Now, I have to review every function call that accepts an optional `scene` parameter and explicitly pass the correct `scene`. 🙈

**Explanation:**  
If you don’t provide the `scene` parameter to a function that supports it, Babylon.js retrieves it using the `LastCreatedScene` static getter from the `EngineStore` class. Since it is `static`—you get the point.

```auto
    public static get LastCreatedScene(): Nullable<Scene> {
        return this._LastCreatedScene;
    }

```

So, take your time and **always** specify the `scene`. You never know when it might save your bacon!

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [March 23, 2025, 2:49pm UTC](https://forum.babylonjs.com/t/always-provide-the-scene-parameter-to-all-babylon-js-functions/57358/2 "2025-03-23T14:49:56Z")

</div>

Yup.  
Also, it’s somehow joining my last request about a warning :

> [@Add console warning when no scene found while needed](https://forum.babylonjs.com/t/add-console-warning-when-no-scene-found-while-needed/57313):
>
> Hello slight_smile ! Not sure either it should go into #Bugs or #Feature requests (or none of them, if it’s known) Some constructors need the scene as param : const transform = new BABYLON.TransformNode("transform", scene); const ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 6, height: 6}, scene); const camera = new BABYLON.ArcRotateCamera("camera", 0, 1, 10, BABYLON.Vector3.Zero(), scene); If not provided, the scene will be retreived automatically If the scene doesn’t exist,…

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [March 23, 2025, 4:18pm UTC](https://forum.babylonjs.com/t/always-provide-the-scene-parameter-to-all-babylon-js-functions/57358/3 "2025-03-23T16:18:18Z")

</div>

Just voted for it. 👍
