bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.89k stars 3.54k forks source link

(0.12 regression) Can't play animation in more than one scene #10512

Closed ostwilkens closed 11 months ago

ostwilkens commented 11 months ago

Bevy version

0.12

[Optional] Relevant system information

2023-11-11T21:29:02.719346Z  INFO bevy_winit::system: Creating new window "App" (0v0)
2023-11-11T21:29:03.010640Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 2070", vendor: 4318, device: 7938, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "536.67", backend: Vulkan }
2023-11-11T21:29:03.653577Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Education", kernel: "19045", cpu: "Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz", core_count: "6", memory: "31.9 GiB" }

What you did

Refer to the same Handle<AnimationClip> on two AnimationPlayers

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, setup_scene_once_loaded)
        .run();
}

#[derive(Resource)]
struct Animation(Handle<AnimationClip>);

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.insert_resource(Animation(asset_server.load("foxes.glb#Animation0")));
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(0.0, 0.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
    commands.spawn(SceneBundle {
        scene: asset_server.load("foxes.glb#Scene0"),
        ..default()
    });
    commands.spawn(SceneBundle {
        scene: asset_server.load("foxes.glb#Scene1"),
        ..default()
    });
}

fn setup_scene_once_loaded(
    animation: Res<Animation>,
    mut players: Query<&mut AnimationPlayer, Added<AnimationPlayer>>,
) {
    for mut player in &mut players {
        player.play(animation.0.clone()).repeat();
    }
}

foxes.glb minimal reproduction project.zip

What went wrong

Additional information

The issue appeared after migrating from 0.11 to 0.12

idanarye commented 11 months ago

Aren't Scene0 and Scene1 different scenes? Are you sure Animation0 fits them both?

What happens when you try to play it only on Scene1?

ostwilkens commented 11 months ago

Aren't Scene0 and Scene1 different scenes? Are you sure Animation0 fits them both?

Yes, Scene1 is a clone of Scene0.

What happens when you try to play it only on Scene1?

I can't believe I didn't try this! It fails as well. That's even more weird, seeing as the scenes are identical. This means the title isn't accurate, but I have no theories about what's happening. I will have to do more testing.

For context, my game uses a single .glb containing multiple rigged scenes, which use the same animations (as they are all humanoids).

image

nicopap commented 11 months ago

FYI you can edit the title by using the "edit" button right next to the title.

This might be caused by the root entity name's not matching. This was removed, as it was considered a bug.

Consider using identical names for your scenes. If it's not possible in your 3D editor (for example, in blender), consider using https://github.com/nicopap/bevy-scene-hook to swap the name when the scene is spawned.

ostwilkens commented 11 months ago

@nicopap Thank you for checking in on this issue!

I was confused as to how an entity name is relevant, as my animations (Actions) in blender AFAIK aren't connected to a specific scene. I just store them in the file.

image

However, you prompted me to look into the structure of the exported GLTF file. And apparently, all animations are re-exported for each scene!

image

So I guess this issue was born out of my lack of GLTF understanding, combined with a bevy bug, which I saw as a feature 😀

I will load each separate animation for the corresponding character, and it should work. Closing.