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.
Get the subsystem
Section titled “Get the subsystem”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.
Functions
Section titled “Functions”| 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 |
scan_paths
Section titled “scan_paths”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.
scan_project
Section titled “scan_project”Scans the Included Paths from the settings, skipping Excluded Paths. This is what Scan project does in the panel.
scan_assets
Section titled “scan_assets”Scans a specific list of assets (unreal.AssetData). Assets in Excluded Paths are skipped.
apply_fixes
Section titled “apply_fixes”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.Conventionrename takes priority.
get_referencing_packages
Section titled “get_referencing_packages”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.
export_report
Section titled “export_report”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.
Issue fields
Section titled “Issue 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.
Examples
Section titled “Examples”Scan folders and export a report
Section titled “Scan folders and export a report”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")Count errors
Section titled “Count errors”errors = [i for i in issues if i.severity == unreal.TAAssetDoctorSeverity.ERROR]unreal.log("Asset Doctor found {} error(s)".format(len(errors)))Apply only rename fixes
Section titled “Apply only rename fixes”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))Fix texture settings and save
Section titled “Fix texture settings and save”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)List assets nobody references
Section titled “List assets nobody references”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.