How can I create a datatable Uasset with Python ?

Hi, I need to create a datatable through a python script that is to be launched at the project startup. However the DataTableFactory object I’m using doesn’t want to create the datatable I’m asking. I’ve checked everything, the structure S_CarStructure is correctly loaded into dt_factory.struct, but the script_factory_create_file is returning False and I’m oblivious to why.

ait = unreal.AssetImportTask()
ait.filename = "J:/dt_creation/dest.csv"
ait.destination_path = '/Game'
ait.automated = True
ait.save = True
dt_factory = unreal.DataTableFactory()
dt_factory.struct = unreal.load_asset("/Game/S_CarStructure")
print(dt_factory.script_factory_create_file(ait))

I’ve been trying to search online for answers for ages but still haven’t found a solution. Any help would be much appreciated !

Thanks.

Not sure if you are still looking for the answer, but I’m fiddling with this problem and find a solution.

The following python code works for me in Unreal 5.6.

asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
row_struct = unreal.load_object(None, f"/Script/{module_name}.{struct_name}")
factory = unreal.DataTableFactory()
factory.struct = row_struct
data_table = asset_tools.create_asset(dt_name, datatable_dest_dir, unreal.DataTable, factory)
1 Like