[C++]Load Class From SoftClassPtr

Hi, I’ve got a SoftClassPtr. How would I load it? Currently, when I deserialize it and check if it’s valid, it returns false. I can’t figure out how to properly load it and then continue on with the rest of the load function that spawns the actor. If you need more info, I can provide it. Thanks!

TL:DR: How do I load an UClass* from a SoftClassPtr

Asyc loading assets has some documentation, but its not the best.

I included a write up and code bits in my document

Its under section 10.

  1. Create a C++ Singleton class, with static variable of type FStreamableManager AssetLoader with a GetMethod.
  2. Create a BP version of singleton, and use it in the Project setting.
  3. Have TArray of type TArray>
  4. Convert all your SoftClassPointers to FSoftObjectPath with MySoftClassPtrObject.ToSoftObjectPath(), and have all the FSoftObjectPath in a TArray
  5. Get the FStreamableManager& reference from your Singleton.
  6. Call the method RequestAsyncLoad on your FStreamableManager&.

Relevant Doc.

Thank you! This works perfectly. I just have 1 question regarding the references to load array. Is there any way to load all subclasses? My game will have hundreds of objects to load but in the end, they will all be children of around 8 or so parent classes. Since this is for a save/load system, when I save the object, I could just add that to the array and save it and then load the array from disk and then load the classes. If there is no better way to save all subclasses of a class, I’ll do that. But thank you again, I’ve spent the last 2 days trying to figure this out.

No Problem. There isn’t an easy way to load all the subclass of a given type. I set it up so you have to specify exactly what you want to load by putting it in an array. In my own personal projects, I have an actor component dedicated to this; it has array of various types for particles, actor, characters, textures, materials, etc. (Doing it at the ActorComponent level makes it easy to give asyc loading to anything I want)

In your case, I’d recommend learning the Python scripts that work in the editor. First, you’d make dummy structures that can hold one of your SoftClass references, and have the structure be able to be put into a UDataTable. This would allow you to parse your files with python to fill csv files that you could import back into the editor as a UDataTable. By building these csv files/datatables with python, you save the effort putting each thing into the array manually. Of course you’d have to convert the data tables back into SoftClassPointers, and then throw those into the your asyc loader.

I know the nuances of managing data tables in C++, but I can’t help you with Python scripting to parse the editor.

Your solution of saving which items you would want to load back in should work for the most part. Though you could divide your scenes into smaller pieces and micro what you want to load and when.