Download

Loading object from content browser?

Hello, I’m trying to load+create a UObject – **EQ_Gun **from the content browser. It’s a blueprint based on the class UEQBase.

A UEQBase object is created fine, but it’s the empty class, not the specific blueprinted version with my values in it.



FSoftObjectPath path("/Game/Data/Ranged/EQ_Gun.EQ_Gun");
UObject* asset = path.TryLoad();

UBlueprint* bp = Cast<UBlueprint>(asset);
UEQBase* equip = NewObject<UEQBase>(bp->GeneratedClass);

I’ve tried a number of combinations, from NewObject directly on the asset var, casting things, etc, but it always just spawns the empty class object, not the blueprint.

The weapons are being loaded in dynamically from the path, so I can’t use and hard TSubclassOf references unfortunately.

How can I do this properly? Thanks!

Maybe you can try ClassFinder in constructor:
ConstructorHelpers::FClassFinder<ParentClass> ClassVar(TEXT(“ROUTE”)

Or using LoadObject in methods(BeginPlay?):
UClass* BPClass = LoadObject< UClass> (nullptr,TEXT(“ROUTE”));

EDIT: Figured out the problem

Empty class:


UEQBase* equip = NewObject<UEQBase>(bp->GeneratedClass);

Working as intended:


UEQBase* equip = NewObject<UEQBase>(this, bp->GeneratedClass);

The first param is the outer, and there happens to be an outer-only overloaded version. So I was passing my class in as the outer, without actually supplying the class lol.