Download

Python Commandlet and AssetRegistry

Hey everyone, so I’ve been trying to scrape some material values from UE. I have a py script that works when run in the Editor directly and when I run through commandline with ExecutePythonScript but not if I do it as a Commandlet…

When I run this script I expect that it will output a decently high number (running in the editor I get 150+)



import os
import unreal

curr_dir = os.path.dirname(os.path.realpath(__file__))

asset_reg = unreal.AssetRegistryHelpers.get_asset_registry()
filter = unreal.ARFilter(class_names="MaterialInstanceConstant"], package_paths="/Game/Materials"], recursive_paths=True)

assets = asset_reg.get_assets(filter)

with open("{}/assets.txt".format(curr_dir), "w") as f:
    f.write(str(len(assets)))


but when run in cmdlet I get 0.

Is there just no way to get assets in py commandlets?

EDIT: This turned out to be PEBKAC, I forgot to set the uproject when running the cmd.