Skip to content

Simplify setup_scene_once_loaded in animated_fox#8999

Merged
mockersf merged 1 commit intobevyengine:mainfrom
nicopap:animated-fox-added
Jun 29, 2023
Merged

Simplify setup_scene_once_loaded in animated_fox#8999
mockersf merged 1 commit intobevyengine:mainfrom
nicopap:animated-fox-added

Conversation

@nicopap
Copy link
Copy Markdown
Contributor

@nicopap nicopap commented Jun 29, 2023

Objective

The setup code in animated_fox uses a done boolean to avoid running the play logic repetitively.

It is a common pattern, but it just work with exactly one fox, and misses an even more common pattern.

When a user modifies the code to try it with several foxes, they are confused as to why it doesn't work (#8996).

Solution

The more common pattern is to use Added<AnimationPlayer> as a query filter.

This both reduces complexity and naturally extend the setup code to handle several foxes, added at any time.

Why use a `done: Local<bool>` when `Added<AnimationPlayer>` works as
well?

It is more in line with what we'd usually do in bevy.

An added advantage is that it is more useful as a starting point when
implementing animations in your own game.
@nicopap nicopap added C-Examples An addition or correction to our examples C-Code-Quality A section of code that is hard to understand or change A-Animation Make things move and change over time labels Jun 29, 2023
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 29, 2023
@thmsgntz
Copy link
Copy Markdown
Contributor

thmsgntz commented Jun 29, 2023

I'm happy to see updates in bevy animation crate :)

Does this update also work if the two animations are completely different (different gltf files, mesh and animations)?

How do you know the queried Res<Animations> are the ones used by the new added animationPlayer?

@nicopap
Copy link
Copy Markdown
Contributor Author

nicopap commented Jun 29, 2023

Does this update also work if the two animations are completely different (different gltf files, mesh and animations)?

open the fold named analysis of setup_scene_once_loaded in #8996 (comment) for an answer.

Concerning the issue you mentioned, I've opened something similar: #8357

@mockersf
Copy link
Copy Markdown
Member

I'm happy to see updates in bevy animation crate :)

Sorry to disappoint, this is not an update in the bevy animation crate, just a change in the example.

Does this update also work if the two animations are completely different (different gltf files, mesh and animations)?

It's already possible?

How do you know the queried Res<Animations> are the ones used by the new added animationPlayer?

That's the hard part, you have to keep track of which gltf is loaded where and how it relates to the animation player component added, and it's not on the same entity but as one of its children.

@mockersf mockersf added this pull request to the merge queue Jun 29, 2023
Merged via the queue into bevyengine:main with commit fd32c6f Jun 29, 2023
@nicopap nicopap deleted the animated-fox-added branch August 30, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Animation Make things move and change over time C-Code-Quality A section of code that is hard to understand or change C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants