fn update(&mut self, engine: &mut Engine, delta_time: f32){
let game_state_ref = engine.get_game_state();
let game_state = game_state_ref.borrow_mut();
for entity in game_state.get_entities() {
let ai_component = game_state.get_component_ai_mut(*entity).unwrap();
ai_component.update(delta_time)
}
}
The compiler won't let me borrow the game_state
type Rc<RefCell<GameState>>
reference as mutable. Does anyone have an idea on how to solve or work around this problem?
error[E0502]: cannot borrow `game_state` as mutable because it is also borrowed as immutable
--> src/systems/ai_system.rs:27:32
|
26 | for entity in game_state.get_entities() {
| -------------------------
| |
| immutable borrow occurs here
| immutable borrow later used here
27 | let ai_component = game_state.get_component_ai_mut(*entity).unwrap();
| ^^^^^^^^^^ mutable borrow occurs here