Gd<T>::bind_mut() failed, already bound
Reason
This error typically occurs when you attempt to get a mutable borrow (bind_mut()
) of a Godot object that is already borrowed (either immutably or mutably). A common scenario is calling self.to_gd().bind_mut()
.
Solutions
Choose one of the following solutions:
-
(Recommended) Avoid
self.to_gd().bind_mut()
. Instead, useself.base_mut().some_base_method()
to call methods on the base class mutably. -
Change Function Signature: If you are passing the object to another function, consider passing a mutable reference to your struct type (
&mut MyClass
) instead ofGd<MyClass>
, if feasible. This allows direct field access in the receiving function without needingbind_mut
. -
Use
base_mut()
Guard Carefully:
fn custom_method(&mut self) { let gd = self.to_gd(); // guard let _guard = self.base_mut(); // now it's safe to call bind gd.bind()}