Morp Animations not loading when unloading / loading Assets

So I have a project which includes various 3D Avatars that are big in Size. Older iPhones have the problem that they crash safari when too much RAM is used. So I am unloading the assets of avatars I am not currently showing and then loading them again whenever I need them. This works fine, except for morphs in animations.

I have two examples here:

In this example, the morphs are first loaded correctly as you can see by the blinking and the mouth animation better. Special about it, is that the assets have “Preload” on. You can then click the button “Unload” to unload all the assets of the avatar, and then press “Load” again and you will see, that now the morph animation has been lost. When unloading and then loading again while debuging with “Launch” I receive the following error (which is not shown in published builds):

morph-instance.js:197 Uncaught TypeError: Cannot read properties of null (reading '_targets')
    at MorphInstance.setWeight (morph-instance.js:197:55)
    at Array.func (default-anim-binder.js:94:47)
    at AnimTarget.callSetters [as _set] (default-anim-binder.js:104:39)
    at AnimEvaluator.update (anim-evaluator.js:264:35)
    at AnimController.update (anim-controller.js:582:29)
    at AnimComponentLayer.update (component-layer.js:257:26)
    at AnimComponent.update (component.js:732:28)
    at AnimComponentSystem.onAnimationUpdate (system.js:84:31)
    at ComponentSystemRegistry.fire (event-handler.js:201:26)
    at Application.update (app-base.js:1171:22)

In this example I do not preload any of the avatars assets and here the morph animations never seem to load. But this also does not throw any errors in when Debugging.

So how do I set it up correctly in order for morph animations to always be loaded correctly. Are there certain assets, that I am not allowed to unload and must be preloaded in order to work properly?

If anyone is interested, I can provide read access to the project.

Okay I think I’ve figured it out.

It works when I do the following:

The (Container) Asset of the .GLB must have “Preload” enabled and is not allowed to be unloaded. Also when unloading and loading the anim component on the entity must be .rebind() and .reset().

It is not an optimal solution since this means that if you have 10x a 5MB Container item, you must always preload the 50MB and can never unload it. I cannot yet say, if this leads to RAM Crashes on certain devices.

Is there the possiblity that this can be addressed in the engine? I think the main issue lies in the container asset not setting up the morphs correctly when not preloaded & loaded through scripts.

It looks like you may be hitting this issue which should be fixed with the release of 1.62 (still in preview mode) Animations and animation state graphs do not load properly with templates · Issue #4696 · playcanvas/engine · GitHub

1 Like

I’m not 100% sure that the related PR fixes the issue as this is about morph targets.

If it doesn’t, can you create an Engine ticket about this please?

1 Like

Will do! Thank you very much for your replies!