What is the correct way to dynamically load assets

I ran into the problem that assets loaded dynamically like:

UStaticMesh* shapeAsset = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), NULL, *assetName));

do not show up in android, but do show up in the editor when I run the game.

What I read from forum posts is that this has to do with the cooking of the game, where it only cooks assets that are needed when classes are initialized (so loaded in the constructor with the FObjectFinder for example)

But I’m making a game where a lot of different shapes can spawn (each shape is an asset), so what I do is spawn an actor from the GameMode and then call a function to load one of the shapes. Not all shapes need to be loaded all the time… normally only 5 shapes are active at a time.

So what is the correct way to handle this situation? How can I make sure these assets are coocked in the game?

thanks for any information!

If you need to forcibly cook some assets, you can add the path(s) containing those assets to the “Additional Asset Directories to Cook” array in your project settings. “Project Settings” → “Packaging” → (Advanced Section) → “Additional Asset Directories to Cook”.