loadAsync function not working or using wrong

I am trying to get a promise from the loadAsync function so that I can use the async, await technique to instansiate an object in my scene. But the problem is that the promise is always pending and that the promiseResult property undefined is. What am I doing wrong? I think I have to specify something else as the return value but after reading the documentation I still don’t know what I am doing wrong. See code below:

async function loadCar() {
    var gltfLoader = new THREE.GLTFLoader();
    var loader = new THREE.Loader(gltfLoader);
    var promise = loader.loadAsync("car/scene.gltf");
    console.log(promise);
    var result = await promise;
    console.log(result);
}

The THREE.Loader class is never used directly, it’s a base class for other loaders. Instead:

var gltfLoader = new THREE.GLTFLoader();
var result = await loader.loadAsync("car/scene.gltf");
...
1 Like

I think you ment:

var gltfLoader = new THREE.GLTFLoader();
var result = await gltfLoader.loadAsync("car/scene.gltf");
...

Because that seems to work :smiley:
Thanks for your working solution!

1 Like