There are an unknown number of levels and each level may have associated with it a data table filled with useful information specific to that level.
A piece of code in the game instance would like to check if the current level has a data table associated with it (using a name or a label) and load it.
The project directory structure would look like this:
Game
|__ Data
|__ DataTable_Level_One
|__ DataTable_Level_Three
...
How can we load the data tables without using direct references or paths?
In the Asset Manager settings for the project, we can associate a label with the DataTable type and point to a directory:
We can create a FPrimaryAssetId but I’m not clear on how to do that, what it should contain and how to tag a data table to have the asset id of a level.
How can we check if a specific data table exists and load it using the asset manager in a way that works in both PIE and packaged games?
Is there a more straightforward way to get a data table based on a name or label that lives in a specified folder?
Ideally we would not assign assets but look for, and load, only the ones that are currently needed.
You are asking extremely broad questions here, answering them would almost require providing the complete implementation of your system, so not a lot of people are going to be eager to do that.
To give you a few pointers:
A FPrimaryAssetId is just a string (FName) under the hood. Nothing fancy. But that’s not what you should focus on right now.
I understand that you want to load a specific, optional, data table based on a level, and the number of levels is unspecified.. You don’t want to use hardcoded paths, but honestly, given your directory structure, there’s no reason not to… “Game/Data/DataTable\_” + levelName would enable you to reconstitude the specific asset path that you need, and load it if it exists. No need for fancy asset management.
NOTE: The fact that you specify “works both for PIE and packaged games”, leads me to believe that you might not be using paths correctly. It’s not supposed to vary between PIE / Package. I don’t expect your implementation to give you trouble once packaged.
Still.. if you absolutely want to use the asset manager, you could have a data asset that maps your levels with your data assets. A simple map with the level as the key, and the data table as the value for instance. That’s totally viable, no need to over-think it.
I understand that the asset manager, and data assets in general, are a super broad concept which has tons of different applications, yet very few actual examples. It’s a complex system initially setup specifically for Fortnite’s very specific brand of on-demand content loading & dynamic downloading.
But most people’s usecases, even yours, seems be to much, much more straightforward, and do not require using more than simple scans/loads in the asset manager.
I ended up not using primary assets for this. Instead I use a subclass of AWorldSettings which has soft object pointers to data tables. This exists per-level and is easy to query using GetWorld()->GetWorldSettings() and works well with the current project.
The only drawback is that the level must be open to edit the world settings, which would not be the case using primary assets. Still, it’s not an issue currently and seems to be the lighter option of the two.