I have a soft class reference (TSoftClassPtr) and want to get the name of the class without loading it? Is this possible and if so how would I do this?
I’ve noticed when I use “Get Display Name” in Blueprints it automatically resolves the soft class reference, but I don’t want to load the whole class, I just need to get the name of it.
Doing this in C++. Would love some pointers (excuse the pun!)
Hi @HappyKat100
I see for UE5.3 class TSoftClassPtr is defined in .\Engine\Source\Runtime\CoreUObject\Public\UObject\SoftObjectPtr.h.
I’d search through that for some “pointers”
The Soft Object Pointer is basically a very simple thing: it contains a path to an asset (which best not be empty), and it contains a pointer to an instance of that asset (which can be empty). When not loaded, the pointer is empty and it only has the path.
This means that things that aren’t part of the actual path are largely going to be inaccessible when the object isn’t loaded. Display Name, for instance, is a thing which only exists on certain classes; it’s not a part of the actual path or anything. And if you want to access data stored inside the actual asset, it somewhat of necessity needs to load the asset.
Think of it like a wallet. You’ve picked up a wallet someone left on a table, and you want to know who to return it to. And you’re privacy-conscious, so you don’t want to open this other person’s wallet! However, the driver’s license is inside the wallet, so you kind of must open the wallet in order to read the license, to know who to give the wallet back to.
In this case, Display Name is a piece of data inside that metaphorical wallet; you can see the wallet, you can hold the wallet, you can do stuff with it, but if you want to know anything inside it, you do have to open it. If that makes sense?
(You can, however, get the asset name – basically, the thing that shows in the content browser – from a Soft Object Pointer, as that is part of the path. Or do something like make a string table mapping paths to friendly display text, then use the path to look up the display name. Then make an editor scripting tool that generates the string table automatically from the display name field.)