title: Bevyengine Panic on despawn
body: <p>I use bevy 0.6 and rapierphysics_2d 0.12.0
  I have panic as a result of clearing my scene. I have two functions below::</p>
  <pre><code>fn cleanup_player(mut commands: Commands, player_data: Res&lt;PlayerData&gt;, query: Query&lt;Entity&gt;) {
    commands
        .entity(player_data.player_entity)
        .despawn_recursive();
    commands
        .entity(player_data.camera_entity)
        .despawn_recursive();
  }
  
  fn cleanup(mut commands: Commands, query: Query&lt;Entity&gt;) {
    for entity in query.iter() {
        commands.entity(entity).despawn_recursive();
    }
  }
  </code></pre>
  <p>As you can see they are just despawn created earlier entities. But it causes a panic if I use any of it.</p>
  <p>I'm actually trying to invoke them on changing from InGame to MainMenu(by pressing ESC)</p>
  <pre><code>impl Plugin for PugPlugin {
      fn build(&amp;self, app: &amp;mut App) {
          app.add_plugin(RapierPhysicsPlugin::&lt;NoUserData&gt;::default())
          .add_system(camera_follow_player.label(&quot;Camera system&quot;))
              .add_system_set(
                  SystemSet::on_enter(crate::AppState::InGame)
                      .with_system(sprite_spawn)
                      .with_system(spawn_floor),
              )
              .add_system_set(
                  SystemSet::on_update(crate::AppState::InGame)
                      .with_system(check_delete)
                      .with_system(myphysics::player_jumps.label(&quot;Player Jumps System&quot;))
                      .with_system(myphysics::jump_reset.label(&quot;Jump Reset System&quot;))
                      .with_system(myphysics::player_movement.label(&quot;Player Movement System&quot;))
                      .with_system(death_by_height.label(&quot;Death system&quot;))
                      ,
              )
               .add_system_set(SystemSet::on_exit(AppState::InGame).with_system(cleanup).with_system(cleanup_player))
              ;
      }
  }
  </code></pre>
  <p>You can see the system set at the end. So I want to switch to main menu from InGame Set, it's not working.</p>
  <p>P.s just clean function is also not working inside a scene even without any transitions to MainMenu or smth. So I can't even just delete any entity from my game.</p>
  <pre class="lang-none prettyprint-override"><code>thread 'Compute Task Pool (0)' panicked at 'Attempting to create an EntityCommands for entity 1v1, which doesn't exist.', /Users/Alexander/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier2d-0.12.0/src/physics/resources.rs:240:26
  </code></pre>
  <p><a href="https://github.com/asinchenko/NamiWorld" rel="nofollow noreferrer">https://github.com/asinchenko/NamiWorld</a></p>