Signal
A built-in type representing a signal of an Object
.
class Signal
Signal
is a built-in Variant
type that represents a signal of an Object
instance. Like all Variant
types, it can be stored in variables and passed to functions. Signals allow all connected Callable
s (and by extension their respective objects) to listen and react to events, without directly referencing one another. This keeps the code flexible and easier to manage.
In GDScript, signals can be declared with the signal
keyword. In C#, you may use the Signal
attribute on a delegate.
Citizens in SwiftGodot
Conformances
protocol ContentVariantRepresentable
Some of Godot’s builtin classes use ContentType for storage. This needs to be public because it affects their initialization, but SwiftGodot users should never need to conform their types to
ContentVariantRepresentable
.protocol Equatable
A type that can be compared for value equality.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Typealiases
Type members
init(
) Constructs an empty
Signal
with no object nor signal name bound.init(alreadyOwnedContent: ContentType
) init(content: ContentType
) init(from: Signal
) init(object: Object, signal: StringName
) Creates a new
Signal
namedsignal
in the specifiedobject
.static var godotType: Variant.GType
static let zero: ContentType
static func != (lhs: Signal, rhs: Signal
) -> Bool Returns
true
if the signals do not share the same object and name.static func == (lhs: Signal, rhs: Signal
) -> Bool Returns
true
if both signals share the same object and name.
Instance members
var content: ContentType
func connect(callable: Callable, flags: Int64
) -> Int64 Connects this signal to the specified
callable
. Optionalflags
can be also added to configure the connection’s behavior (seeObject.ConnectFlags
constants). You can provide additional arguments to the connectedcallable
by usingCallable/bind()
.func disconnect(callable: Callable
) Disconnects this signal from the specified
Callable
. If the connection does not exist, generates an error. UseisConnected(callable:)
to make sure that the connection exists.func emit(Variant...
) Emits this signal. All
Callable
s connected to this signal will be triggered. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.func getConnections(
) -> GArray Returns an
GArray
of connections for this signal. Each connection is represented as aGDictionary
that contains three entries:func getName(
) -> StringName Returns the name of this signal.
func getObjectId(
) -> Int64 Returns the ID of the object emitting this signal (see
getInstanceId
).func isConnected(callable: Callable
) -> Bool Returns
true
if the specifiedCallable
is connected to this signal.func isNull(
) -> Bool Returns
true
if the signal’s name does not exist in its object, or the object is not valid.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.