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

Unable to directly spawn gltf that does not require components #102

Closed
GitGhillie opened this issue Jan 19, 2024 · 12 comments · Fixed by #134
Closed

Unable to directly spawn gltf that does not require components #102

GitGhillie opened this issue Jan 19, 2024 · 12 comments · Fixed by #134

Comments

@GitGhillie
Copy link
Contributor

GitGhillie commented Jan 19, 2024

I want to spawn a scene and because of an issue I ran into (Jondolf/avian#304 if you want more context) I figured I would just spawn it directly during Startup, as this scene doesn't have any components that need to be added using bevy_gltf_components. However, this results in a panic with message "this gltf should have been loaded".

It's not too bad to work around but I'm guessing it's not the intended behavior of the crate.

@czettnersandor
Copy link
Contributor

@GitGhillie how did you workaround this?

@GitGhillie
Copy link
Contributor Author

@GitGhillie how did you workaround this?

My idea was to use bevy_asset_loader as I do normally with bevy_gltf_components, and then delay spawning one of the scenes like so:

.add_systems(OnEnter(GameState::AssetsLoaded), spawn_A)
.add_systems(
    OnEnter(GameState::AssetsLoaded),
    spawn_B.run_if(on_timer(Duration::new(5, 0))),
)

However, this does not work and only spawns one of A and B... which means the issue I had with bevy_xpbd is maybe an issue with bevy_asset_loader instead. Need to find a different workaround :(

@kaosat-dev
Copy link
Owner

kaosat-dev commented Jan 19, 2024

I want to spawn a scene and because of an issue I ran into (Jondolf/bevy_xpbd#304 if you want more context) I figured I would just spawn it directly during Startup, as this scene doesn't have any components that need to be added using bevy_gltf_components. However, this results in a panic with message "this gltf should have been loaded".

It's not too bad to work around but I'm guessing it's not the intended behavior of the crate.

hmm that is a scenario I did not encounter before, thanks for the bug report !
I think it might make sense to change the way the gltf loading tracking is handled in bevy_gltf_components so that it gives you a warning, and does not blow up in your face/panics.
(this is way overdue, as I also want to deal with dropping un-needed gltf handles that are kept around in the asset tracker).

So changing track_new_gltf (excuse the poor code quality, very tired & sick)

 let handle = asset_server.get_id_handle(*id);
            if let Some(handle) = handle {
                tracker.add_gltf(handle.clone());
                debug!("gltf created {:?}", handle.clone());
            }else {
                warn!("this gltf should have been loaded, no handle available, not processing it")
            }
            ```

@GitGhillie
Copy link
Contributor Author

That seems to do the trick! Now I'm running into an issue where the scene loaded with the asset loader only rarely shows up, but I think that's then something to do with bevy_asset_loader.

@kaosat-dev
Copy link
Owner

@GitGhillie is its a random failure of a scene to show up ?
I had such issues back in Bevy 0.11 where scenes would get randomly unloaded directly after being loaded, had not had those issues since then.
Have you tried forcing the creation of a strong handle manually to prevent the issue ?

@GitGhillie
Copy link
Contributor Author

I made a minimal example to illustrate the problem I'm having with bevy/bevy_asset_loader: https://github.com/GitGhillie/asset_loading_mre/blob/main/src/main.rs

Not sure how to manually create a strong handle but appending #Scene0 to the paths fixes the scenes randomly getting swapped. With my Bevy 0.11 project I was already doing this but now with 0.12 it seems like bevy_gltf_components doesn't work when a scene is spawned with #Scene0. I'm getting "this gltf should have been loaded, no handle available, not processing it" from your hotfix.

@kaosat-dev
Copy link
Owner

@GitGhillie I suddenly remembered that I faced this issue as well !
When using #scene it unloads the gltf file, the handle is lost, that is why I switched to loading the full gltf files in the examples
I had noted it down as being related to this issue, so it might work on main

@GitGhillie
Copy link
Contributor Author

Hmm I think the fix for that already lives on 0.12.1 :( When I have more time I'll try to make a minimal reproducer without bevy_asset_loader, then I can also easily test against bevy main

@GitGhillie
Copy link
Contributor Author

I moved the discussion about asset loading here btw NiklasEi/bevy_asset_loader#182

kaosat-dev added a commit that referenced this issue Jan 31, 2024
…annot be found (#108)

* added some minor extra debug information
* removed a useless clone() call on the gltf handle
* should resolve at least a part of #102
@kaosat-dev
Copy link
Owner

Hi @GitGhillie would you mind trying out this pr to see if it solve your issues ?

@GitGhillie
Copy link
Contributor Author

Looks like it works! I can now load with and without using #Scene0 and with or without components

@kaosat-dev
Copy link
Owner

Awesome , thanks for trying it out so quickly !

kaosat-dev added a commit that referenced this issue Feb 19, 2024
…ltf extras (#134)

 * not using / tracking gltf files anymore (should avoid issues with scenes vs gltf files)
 * restructured accordingly
 * closes #102
 * closes #111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants