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

Invalidated Entity's #29

Closed
zicklag opened this issue Nov 8, 2022 · 6 comments · Fixed by #31
Closed

Invalidated Entity's #29

zicklag opened this issue Nov 8, 2022 · 6 comments · Fixed by #31

Comments

@zicklag
Copy link
Contributor

zicklag commented Nov 8, 2022

To answer your side question:

GGRS rewinds by loading an old state and overwriting current values. When loading a snapshot, items that have been deleted will have to be recreated and thus get a new entity id. In the same time, your inventory will be overwritten with the entity id vector it had at that point in time. These IDs will then probably be invalid.

Originally posted by @gschup in #11 (comment)


I started a new thread to avoid cluttering the other one.

So, if the entities in an inventory component could end up invalidated by the rollback, does that mean Bevy's hierarchy could get corrupted too?

Because the hierarchy works by having Parent and Children components where Entitys are used for references, similar to an inventory.

@gschup
Copy link
Owner

gschup commented Nov 8, 2022

You raise a valid concern. I did not think about hierarchical entities when writing this plugin. I have not tried it, but I doubt it would work.

@gschup
Copy link
Owner

gschup commented Nov 8, 2022

I will take a deeper look into this on the weekend. The more I learn about bevy, the more I am certain that this version of the bevy_ggrs plugin is a prototpye that needs a rewrite :D

@zicklag
Copy link
Contributor Author

zicklag commented Nov 8, 2022

Yeah, I'll be thinking about this too.

I like that this plugin isn't super complicated anyway. I did a little bit of looking at the ggrs crate API and it's pretty simple, too. Good job.


While brainstorming I was wondering if we could have a sub-world that we do the rollback system in, which would have it's own entities, and could we somehow snapshot the entire world, including it's entities, and then have like an extract phase similar to how is used for Bevy rendering to pull the needed components into the normal Bevy world before rendering.

I don't actually think that would work with the current state of Bevy, but it's food for thought. I'm still thinking... :D

@zicklag
Copy link
Contributor Author

zicklag commented Nov 9, 2022

Something maybe to look into is Bevy's DynamicScene and also the EntityMap used to write DynamicScenes to the world.

@zicklag
Copy link
Contributor Author

zicklag commented Nov 9, 2022

Aha! This code is key to how Bevy imports hierarchy's from scene files:

        for registration in type_registry.iter() {
            if let Some(map_entities_reflect) = registration.data::<ReflectMapEntities>() {
                map_entities_reflect
                    .map_entities(world, entity_map)
                    .unwrap();
            }
        }

It uses ReflectMapEntities to update all the Parent and Children components with the mapped entities.

I'm still fitting this together in my head, but I think we can make this work with that.

@zicklag zicklag changed the title [Discussion] Invalidated Entity's Invalidated Entity's Nov 29, 2022
@zicklag
Copy link
Contributor Author

zicklag commented Nov 29, 2022

I just found that invalidating entities is still an issue, but luckily I also discovered the fix we need in the bevy_hierarchy crate. Just posting here for a heads-up in case anybody runs into it:

bevyengine/bevy#6790

For now, in my game I've just patched Bevy with the PR linked in the issue above to fix it.

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.

2 participants