C++ And data assets

Hello everyone.

Im starting a project in unreal engine, and I want to use data assets this time. I know how to use it in blueprints, but I want to use it in c++.

I have a base character class, and I want to have a reference to a data asset (PrimaryDataAsset as CharacterDataAsset in c++)
I’ve already created the child of the CharacterDataAsset on the editor, but I can’t access it on my c++, Im using
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Character”)
TSubclassOf CharacterDataAsset;
To expose it, so I can define it on editor, then I want to access it in my cpp, like CharacterDataAsset->…

What Im doing wrong? Its possible to access the data asset that I’ve created on blueprint as a child of a c++ primary data asset class on my c++? If not, what’s the right way to do it?

I just want to create a PrimaryDataAsset in c++, create a child in blueprint and use the data defined on editor in my c++ code.

Thanks.

Nevermind… I just figure out the problem.

I was creating my data asset with the PrimaryDataAsset class, instead of this, create with the UDataAsset class, after creating the data asset main class, go to your editor and create a new data asset, choose your created data asset as your class.

To reference it in another class, you can do it by importing the header file of you data asset, and doing like UYourDataAssetName* YourDataAssetName;

Then you can simply access it this way: YourDataAssetName->ThePropertyName;

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.