A class to keep track of loaded assets

I am looking for a simple way to keep track of loaded assets (their names). To this end, I introduced cLoader manager class that records asset names on successful load -
cLoader has loadedMeshNames array data member and, on successful load, the new mesh name is appended to this array.
Thus if I want to keep track of a particular mesh, for example, I can load the mesh through this class. Here is my playground

Unfortunately, that does not work because I am getting an error in the callback for onSuccess load.
In console, you can see following error
logger.ts:103 BJS - [16:17:25]: Unable to load from https://assets.babylonjs.com/meshes/Yeti/MayaExport/glTF/Yeti.gltf: Error in onSuccess callback: TypeError: Cannot read properties of undefined (reading ‘loadedMeshNames’)

For some reason, I cannot access the data member in my class’ method.
Any suggestion, what would be the optimum way for me to keep track of loaded assets, so I can destroy, hide, unhide them as needed?
Thank you

This is because you don’t pass a variable to the callback function.
Here it works (see console) - https://playground.babylonjs.com/#00BDB0#5
Please note that in this configuration there will be only the first meshes from each model in your loadedMeshNames array, and all of them will have identical names '__root__'.
To avoid this use either mesh IDs, or save all meshes names in your array (Yeti model has 7 meshes).


@labris Thank you for both solving the problem and pointing out a potential issue with mesh name!

1 Like