# I need help for ImportMeshAsync

**URL:** <https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648>\
**Category:** Questions\
**Tags:** meshes\
**Created:** [February 14, 2022, 3:17pm UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648 "2022-02-14T15:17:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [February 14, 2022, 3:17pm UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648/1 "2022-02-14T15:17:10Z")

</div>

Hi,

i’m trying to create instances of an object.  
I want to do this things in a class : if the object doesn’t exist then import him and create an instances, else (if the object doesn’t exist) create an instances.

I have the following code :

_index_

```auto
const scene = createScene();

let obj = new ObjetSupp("test", "./Objets de decoration/", "Tree.obj");
obj.Charge();
obj.Charge();

console.log(obj);

```

_ObjetSupp_

```auto
isCreated() {
    console.log(scene.meshes);

    if(scene.meshes.find(meshe => meshe.name == this.nom) != undefined){
        console.log(true);
        return true;
    }
    else{
        console.log(false);
        return false;
    }
}

async Charge() {
    if (!this.isCreated()) {

        console.log("not created");

        BABYLON.SceneLoader.ShowLoadingScreen = false;
        var newMeshes = await BABYLON.SceneLoader.ImportMeshAsync(null, this.path, this.file, scene);

        console.log("end await")

        for (var i = 0; i < newMeshes.meshes.length; i++) {
            if (newMeshes.meshes[i].material != null) {
                if (newMeshes.meshes[i].material.diffuseTexture != null) {
                    newMeshes.meshes[i].material.diffuseTexture.hasAlpha = true;
                    newMeshes.meshes[i].material.useAlphaFromDiffuseTexture = true;
                }
            }
        }

        console.log("start merge")

        this.mesh = BABYLON.Mesh.MergeMeshes(newMeshes.meshes, true, true, null, false, false);
        this.mesh.name = this.nom;
        this.mesh.normalizeToUnitCube();
        // this.mesh.isVisible = false;
    }

    console.log("create instance");
    this.mesh.createInstance(this.nom + "-" + this.mesh.instances.length+1);
}

```

But it doesn’t work beacause the 2nd “obj.Charge()” start before the end of the 1st one.  
Here all my console log to illustre what i say :

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/3/5349bf86f709b18427cbf3fff888d5ab65cbac81.png)

Can i get some help ?  
thanks by advance

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [February 14, 2022, 3:38pm UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648/2 "2022-02-14T15:38:52Z")

</div>

> [@VerandaLouis](#):
>
> doesn’t work beacause the 2nd “obj.Charge()” start before the end of the 1st one

You can wait until it’s done like below (and will need to make the function that below code is in async).

```auto
await obj.Charge();
await obj.Charge();
console.log(obj);

```

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [March 15, 2022, 10:30am UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648/3 "2022-03-15T10:30:36Z")

</div>

Hello @VerandaLouis just checking in, was your question answered?

---

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [March 28, 2022, 4:00pm UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648/4 "2022-03-28T16:00:34Z")

</div>

Hello, sorry for late reply, so yeah in fact it works but an async function in a async function is not too much haha ?

And I put my question on hold for the moment because nothing is urgent.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [March 28, 2022, 4:57pm UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648/5 "2022-03-28T16:57:44Z")

</div>

There aren’t any problems in having async functions nested inside others, as long as you use them properly 😃

---

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [March 29, 2022, 8:16am UTC](https://forum.babylonjs.com/t/i-need-help-for-importmeshasync/27648/6 "2022-03-29T08:16:34Z")

</div>

alright, thank you 🙂
