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.
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
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):
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
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