The task is include blueprint asset based on C++ class to C++ code.
I tryed two options.
Use FObjectFinder
// Connect data base in BP
static ConstructorHelpers::FObjectFinder<UDreampaxItemsDataAsset> DreampaxItemsDataAssetBPClass(TEXT("DreampaxItemsDataAsset'/Game/Items/BP_DreampaxDataAsset.BP_DreampaxDataAsset'"));
if (DreampaxItemsDataAssetBPClass.Object != NULL)
{
DreampaxItemsDataAssetClass = DreampaxItemsDataAssetBPClass.Object; // assign our class
DreampaxItemsDataAsset = DreampaxItemsDataAssetClass->GetDefaultObject<UDreampaxItemsDataAsset>(); // create it
}
This code can find my BP DataAsset, however next code doesn’t work due to fault of assignment
// Connect data base in BP
static ConstructorHelpers::FClassFinder<UDataAsset> DreampaxItemsDataAssetBPClass(TEXT("DataAsset'/Game/Items/BP_DreampaxDataAsset.BP_DreampaxDataAsset'"));
if (DreampaxItemsDataAssetBPClass.Class != NULL)
{
DreampaxItemsDataAssetClass = DreampaxItemsDataAssetBPClass.Class; // assign our class
DreampaxItemsDataAsset = DreampaxItemsDataAssetClass->GetDefaultObject<UDreampaxItemsDataAsset>(); // create it
}
No any problems with compilation and assignment.
Nevertheless, this code is not able to find the BP file.
I tryed many variants:
Something is really odd in what you trying to do. DataAssets are not Blueprints and they don’t generate class and assets are already instantiated UObject.
So DreampaxItemsDataAssetBPClass.Object should already be UDreampaxItemsDataAsset you looking for.
What you trying to is what you would do if you trying to get class of a blueprint from blueprint asset (UBlueprint), but here you trying to get DataAsset which is compliantly different assert type. And technicly your UDreampaxItemsDataAsset (that i assume it extends from UDataAsset) is asset type by it self, UDataAsset is just easy way to make new asset type, without need to register new asset type in code and without making new UFactory for it.
Yes, you are right. Sometimes I don’t understand how to do somethings due to absence of expirience and proper education.
I have Blueprint DataAsset. This data asset derived from C++ class UDreampaxItemsDataAsset. This C++ class derived from UDataAsset, you are right again.
In the Blueprint DataAsset (BP_DreampaxDataAsset) I have some data. I need to use this data in C++ code.
UCLASS()
//class ADreampaxGameMode : public AGameModeBase
class ADreampaxGameMode : public AGameMode
{
GENERATED_BODY()
public:
ADreampaxGameMode(const FObjectInitializer& ObjectInitializer);
// Connect data base in BP
UPROPERTY(EditDefaultsOnly, Category = "Items Database")
class UDreampaxItemsDataAsset* DreampaxItemsDataAsset;
// To link BP class and C++ code to avoid ConstructorHelpers
UPROPERTY(EditDefaultsOnly, Category = "Default Player")
TSubclassOf<class APawn> DefaultDreampaxCharacterClass;
Create BP for GameMode derived from C++ class above.