Find assets with no references

Is there a trick to this? I looked at AssetRegistry list() but it looks like it lacks support for filtering by that?

Story: I loaded a bunch of textures in and want to remove the ones that are not being used without manually checking all assets.

I’m afraid not. You might be able to use the Editor API to do the filter on a per scene basis (which assets are used in the current loaded scene): https://github.com/playcanvas/editor-api/blob/main/docs/classes/Assets.md

1 Like

If it helps, the dot next to the asset means that it isn’t been referenced in the current scene (there is a bug with JSON script attributes though https://github.com/playcanvas/editor/issues/681):

image

1 Like

In the Editor, open the browser devtools and paste the following:

var a = editor.assets.filter(function(a) { return a.get('type') === 'texture' && editor.call('assets:used:index')[a.get('id')].count > 0; })

for (var i = 0; i < a.length; i++) {
    console.log(a[i].get('name'))
}

This should give you a list of textures that aren’t referenced in the current scene

2 Likes

Very nice.

I modified it by adding a condition, because I hit an “Uncaught TypeError: Cannot read properties of undefined (reading ‘count’)” exception. The following works for me.

var a = editor.assets.filter(function(a) { return a.get('type') === 'texture' && editor.call('assets:used:index')[a.get('id')] && editor.call('assets:used:index')[a.get('id')].count > 0; })

for (var i = 0; i < a.length; i++) {
    console.log(a[i].get('name'))
}

Thanks