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

Despawn events missed when using FixedUpdate #635

Open
IVSOP opened this issue Feb 14, 2025 · 0 comments
Open

Despawn events missed when using FixedUpdate #635

IVSOP opened this issue Feb 14, 2025 · 0 comments

Comments

@IVSOP
Copy link

IVSOP commented Feb 14, 2025

I followed the custom setup example, but I used FixedUpdate instead of PostUpdate.
I noticed that, sometimes, the bodies/colliders of despawned entities would remain active in the world, when they should have been removed.
After looking into the plugin's setup code, I found

// These *must* be in the main schedule currently so that they do not miss events.
// See test `test_sync_removal` for an example of this.
if self.schedule != PostUpdate.intern() {
    app.add_systems(
        PostUpdate,
        (systems::sync_removals,).before(TransformSystem::TransformPropagate),
    );
}

So, despite using with_default_system_setup(false), self.schedule is still PostUpdate, which means this will not be called and sync_removals will not be placed in the correct schedule. In the example I mentioned, the custom schedule used is PostUpdate, so this issue does not happen.
To fix this, I used with_default_system_setup(false).in_schedule(FixedUpdate), but this feels like a hack since I will still have to register the systems again later.
My use case was I wanted to be able to pause the simulation, so I needed to add the systems and only make them run if the game is in a certain state:

        .configure_sets(
            FixedUpdate,
            (
                PhysicsSet::SyncBackend,
                PhysicsSet::StepSimulation,
                PhysicsSet::Writeback,
            )
                .chain()
                .before(TransformSystem::TransformPropagate),
        )
        .add_systems(
            FixedUpdate,
            (
                RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::SyncBackend)
                    .in_set(PhysicsSet::SyncBackend),
                RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::StepSimulation)
                    .in_set(PhysicsSet::StepSimulation),
                RapierPhysicsPlugin::<NoUserData>::get_systems(PhysicsSet::Writeback)
                    .in_set(PhysicsSet::Writeback),
            )
            .run_if(in_state(GameState::Running)) // only run if game is running
        )
@IVSOP IVSOP changed the title Despawn events missed when using FixedTimestep Despawn events missed when using FixedUpdate Feb 14, 2025
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

No branches or pull requests

1 participant