Struct Signal
pub struct Signal { /* private fields */ }
Expand description
A Signal
represents a signal of an Object instance in Godot.
Signals are composed of a reference to an Object
and the name of the signal on this object.
§Godot docs
Implementations§
§impl Signal
impl Signal
pub fn from_object_signal<T, S>(object: &Gd<T>, signal_name: S) -> Signal
pub fn from_object_signal<T, S>(object: &Gd<T>, signal_name: S) -> Signal
Create a signal for the signal object::signal_name
.
Godot equivalent: Signal(Object object, StringName signal)
pub fn invalid() -> Signal
pub fn invalid() -> Signal
Creates an invalid/empty signal that cannot be called.
Godot equivalent: Signal()
pub fn connect(&self, callable: &Callable, flags: i64) -> Error
pub fn connect(&self, callable: &Callable, flags: i64) -> Error
Connects this signal to the specified callable.
Optional flags can be also added to configure the connection’s behavior (see ConnectFlags
constants).
You can provide additional arguments to the connected callable by using Callable::bind
.
A signal can only be connected once to the same Callable
. If the signal is already connected,
returns Error::ERR_INVALID_PARAMETER
and
pushes an error message, unless the signal is connected with ConnectFlags::REFERENCE_COUNTED
.
To prevent this, use Self::is_connected
first to check for existing connections.
pub fn disconnect(&self, callable: &Callable)
pub fn disconnect(&self, callable: &Callable)
Disconnects this signal from the specified Callable
.
If the connection does not exist, generates an error. Use Self::is_connected
to make sure that the connection exists.
pub fn emit(&self, varargs: &[Variant])
pub fn emit(&self, varargs: &[Variant])
Emits this signal.
All Callables connected to this signal will be triggered.
pub fn connections(&self) -> Array<Dictionary>
pub fn connections(&self) -> Array<Dictionary>
Returns an Array
of connections for this signal.
Each connection is represented as a Dictionary that contains three entries:
signal
is a reference to thisSignal
;callable
is a reference to the connectedCallable
;flags
is a combination ofConnectFlags
.
Godot equivalent: get_connections
pub fn name(&self) -> StringName
pub fn name(&self) -> StringName
Returns the name of the signal.
pub fn object(&self) -> Option<Gd<Object>>
pub fn object(&self) -> Option<Gd<Object>>
Returns the object to which this signal belongs.
Returns None
when this signal doesn’t have any object, or the object is dead. You can differentiate these two situations using
object_id()
.
Godot equivalent: get_object
pub fn object_id(&self) -> Option<InstanceId>
pub fn object_id(&self) -> Option<InstanceId>
Returns the ID of this signal’s object, see also Gd::instance_id
.
Returns None
when this signal doesn’t have any object.
If the pointed-to object is dead, the ID will still be returned. Use object()
to check for liveness.
Godot equivalent: get_object_id
pub fn is_connected(&self, callable: &Callable) -> bool
pub fn is_connected(&self, callable: &Callable) -> bool
Returns true
if the specified Callable
is connected to this signal.
Trait Implementations§
§impl FromGodot for Signal
impl FromGodot for Signal
§fn try_from_godot(
via: <Signal as GodotConvert>::Via,
) -> Result<Signal, ConvertError>
fn try_from_godot( via: <Signal as GodotConvert>::Via, ) -> Result<Signal, ConvertError>
Err
on failure.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl ParamType for Signal
impl ParamType for Signal
§fn owned_to_arg<'v>(self) -> <Signal as ParamType>::Arg<'v>
fn owned_to_arg<'v>(self) -> <Signal as ParamType>::Arg<'v>
impl AsArg<T>
. Read more§impl ToGodot for Signal
impl ToGodot for Signal
§impl Var for Signal
impl Var for Signal
fn get_property(&self) -> <Signal as GodotConvert>::Via
fn set_property(&mut self, value: <Signal as GodotConvert>::Via)
§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.