We try to implement a preloading System and encounter some Problems. Also its not very clear what Managers and Classes should be used to archive this. In Our Case we have a Application which has around 30GB in .pak data and we want to preload some of this content so we can reduce our Loading times.
A Preload / caching System is loading Assets at Runtime into the System Memory before they are needed by the Application so that when needed the Loading times are much faster. This can either be done by blocking the main threat or asynchronous (what we would prefer).
So there are 3 things to do:
- Check if we have SystemMemory left
- Load Assets from Disk (= a lot of functions and classes can do this, and different Strategies can be applied)
- Store them so they don’t get garbagecollected
1) is easy and can be done by:
const FPlatformMemoryConstants& memConstants = FPlatformMemory::GetConstants();
2) There are a couple of places where you can find methodes to load assets:
- FStreamableManager A native class for managing streaming assets in and keeping them in memory.
- AssetManager A singleton that is responsible for loading and unloading PrimaryAssets, and maintaining game-specific asset references Games should override this class and change the class reference
- LoadPackageAsync Asynchronously load a package and all contained objects that match context flags.
- In addition to that there are various Blueprint Exposed Functions which are able to async load Assets
If you read through the documentation there are a couple of Objects and concepts which are not further explained:
primary and secondary assets-> https://docs.unrealengine.com/en-US/Engine/Basics/AssetsAndPackages/AssetManagement/index.html
- Package and UPackage
3) You could store Pointers to these Assets into a TMap or Array, with the UPROPERTY() Macro to prevent them from GC.
- Can Anyone answer what Method to use here ? Or even Further explain the underlying Concept ?
- What is a good strategy of loading Assets ? Should you always use .umaps or the “parent” actor so that references are loaded automatically whit them ? Or can you just load all type of assets contained in a Folder as well ?
- How to efficiently prevent the loaded Assets from GC ? Also keeping in mind that when finally using the assets they are accessible in a fast way ? Or is this automatically handled by the AssetRegistry or some other System ?
P.s. I created an UDN Ticket as well but I dont know when and how it gets exposed to AnswerHub…