Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animations and animation state graphs do not load properly with templates #4696

Open
Astra307 opened this issue Oct 5, 2022 · 11 comments
Open
Labels
area: animation Animation related issue bug

Comments

@Astra307
Copy link

Astra307 commented Oct 5, 2022

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.

@mvaligursky mvaligursky added the area: animation Animation related issue label Oct 5, 2022
@yaustar
Copy link
Contributor

yaustar commented Oct 5, 2022

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 🤔

@yaustar yaustar added the bug label Oct 5, 2022
@Astra307
Copy link
Author

Astra307 commented Oct 5, 2022

Yeah, that's my impression. I'll try to reproduce it in a fresh project now.

@Astra307
Copy link
Author

Astra307 commented Oct 5, 2022

Hey, managed to reproduce it now in this project: https://playcanvas.com/editor/scene/1552117

@Astra307
Copy link
Author

Astra307 commented Mar 1, 2023

Hey, any progress on this issue?

@yaustar
Copy link
Contributor

yaustar commented Mar 1, 2023

@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? #5112

@Astra307
Copy link
Author

Astra307 commented Mar 1, 2023

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)

@Astra307
Copy link
Author

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

@yaustar
Copy link
Contributor

yaustar commented Mar 16, 2023

@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? #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?

@Astra307
Copy link
Author

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.

@yaustar
Copy link
Contributor

yaustar commented Mar 16, 2023

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

@Astra307
Copy link
Author

Astra307 commented Jun 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: animation Animation related issue bug
Projects
None yet
Development

No branches or pull requests

4 participants