Skip to content

Python

Asset Doctor’s editor subsystem, TAAssetDoctorSubsystem, exposes its scan, fix and export functions to Blueprint and Python. Use them in editor scripts, Editor Utility Widgets or Editor Utility Blueprints.

import unreal
doctor = unreal.get_editor_subsystem(unreal.TAAssetDoctorSubsystem)

In Blueprint, get the editor subsystem and use the functions in the ta Asset Doctor category.

Python Blueprint Returns
scan_paths(package_paths, show_progress=True) Scan Paths Array of TAAssetDoctorIssue
scan_project(show_progress=True) Scan Project Array of TAAssetDoctorIssue
scan_assets(assets, show_progress=True) Scan Assets Array of TAAssetDoctorIssue
apply_fixes(issues) Apply Fixes Number of assets changed
get_referencing_packages(asset_path) Get Referencing Packages Array of package names
export_report(issues, file_path) Export Report True if the file was written

Scans every asset in the given folders and their subfolders, for example ["/Game/Props"]. Assets in Excluded Paths are skipped.

  • package_paths: list of package paths.
  • show_progress: show a progress dialog with a Cancel button. The dialog only appears in the editor when more than 100 assets are scanned. If the user cancels, the issues found so far are returned.

Scans the Included Paths from the settings, skipping Excluded Paths. This is what Scan project does in the panel.

Scans a specific list of assets (unreal.AssetData). Assets in Excluded Paths are skipped.

Applies every automatic fix in the list and returns the number of assets changed. Issues without an automatic fix are ignored. Unlike the panel, there is no confirmation dialog.

  • Renames update references and the renamed assets are saved immediately. With Fix Up Redirectors After Rename enabled (default), the redirectors left behind are fixed up as well.
  • Texture setting changes leave the assets unsaved. Save them yourself, for example with unreal.EditorLoadingAndSavingUtils.save_dirty_packages.
  • If several rename fixes target the same asset, only one is applied; a Naming.Convention rename takes priority.

Returns the packages that reference the asset, according to the Asset Registry (hard and soft references), sorted by name. asset_path is a SoftObjectPath, for example an issue’s asset_path. References from C++ code, config files or string paths are not included.

Writes the issues to a file. A .csv file name writes CSV; any other extension writes JSON. Missing folders are created. See Report formats for the fields.

Each issue is a unreal.TAAssetDoctorIssue with these read-only properties:

Property Type Meaning
asset_path SoftObjectPath Object path of the asset, for example /Game/Props/Rock.Rock
asset_class Name Class of the asset, for example StaticMesh
rule_id Name Rule that reported the issue, for example Naming.Convention
severity TAAssetDoctorSeverity INFO, WARNING or ERROR
message Text Issue message
fix_type TAAssetDoctorFixType NONE (fix by hand), RENAME or CUSTOM (the rule knows how to fix it)
fix_data str For rename fixes, the new asset name
referencer_count int Number of other packages that reference the asset, -1 if unknown

Scan results are sorted by severity (errors first), then by asset path and rule id.

import unreal
doctor = unreal.get_editor_subsystem(unreal.TAAssetDoctorSubsystem)
issues = doctor.scan_paths(["/Game/Props", "/Game/Characters"], False)
for issue in issues:
print(issue.severity, issue.rule_id, issue.asset_path, issue.message)
doctor.export_report(issues, "C:/Temp/asset_doctor.json")
errors = [i for i in issues if i.severity == unreal.TAAssetDoctorSeverity.ERROR]
unreal.log("Asset Doctor found {} error(s)".format(len(errors)))
renames = [i for i in issues if i.fix_type == unreal.TAAssetDoctorFixType.RENAME]
for issue in renames:
print(issue.asset_path, "->", issue.fix_data)
changed = doctor.apply_fixes(renames)
unreal.log("Renamed {} asset(s)".format(changed))
texture_fixes = [
i for i in issues
if str(i.rule_id).startswith("Texture.") and i.fix_type == unreal.TAAssetDoctorFixType.CUSTOM
]
doctor.apply_fixes(texture_fixes)
# Texture fixes leave the assets unsaved. This saves all dirty content packages.
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(False, True)

Check the assets selected in the Content Browser

Section titled “Check the assets selected in the Content Browser”
selected = unreal.EditorUtilityLibrary.get_selected_asset_data()
issues = doctor.scan_assets(selected, True)
for issue in issues:
if issue.referencer_count == 0:
print("Possibly unused:", issue.asset_path)

Only assets that have at least one issue are returned by a scan, so this lists unreferenced assets among those. Check them in the Reference Viewer before deleting anything.