Get currentScene from script

Hi there, I’m trying to get current scene from a script but I’m not finding a way to do it.

I have a scene with a table and some chairs, I’d like to spawn a object and make it go to one of the chairs. I found the great editor made by Julien, and set my scene there. Now I want to make a script so my object goes from spawn point to one of the chairs, but I just can’t find the proper methods to achieve that because I don’t have the scene in that script, so I thought of getting the current scene I’m in and search for the chair I’m looking for and get it’s coordinates so my object can go there.

Any ideas?


Hi @gbelintani !

In scripts you can use this in case the script is attached to the scene.
Else, the “Node” class exposes a method named getScene() that is then available in all Cameras, Light, Meshes, TransformNodes classes.


import { Mesh } from "@babylonjs/core/Meshes/mesh";

export default class MyMeshComponent extends Mesh {

     * Called on the node is being initialized.
     * This function is called immediatly after the constructor has been called.
    public onInitialize(): void {



I’m trying to discover what I can do with Babylonjs and I have a similar question. I can build my canvas just fine, and spin my Lego minifigure and it’s nifty.

I’m working in a VueJS app with the BabylonJS canvas underneath the HTML UI. I want to have an HTML button that would trigger the JavaScript in the VueJS component to manipulate the existing babylonjs scene that is rendered on the page already.

What I can’t figure out is how to connect to the Babylonjs scene to manipulate the material. I see a lot of example code for creating scenes, but I’m clearly not searching the correct keywords to figure out how to manipulate an existing object that is already in a scene.

Is there a “get scene” type method I can call to connect to the existing scene and manipulate it? Feel like I’m really on the wrong track, but not sure how to think about it so that I can get it working.

What I have in the VueJS component now. I know I can’t get to it via the this, that’s where I’m convinced I have my head thinking about this wrong.

    <div id="charactergui-wardrobe" class="text-white">
        <button class="btn btn-success" v-on:click="changeToGreen()">green</button>

import * as BABYLON from "@babylonjs/core";
export default {
  name: "CharacterGuiWardrobe",
  methods: {
      changeToGreen() {
          this.Engine.scenes[0].meshes[1].material.diffuseColor = BABYLON.Color3.Green();