@@ -47,14 +47,14 @@ impl Variant {
47
47
48
48
/// Create a variant holding a non-nil value.
49
49
///
50
- /// Equivalent to `value.to_variant()`.
50
+ /// Equivalent to [ `value.to_variant()`][ToGodot::to_variant], but consumes the argument .
51
51
pub fn from < T : ToGodot > ( value : T ) -> Self {
52
52
value. to_variant ( )
53
53
}
54
54
55
55
/// ⚠️ Convert to type `T`, panicking on failure.
56
56
///
57
- /// Equivalent to `T::from_variant(&self)`.
57
+ /// Equivalent to [ `T::from_variant(&self)`][FromGodot::from_variant] .
58
58
///
59
59
/// # Panics
60
60
/// When this variant holds a different type.
@@ -64,14 +64,14 @@ impl Variant {
64
64
65
65
/// Convert to type `T`, returning `Err` on failure.
66
66
///
67
- /// Equivalent to `T::try_from_variant(&self)`.
67
+ /// Equivalent to [ `T::try_from_variant(&self)`][FromGodot::try_from_variant] .
68
68
pub fn try_to < T : FromGodot > ( & self ) -> Result < T , ConvertError > {
69
69
T :: try_from_variant ( self )
70
70
}
71
71
72
72
/// Checks whether the variant is empty (`null` value in GDScript).
73
73
///
74
- /// See also [`Self::get_type` ].
74
+ /// See also [`get_type()`][ Self::get_type].
75
75
pub fn is_nil ( & self ) -> bool {
76
76
// Use get_type() rather than sys_type(), to also cover nullptr OBJECT as NIL
77
77
self . get_type ( ) == VariantType :: NIL
@@ -80,8 +80,8 @@ impl Variant {
80
80
/// Returns the type that is currently held by this variant.
81
81
///
82
82
/// If this variant holds a type `Object` but no instance (represented as a null object pointer), then `Nil` will be returned for
83
- /// consistency. This may deviate from Godot behavior -- for example, calling `Node::get_node_or_null()` with an invalid
84
- /// path returns a variant that has type `Object` but acts like `Nil` for all practical purposes.
83
+ /// consistency. This may deviate from Godot behavior -- for example, calling [ `Node::get_node_or_null()`][crate::classes::Node::get_node_or_null]
84
+ /// with an invalid path returns a variant that has type `Object` but acts like `Nil` for all practical purposes.
85
85
pub fn get_type ( & self ) -> VariantType {
86
86
let sys_type = self . sys_type ( ) ;
87
87
@@ -107,6 +107,20 @@ impl Variant {
107
107
}
108
108
}
109
109
110
+ /// For variants holding an object, returns the object's instance ID.
111
+ ///
112
+ /// If the variant is not an object, returns `None`.
113
+ ///
114
+ /// If the object is dead, the instance ID is still returned. Use [`Variant::try_to::<Gd<T>>()`][Self::try_to]
115
+ /// to retrieve only live objects.
116
+ #[ cfg( since_api = "4.4" ) ]
117
+ pub fn object_id ( & self ) -> Option < crate :: obj:: InstanceId > {
118
+ // SAFETY: safe to call for non-object variants (returns 0).
119
+ let raw_id: u64 = unsafe { interface_fn ! ( variant_get_object_instance_id) ( self . var_sys ( ) ) } ;
120
+
121
+ crate :: obj:: InstanceId :: try_from_u64 ( raw_id)
122
+ }
123
+
110
124
/// ⚠️ Calls the specified `method` with the given `args`.
111
125
///
112
126
/// Supports `Object` as well as built-ins with methods (e.g. `Array`, `Vector3`, `GString`, etc.).
0 commit comments