Repository navigation
Add unbind() for reentrant scope - #1708
Merged
Merged
Conversation
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1708 |
Contributor
|
I have skimmed over the changes, and I think it looks the way I expected it to look. 😄 |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 1, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses a long-standing confusion around re-entrancy into objects.
When you have a
&mut self, call into Godot and then somehow call back into the same object, this is called re-entrant. Without special APIs likeself.base_mut()orself.signals().xy().emit()(initialized viaconnect_self()), this causes a double-borrow panic because&mut selfis an exclusive reference that cannot be borrowed again.Closes #916.
Closes #1656.
Closes #1692.
Closes #1697.
Today,
base_mut()can be used as a guard in the following way:You can now do the equivalent with:
Name "unbind" because it's pretty much the reverse operation of
Gd::bind_mut(), which goes fromGd<T>to&mut T. I considered "reentrant" or "reentrant_scope" but I believe this is easier to conceptualize. I'm aware of collision withCallableAPIs, but those are much more niche and can also be renamed tobind_args/unbind_argsor so.Some examples, also in the doc:
Example: reentrant signal
A
Playerowns aWeapon. If that weapon is out of ammo, anout_of_ammosignal is emitted, which links back to thePlayer::reloadmethod. Now ifPlayer::shoot(&mut self)causes the weapon to be empty, that callback needs to access&mut selfagain. This wouldn't normally work since it's already borrowed, butunbind()explicitly allows it.Example: dynamic calls through Godot VM
Hidden turrets pop up when an alarm is raised.
Turret::raise_alarm()notifies all turrets in the group viacall_group(), which re-enterson_alarm()onself. Thenset_visible()synchronously sends theVISIBILITY_CHANGEDnotification, again reentrantly.