[SOLVED] Reloading asset causes "asset.getPreferredFile is not a function" error

Hello, I’ve been working on a system to unload and reload assets using asset IDs and for some reason when I load, unload, then attempt to reload an asset, on the reload the PlayCanvas engine gets this error: "
playcanvas-stable.dbg.js:25932 Uncaught TypeError: asset.getPreferredFile is not a function". Anyone know what could be happening here?

For some textures I noticed if I don’t unload the material (but still unload the textures themselves) the error seemed to go away. But, now I’m trying to unload a texture that isn’t part of a material and I’m still getting the error.

I can provide more detailed debug logs if that’s helpful, but just trying to see if anyone could point me in the right direction, posting the whole asset loading system or trying to create a minimal, reproduceable example would be somewhat impractical.

Is this on one particular type of asset? Is it possible to reproduce in a new small project? We can’t really advise without seeing the logic path that you are going through.

It’s weird that it’s no longer a function, maybe there is a typo somewhere where it’s given a value?

I understand, it’s for any texture asset that gets unloaded and an attempt to load it again causes that error. If I get some time I’ll put together a test project, but I appreciate your help.

I can supply the full asset object from the debugger if that helps. Wait a seccond, it’s the asset name. I might’ve screwed something up here…

Damnit, I’m an idiot. I forgot to get the asset with the asset name and pass that asset object to “load()”. I mistakenly was just passing the asset name straight into the load function. My bad!

1 Like

I do miss type checking sometimes :sob: