Coder Social home page Coder Social logo

Comments (5)

johanhelsing avatar johanhelsing commented on September 28, 2024

Have you tried registering all the components in spritebundle?

from bevy_ggrs.

PraxTube avatar PraxTube commented on September 28, 2024

Oh damn, I didn't do that. Though even after registering these Components

.register_rollback_component::<Sprite>()
.register_rollback_component::<Handle<Image>>()
.register_rollback_component::<Visibility>()
.register_rollback_component::<ComputedVisibility>()

(not sure if the handle makes any sense), I am still able to trigger the same bug.
The SpriteBundle only has these Components.

pub struct SpriteBundle {
    pub sprite: Sprite,
    pub transform: Transform,
    pub global_transform: GlobalTransform,
    pub texture: Handle<Image>,
    /// User indication of whether an entity is visible
    pub visibility: Visibility,
    /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
    pub computed_visibility: ComputedVisibility,
}

Interestingly, the Sprite gets respawned now, which was not the case when I didn't register them as rollback components, so that definitely helped.
But the player is still invisible.

I just realized that it's probably the handle that is getting dropped? I only have one single handle that references the player sprite (player one and two have different assets). And so perhaps because the handle gets dropped (despawned) we have a handle that doesn't point to anything when we try to respawn it?

EDIT: The handle doesn't seem to be the issue. I spawned an idle Sprite with the same asset that didn't do anything and was just there to be a strong handle for the asset. The issue was still present.

from bevy_ggrs.

ConnorBP avatar ConnorBP commented on September 28, 2024

I am also getting this issue of Rollbacks not restoring everything properly after a despawn_recursive. I would definitely prefer to not have to sync every single component that is attached to the entity to get rollback to work properly. Attached components should be restored when the synced components are restored even if that means registering them somewhere else.

from bevy_ggrs.

clinuxrulz avatar clinuxrulz commented on September 28, 2024

.despawn_recursive() suggests the entity must have child entities.

When rollbacks happen, the restored entities will not have the same ID number they had. Because it is impossible to spawn an entity with a specific entity ID (the ID on spawn is more or less random.)
However there exists Parent and Children components referencing those entity by their ID, that will end up pointing to a non-existent entities on rollback.

See: https://docs.rs/bevy/0.12.1/bevy/hierarchy/struct.Parent.html

So I suggest making the rollback entities single level only with no parents or children. Then use other non-rollback entities with children/etc. constructed with their transforms updated to match the rollback entities.

I had the same problem with SceneBundle when loading gltf files. But resolved it by creating a FollowPlayer component for the separate non-rollback entity containing the SceneBundle to get it to follow the rollback player entity that had no children.

Demo for separating SceneBundle from the player by using FollowPlayer component on separate entity:

from bevy_ggrs.

clinuxrulz avatar clinuxrulz commented on September 28, 2024

If child entities are really required, you would need to implement your own child/parents system with your own IDs and not entity IDs. As only your ID numbers not entity ID numbers can be restored on rollback.

This can still be done efficiently. Create a HashMap resource that maps your IDs to the entity IDs. Update that resource at the start of every GGRS update frame. Use that resource to convert your IDs to actual entity IDs. You can also have a NextID resource for generating unique your-IDs.

Here is some untested code that serves as a proof of concept: https://github.com/clinuxrulz/bevy_rollsafe_hierarchy
It is a replacement for bevy_hierarchy, but works on generated IDs rather than entity IDs.

from bevy_ggrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.