1

I am loading my assets into an array with a function LoadJSON() that uses THREE.ObjectLoader() (assets are JSON files) . If I try to access the members of the array shortly after calling LoadJSON() it returns undefined and my program fails to run. Some research revealed that the assets are being loaded asynchronously which is why I can't access the assets in my array right away ( they are still loading ). To confirm this I did a test accessing the members of the array after a short time delay and they work.

My question: Is there a way to make sure the assets are loaded before doing anything else? I looked at the THREE.ObjectLoader code and couldn't seem to find a solution there ( though I may be missing it ). Setting a time delay seems like a bad/inconsistent solution.

link to THREE.ObjectLoader on github

mikel942
  • 23
  • 2

1 Answers1

0

load functions have a callback.

var loader = new THREE.OBJLoader( manager );

loader.load( 'obj/male02/male02.obj', function ( object ) {
    //this happens after load object being what is loaded.
} );

for more info see the example

Kevin Kuyl
  • 1,215
  • 1
  • 17
  • 31