How to get a list of assets from AssetManager (...)

Hey there! At first, thanks for building up such a great piece of software and the community!

I have a problem I can’t find any solution to: I need a list of the paths of all available assets in a certain folder in the asset directory. To be more specific: I want to load a random sound from a certain asset folder, so i need a list to pick from. Of course i can just name the files “0.wav” and “1.wav” (and so on) and then build the paths myself, but then i would have to know how many files there are in which folder.
I found this article: https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:development:projects_assets - it say there is a way to get a list of assets, but the jme3 doesn’t even seem to know those classes mentioned, there. Maybe it is outdated.

From my understanding it should be a pieco of cake for the AssetManager to provide a list of assets from a certain asset folder - so why is this feature missing? I am also surprised by the lack of requests and forum threads about this.

Can anyone help?

Thanks a lot!

No, it can’t. The AssetManager is essentially a wrapper around the classloader. All of those assets in your assets folder get packaged up into a .jar file and loaded as class resources. There is no reliable way to list all class resources thus AssetManager does not provide a way to list all assets. I mean, AssetManager doesn’t even know where the things are coming from… it could be a web site at some URL for example in which case it’s just impossible to get the list.

The lack of request for such a feature is because it is almost never needed. And when it is it is usually because the game is trying to read from a local folder (through an asset locator) in which case they already have the normal file system way of finding things.

As the assets are packed when the app is built you could just create a .txt file containing a list of the files in the assets folder via an ANT build target in the build.xml file and store along with the assets in the assets folder. But as was said, if you depend on making a list of things that are known at compile time you might have some design flaw in your app. (This also explains why theres so few posts about it)

Hey, thanks for your answers so far!
I’m aware that the assets are packed in the assets.jar - i was just hoping that there might still be a way…
Also I wouldn’t call it a design flaw, but rather a pretty special case :wink: The plan is to manage huge amounts of samples organized according to different parameters (length, intensity, whatever) and then compose the sound scape of the game out of samples that were (semi-)randomly picked from those directory structure.
As i said, i can finish collecting those samples, finalize my choices and then just rename the files from “0” to “n” and hardcode some final int with the aount of files in every sample folder… i just would have liked it much more to be able to keep it dynamic and just throuw in samples and thats it. If i just had something like a File object of the asset sound folder (i know, it’s packed in a jar) - yeah, that’d be great!

@Kjubert said: Hey, thanks for your answers so far! I'm aware that the assets are packed in the assets.jar - i was just hoping that there might still be a way... Also I wouldn't call it a design flaw, but rather a pretty special case ;) The plan is to manage huge amounts of samples organized according to different parameters (length, intensity, whatever) and then compose the sound scape of the game out of samples that were (semi-)randomly picked from those directory structure. As i said, i can finish collecting those samples, finalize my choices and then just rename the files from "0" to "n" and hardcode some final int with the aount of files in every sample folder... i just would have liked it much more to be able to keep it dynamic and just throuw in samples and thats it. If i just had something like a File object of the asset sound folder (i know, it's packed in a jar) - yeah, that'd be great!

You can’t do what you want to do. You will have to create some kind of manifest text file or something… which is ultimately better for you since you may find that loading 1000 sound files is kind of bad and that you’d really rather be indexing into batched clips.