Open Astra307 opened 2 years ago
Do you have a repro project we can take a look at please?
Generally, the template is a separate asset to the assets that are referenced so when the template is instantiated, the components should attempt to lazy load the assets used in each component.
It sounds like this may not be happening correctly with the anim component 🤔
Yeah, that's my impression. I'll try to reproduce it in a fresh project now.
Hey, managed to reproduce it now in this project: https://playcanvas.com/editor/scene/1552117
Hey, any progress on this issue?
@ellthompson I've had another look at this and it looks like the anim assets are being loaded when the template is instanced into the scene but the anim system is not started/animating when it is done.
Would the recent PR you've done for empty states also fix this as a side effect? https://github.com/playcanvas/engine/pull/5112
hmm.. interesting. Actually it looks like calling anim.rebind() some time after load makes the animations play! (but doing it when the assets load is marked "ready" seems to be too early)
ok, my bad. That "hack" did not work. And this is still very much an issue. To get animations to play they have to be pre-loaded or manually loaded before a template using them are loaded. Otherwise they simply won't play
@ellthompson I've had another look at this and it looks like the anim assets are being loaded when the template is instanced into the scene but the anim system is not started/animating when it is done.
Would the recent PR you've done for empty states also fix this as a side effect? https://github.com/playcanvas/engine/pull/5112
I've just tried this with engine latest and it doesn't solve this particular issue.
@ellthompson Any ideas of workarounds in the short term?
ok, I found a temporary hack that worked: When loading a template that has animations attached to it, wait a bit, then re-load and instantiate the whole thing again.
I've done some investigation on this and it's not a trivial bug 🤔
The issue seems to be in the clone function of the Anim Component (that template instantiate uses under the hood).
It goes through a flow where it copies the data.layers to the clone https://github.com/playcanvas/engine/blob/main/src/framework/components/anim/system.js#L49
However, the animation assets have not loaded yet so the layers animation assignment is blank which means the instantiated Entity has no animations mapped to the states.
The only workaround I have is to load the template asset and animation assets, wait for them to finish (add listeners for the ready callback) and then instantiate the template. But that's not a great workaround
Hey, I noticed it looks like this issue has been fixed!
.. eexcept some issue with shape keys. If you immediately trigger an animation after the entity is instantiated it now plays correctly, except for the shape keys. Briefly playing another animation later on or using the anim.rebind() function on a timeout fixes the problem, making the shape keys effect visible.
After loading a template at run-time into the scene, animated objects in the template do not play.
The issue seems to be that the animation state graph and animation assets that are linked to the objects in the template are not loaded together with the template or no loaded in the right order. Pre-loading these solves the problem, but is not ideal in terms of optimization and can be messy to keep track of.