Documentation
¶
Overview ¶
Package Object provides methods for working with Object instances.
Index ¶
- func As[T gd.IsClass](value gd.IsClass) (T, bool)
- func Call(object Any, method string, args ...any) any
- func Get(object Any, property string) any
- func HasMethod(object Any, method string) bool
- func InstanceIsValid(obj Any) bool
- func Is[T gd.IsClass](value gd.IsClass) bool
- func Set(object Any, property string, value any)
- func To[T gd.IsClass](value gd.IsClass) T
- func Use(obj interface{ ... })
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (obj Instance) AsObject() [1]gd.Object
- func (obj Instance) CanTranslateMessages() bool
- func (obj Instance) ClassName() string
- func (obj Instance) Connect(signal string, callable any, flags ...Signal.Flags) error
- func (obj Instance) HasMethod(name string) bool
- func (obj Instance) ID() ID
- func (obj Instance) IsConnected(signal string, callable any) bool
- func (obj Instance) NotifyPropertyListChanged()
- func (obj Instance) Script() ([1]gdclass.Script, bool)
- func (obj Instance) SetMessageTranslation(enable bool)
- func (self *Instance) SetObject(obj [1]gdclass.Object) bool
- func (obj Instance) SetScript(script [1]gdclass.Script)
- func (obj Instance) SetSignalsBlocked(enable bool)
- func (obj Instance) Signal(name string) Signal.Any
- func (obj Instance) SignalsBlocked() bool
- func (obj Instance) String() string
- func (obj Instance) Translate(message string) string
- func (obj Instance) Translation(message string, plural_message string, n int, context string) string
- func (self *Instance) UnsafePointer() unsafe.Pointer
- func (obj Instance) Virtual(name string) reflect.Value
- type Interface
- type Notification
- type PropertyInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get returns the Variant value of the given property. If the property does not exist, this method returns null.
Note: property must be in snake_case when referring to built-in Godot properties.
func HasMethod ¶
HasMethod returns true if the given method name exists in the object.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
func InstanceIsValid ¶
InstanceIsValid returns true if the given object instance is valid (the reference has not been invalidated and the object has not been freed).
func Set ¶
Set assigns value to the given property. If the property does not exist or the given value's type doesn't match, nothing happens.
Note: property must be in snake_case when referring to built-in Godot properties.
Types ¶
type Advanced ¶
func (*Advanced) UnsafePointer ¶
type Extension ¶
Extension can be embedded in a struct to create a new class. T should be the type of the struct that embeds this Extension.
type Instance ¶
Instance is an advanced Variant type. All classes in the engine inherit from Object. Each class may define new properties, methods or signals, which are available to all inheriting classes. For example, a Sprite2D instance is able to call Node.add_child because it inherits from Node.
You can create new instances, using New.
Objects can have a Script attached to them. Once the Script is instantiated, it effectively acts as an extension to the base class, allowing it to define and inherit new properties, methods and signals.
Each Interface method can be overidden independently:
type Interface interface { Get(property string) any GetPropertyList() []ClassDB.PropertyInfo Notification(what int, reversed bool) PropertyCanRevert(property string) bool PropertyGetRevert(property string) any Set(property string, value any) bool ToString() string ValidateProperty(ClassDB.PropertyInfo) }
var Nil Instance
Nil is a nil Object instance. Useful for comparisons.
func (Instance) CanTranslateMessages ¶
CanTranslateMessages returns true if the object is allowed to translate messages with tr and tr_n. See also Instance.SetMessageTranslation.
func (Instance) Connect ¶
Connect connects a signal by name to a callable. Optional flags can be also added to configure the connection's behavior (see Signal.Flags constants).
A signal can only be connected once to the same Callable. If the signal is already connected, this method returns Error.InvalidParameter and pushes an error message, unless the signal is connected with [Signal.Weak]. To prevent this, use Instance.IsConnected first to check for existing connections.
If the callable's object is freed, the connection will be lost.
func (Instance) ID ¶
ID returns the object's unique instance ID. This ID can be saved in EncodedObjectAsID, and can be used to retrieve this object instance with ID.Instance.
func (Instance) IsConnected ¶
IsConnected returns true if a connection exists between the given signal name and callable.
func (Instance) NotifyPropertyListChanged ¶
func (obj Instance) NotifyPropertyListChanged()
NotifyPropertyListChanged emits the property_list_changed signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
func (Instance) Script ¶
ScriptInstance returns the object's Script instance, or false if no script is attached.
func (Instance) SetMessageTranslation ¶
SetMessageTranslation if set to true, allows the object to translate messages with tr and tr_n. Enabled by default. See also Instance.CanTranslateMessages.
func (Instance) SetScript ¶
SetScript attaches script to the object, and instantiates it. As a result, the script's _init is called. A Script is used to extend the object's functionality.
If a script already exists, its instance is detached, and its property values and state are lost. Built-in property values are still kept.
func (Instance) SetSignalsBlocked ¶
SetBlockSignals if set to true, the object becomes unable to emit signals. Signal connections will not work, until it is set to false.
func (Instance) Signal ¶
Signal returns the signal with the given name, or a nil signal if it does not exist.
func (Instance) SignalsBlocked ¶
SignalsBlocked returns true if the object is blocking its signals from being emitted. See Instance.SetSignalsBlocked.
func (Instance) String ¶
String returns a String representing the object. Defaults to "<ClassName#RID>". Override _to_string to customize the string representation of the object.
func (Instance) Translate ¶
Translate translates a message, using the translation catalogs configured in the Project Settings. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If Instance.CanTranslateMessages is false, or no translation is available, this method returns the message without changes. See Instance.SetMessageTranslation.
func (Instance) Translation ¶
func (obj Instance) Translation(message string, plural_message string, n int, context string) string
Translation translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If Instance.CanTranslateMessages is false, or no translation is available, this method returns message or plural_message, without changes. See Instance.SetMessageTranslation.
The n is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It's recommended to handle these cases with Instance.Translate.
Note: This method can't be used without an Object instance, as it requires the Instance.CanTranslateMessages method. To translate strings in a static context, use [TranslationServer.TranslatePlural].
func (*Instance) UnsafePointer ¶
type Notification ¶
type Notification int
const ( NotificationPostInitialize Notification = 0 // Notification received when the object is initialized, before its script is attached. Used internally. NotificationPreDelete Notification = 1 // Notification received when the object is about to be deleted. Can be used like destructors in object-oriented programming languages. NotificationExtensionReloaded Notification = 2 // Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived. )