Without a playground it is difficult to be definitive but would suggest that you are getting undefined outside the function because this line is being called before meshTask has successfully finished and so, as it says, length is not yet defined.
Everything you want to do to loaded meshes must be done inside the onSuccess function.
the interpreter farms out the load task and goes straight to the next block of code, it does not hang around waiting for the task to finish before executing the next block of code. Once the load task has been completed the interpreter is notified and then the onSuccess code executed.
This way, for example, while the models are being loaded the interpreter can get on with building a menu system.
Ok I understand.
So is there a way to notify an external calling function that all the assets are now loaded and are ready to be called ? what approach would you advice ? Thanks.
That’s because the “On Success” does not fire till its done so the length never gets bound and gets tossed into the stack basically. While your thread continues on to process the console log that was defined on the line below.
If you have an expected number of assets you are loading you could have a variable that increments on each OnSuccess and then fire a function to see if the incremented number matches what you are expecting if so then do some sort of response.