Skip to content

Commit 8b37feb

Browse files
committed
Add InstanceId::lookup_validity()
1 parent ccd67dc commit 8b37feb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

godot-core/src/obj/gd.rs

+3
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,12 @@ impl<T: GodotClass> Gd<T> {
209209

210210
/// ⚠️ Looks up the given instance ID and returns the associated object.
211211
///
212+
/// Corresponds to Godot's global function `instance_from_id()`.
213+
///
212214
/// # Panics
213215
/// If no such instance ID is registered, or if the dynamic type of the object behind that instance ID
214216
/// is not compatible with `T`.
217+
#[doc(alias = "instance_from_id")]
215218
pub fn from_instance_id(instance_id: InstanceId) -> Self {
216219
Self::try_from_instance_id(instance_id).unwrap_or_else(|err| {
217220
panic!(

godot-core/src/obj/instance_id.rs

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ impl InstanceId {
5858
self.to_u64() & (1u64 << 63) != 0
5959
}
6060

61+
/// Dynamically checks if the instance behind the ID exists.
62+
///
63+
/// Rather slow, involves engine round-trip plus object DB lookup. If you need the object, use
64+
/// [`Gd::from_instance_id()`][crate::obj::Gd::from_instance_id] instead.
65+
///
66+
/// This corresponds to Godot's global function `is_instance_id_valid()`.
67+
#[doc(alias = "is_instance_id_valid")]
68+
pub fn lookup_validity(self) -> bool {
69+
crate::gen::utilities::is_instance_id_valid(self.to_i64())
70+
}
71+
6172
// Private: see rationale above
6273
pub(crate) fn to_u64(self) -> u64 {
6374
self.value.get()

0 commit comments

Comments
 (0)