# Import 2 objects make just the first one usable

**URL:** <https://forum.babylonjs.com/t/import-2-objects-make-just-the-first-one-usable/23605>\
**Category:** Questions\
**Created:** [September 6, 2021, 10:33am UTC](https://forum.babylonjs.com/t/import-2-objects-make-just-the-first-one-usable/23605 "2021-09-06T10:33:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toni\_Bruno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/toni_bruno/32/18448_2.png) [@Toni\_Bruno](https://forum.babylonjs.com/u/Toni_Bruno)\
**Post date:** [September 6, 2021, 10:33am UTC](https://forum.babylonjs.com/t/import-2-objects-make-just-the-first-one-usable/23605/1 "2021-09-06T10:33:13Z")

</div>

Ciao, I have this function

```auto
public addCube() {

        const material = new BABYLON.StandardMaterial("defaultMaterial", this.scene!);

        material.alpha = 1;

        material.diffuseColor = new BABYLON.Color3(1.0, 0, 0);

        material.alpha = 0.8;

        const obj1 = BABYLON.SceneLoader.Append("https://dl.dropbox.com/s/kum4ztqput0l3gx/", "demo20%bar.stl", this.scene, () => {

            const mesh = this.scene?.getMeshByName("stlmesh");

            if (mesh != null) {

                mesh.material = material;

            }

            const pointerDragBehavior = new BABYLON.PointerDragBehavior({ dragAxis: new BABYLON.Vector3(1, 0, 0) });

            pointerDragBehavior.useObjectOrientationForDragging = false;

            mesh!.addBehavior(pointerDragBehavior, true);

        });

        const obj2 = BABYLON.SceneLoader.Append("https://dl.dropbox.com/s/kum4ztqput0l3gx/", "demo20%bar.stl", this.scene, () => {

            const mesh = this.scene?.getMeshByName("stlmesh");

            if (mesh != null) {

                mesh.material = material;

            }

            const pointerDragBehavior = new BABYLON.PointerDragBehavior({ dragAxis: new BABYLON.Vector3(1, 0, 0) });

            pointerDragBehavior.useObjectOrientationForDragging = false;

            mesh!.addBehavior(pointerDragBehavior, true);

        });

    }

```

I see both of the objects imported, but the first one has the correct material and the correct behaviour, the second one is visible but with a gray material and is not draggable. What am I doing wrong?

Thank you

Toni

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 6, 2021, 3:04pm UTC](https://forum.babylonjs.com/t/import-2-objects-make-just-the-first-one-usable/23605/2 "2021-09-06T15:04:43Z")

</div>

The second callback will get the first object when doing:

```auto
this.scene?.getMeshByName("stlmesh");

```

as the two objects have the same name.

You should probably put the code `const obj2 = ...` inside the callback of `const obj1 = ...`. That way, you will be able change the name of the object (`mesh.name = stlmesh0") ` before loading for the second time. By doing so, the 2nd `this.scene?.getMeshByName("stlmesh")` call will get the right mesh (the one loaded by the `SceneLoader.Append` call).

---

<div class="post-metadata">

**Author:** ![Toni\_Bruno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/toni_bruno/32/18448_2.png) [@Toni\_Bruno](https://forum.babylonjs.com/u/Toni_Bruno)\
**Post date:** [September 6, 2021, 6:58pm UTC](https://forum.babylonjs.com/t/import-2-objects-make-just-the-first-one-usable/23605/3 "2021-09-06T18:58:01Z")

</div>

> [@Evgeni\_Popov](#):
>
> d probably put the code `const obj2 = .`

Thank you, you saved my day!
