Skip to content

tools: Add script to check for orphan assets - #2787

Merged
wjt merged 2 commits into
mainfrom
orphans-tool
Sep 7, 2026
Merged

tools: Add script to check for orphan assets#2787
wjt merged 2 commits into
mainfrom
orphans-tool

Conversation

@manuq

@manuq manuq commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

I've been using this in StoryQuests submissions.

StoryQuests: Remove unused assets

Using the output of tools/check_orphan_assets.gd and confirming that they are
also not referenced from scripts by filename or UID.

Except for Champ, because these assets could be actual placeholders.

I've been using this in StoryQuests submissions.
@github-actions

Copy link
Copy Markdown

Play this branch at https://play.threadbare.game/branches/endlessm/orphans-tool/.

(This launches the game from the start, not directly at the change(s) in this pull request.)

@manuq
manuq marked this pull request as ready for review August 25, 2026 18:11
@manuq
manuq requested a review from a team as a code owner August 25, 2026 18:11
Using the output of tools/check_orphan_assets.gd and confirming that they are
also not referenced from scripts by filename or UID.
@manuq
manuq requested review from a team as code owners August 25, 2026 18:25
@manuq

manuq commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

@wjt wjt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is useful, let's ship it!

I can think of some changes I might make - noted below - but this is the kind of script that we can incrementally improve as we use it.

## Extensions considered assets, lowercase and without the dot.
const ASSET_EXTENSIONS: PackedStringArray = [
"png", "jpg", "jpeg", "webp", "svg", "ogg", "wav", "mp3", "ttf", "otf", "ogv"
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to see whether this hardcoded list could be avoided. For example, .dialogue files are potentially-orphaned "assets" of a sort...

I tried using ResourceLoader.list_directory() rather than the DirAccess methods. By definition this only includes files that Godot recognises as resources (which includes .gd files but not, for example, Markdown files). It also includes files where you have an .import file but the corresponding file has been deleted (!!) but only because the imported texture (for example) is in the .godot cache.

Not sure it's an improvement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this list is actually the file extensions in .gitattributes, excluding files not recognized by Godot (currently just .aseprite). Let me check with ResourceLoader.list_directory()!.

Comment on lines +99 to +102
for directory: String in DirAccess.get_directories_at(current):
# Godot's own cache holds copies of everything and would count as
# references to assets that are otherwise unused.
if directory != ".godot":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you use the non-static methods of DirAccess - i.e. open the dir with DirAccess.open() then iterate d.get_directories() - then you could use the include_hidden property (i.e. set it to false) to avoid having to filter this by hand.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hints! I will try them.

@wjt
wjt merged commit bfe93c3 into main Sep 7, 2026
7 checks passed
@wjt
wjt deleted the orphans-tool branch September 7, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants