Download

FObjectFinder Asset reference syntax and how to convert to c++ base class

Hello,

I am stuck with a little problem.

I have a vehicle definition asset with this reference (copy reference in content browser): Blueprint’/Game/VehicleAdvCPP/VehicleDef.VehicleDef’

which is derived from a Blueprintable c++ Class UVehicleDefinition.


UCLASS(BlueprintType, Blueprintable)
class TANKGAME_API UVehicleDefinition : public UDataAsset
{
}

Reading through the forums it looks like I have to load this object into a UBlueprint class, however I would like to get a pointer to UVehicleDefinition.
Here is the code I use to find the object


	ConstructorHelpers::FObjectFinder<UBlueprint> CHFVehicleDefinition(TEXT("Blueprint'/Game/VehicleAdvCPP/VehicleDef.VehicleDef'"));

	UVehicleDefinition* PVehicleDefinition = CHFVehicleDefinition.Object;

Why does this not work? What is the right way to load a Blueprint derived from C++ and retrieve a C++ pointer?


	ConstructorHelpers::FObjectFinder<UVehicleDefinition> CHFVehicleDefinition(TEXT("Vehicle'/Game/VehicleAdvCPP/VehicleDef.VehicleDef'"));

	UVehicleDefinition* PVehicleDefinition = CHFVehicleDefinition.Object;

The example in the mid seems to find the object, the second one doesn’t.

Is there any C++ tutorial or documentation about loading assets with asset references?

Thank you in advance

I found a solution to my problem.

UVehicleDefinition derives from UDataAsset, so I should have created a “DataAsset” and chose VehicleDefinition instead of creating a Blueprint DataAsset from it.
This solves my problem.



ConstructorHelpers::FObjectFinder<UVehicleDefinition> CHFVehicleDefinition(TEXT("VehicleDefinition'/Game/VehicleAdvCPP/VehicleDef.VehicleDef'"));

	UVehicleDefinition * PV = CHFVehicleDefinition.Object;

However I am curious, it looks like UBlueprint acts like a container around the native class it is based on, shouldn’t it be possible to access a native c++ pointer to the class somehow?

Thanks and Mark!