Why do I see my imported Mesh object twice?

I’m still learning, therefore my project is very simple code.

Consider the following code:

async importCarMesh(){
    const importPromise = await SceneLoader.ImportMeshAsync(
        "", // root url
        "assets/blender/little_car.babylon", // file name
        "", // scene name
        //this.scene // the scene where the model will be added

      return importPromise.meshes[2];

And the way I use it, in my Scene initialization:

  1.      const car = await this.importCarMesh();
  2.      car.position = new Vector3(0, -6, 0);

When I only run line 1, I get to see a car on (roughly) Vector3(0,5,0)
When I run both line 1 and 2, I get to see two cars, where one is on Vector3(0,5,0) and my other is one Vector3(0, -6, 0);

I don’t understand what’s happening. Why do I get 2 cars?

I have seemingly solved it by pure guesswork, which creates a new question.
In my little_car.babylon file , I have spotted the variable “isVisible”:true
I have changed this to “false” and this has magically removed the strange static “ghost” car that was appearing on Vector3(0,5,0) .
After changing it to “false”, I now only get to see 1 car instead of 2.

Any explanation on this mechanism to make me understand better is still very welcome!

I’d be curious to see a PG with your .babylon file. Hard to figure out without a scene to test :slight_smile:

1 Like

isVisible = false (or !isVisible) as its name suggests, makes the object/mesh invisible.
This doesn’t mean your mesh is not loaded/created. In fact, in absence of an error thrown, it actually means that the mesh exists and has been set to be invisible.
To make sure of that, open the inspector from the debug layer and check through your Nodes. You should see your second (ghost) car in there. Else, open the console and check for any errors.


As Cedric says, hard to tell you exactly without a PG or the entire code. You could be looping through somehow with your async, promise and await. One thing is clear: If you do have 2 cars, adding line #2 simply moves one of them to a new position. This means that without line #2, you already have 2 cars and the only difference is that, since they are positioned and scaled exactly the same, you see it as a single car.