Edit a custom Data Asset with Python

Hello. I have been running my head against the wall for the last few days, trying out everything and now finally have to throw in the towel, hopefully someone can point me in the right direction. I’m trying to create a custom DataAsset (Defined in c++), with Python and populating data in it.

Here are some code examples (I have stripped out all code that was not needed for this example):
C++ UDataAsset:

class CUSTOM_API TestDataAsset: public UDataAsset
{
GENERATED_BODY()
//…
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=“Imposter Animation Data”)
FName Name = NAME_None;

  //......

}

Python Script Creating asset:

import unreal

Set the asset name and path

asset_name = “MyDataAsset”
asset_path = “/Game/Custom/Path”

Get the global unreal module

ue = unreal

Create a new data asset factory

data_asset_factory = unreal.DataAssetFactory()

Set the data asset class

data_asset_class = unreal.load_class(None, “/Script/CUSTOM.TestDataAsset”)

my_data_asset = unreal.AssetToolsHelpers.get_asset_tools().create_asset(asset_name, asset_path, data_asset_class, unreal.DataAssetFactory())

print(my_data_asset)
my_data_asset.Name = “My Data Asset”
unreal.EditorAssetLibrary.save_loaded_asset(my_data_asset)

The python script creates the correct data Asset, but when I try to set the property Name it early outs with this error:

LogPython: Error: Traceback (most recent call last):
LogPython: Error: File “C:/mads_LAPTOP-8O39NGT2_main_2852/Svalinn/SourceContent/Animation/AnimationPrototype/Thirdperson/LODAnimations/Tooling/UnrealImporter.py”, line 19, in
LogPython: Error: my_data_asset.Name = “My Data Asset”
LogPython: Error: AttributeError: ‘SvCharacterImposterAnimationData’ object has no attribute ‘Name’

I really hope someone have experience with a problem like this as I’m completely stuck and its important for the workflow we are setting up.

In case someone else runs into this, apparently the base object has a set_property() method, simply changing

my_data_asset.Name = “My Data Asset”

to

my_data_asset.set_editor_property(“Name”, “Bob”)

Solved the issue, this makes a lot of sense but was supper hard to find

3 Likes

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