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