Object

package
v0.0.0-...-7c34d27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package Object provides methods for working with Object instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T gd.IsClass](value gd.IsClass) T

As attempts to cast the given class to T, returning the casted value if successful, or panicking if not.

func Is

func Is[T gd.IsClass](value gd.IsClass) (T, bool)

Is attempts to cast the given class to T, returning true if the cast was successful.

func Use

func Use(obj interface{ AsObject() [1]gdclass.Object })

Use keeps an object alive, preventing it from being garbage collected until the next frame.

Types

type Advanced

type Advanced [1]gdclass.Object

func (Advanced) AsObject

func (obj Advanced) AsObject() [1]gd.Object

func (*Advanced) UnsafePointer

func (self *Advanced) UnsafePointer() unsafe.Pointer

func (Advanced) Virtual

func (obj Advanced) Virtual(name string) reflect.Value

Virtual method lookup.

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID uniquely and opaquely identifies an Object instance.

func (ID) Instance

func (id ID) Instance() Instance

Instance returns the Object instance identified by this ID.

type Instance

type Instance [1]gdclass.Object

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.

func New

func New() Instance

New creates a new Object instance.

func (Instance) AsObject

func (obj Instance) AsObject() [1]gd.Object

func (Instance) CanTranslateMessages

func (obj Instance) CanTranslateMessages() bool

CanTranslateMessages returns true if the object is allowed to translate messages with tr and tr_n. See also Instance.SetMessageTranslation.

func (Instance) ClassName

func (obj Instance) ClassName() string

ClassName returns the object's built-in class name, as a string.

func (Instance) ID

func (obj Instance) ID() 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) 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

func (obj Instance) Script() ([1]gdclass.Script, bool)

ScriptInstance returns the object's Script instance, or false if no script is attached.

func (Instance) SetMessageTranslation

func (obj Instance) SetMessageTranslation(enable bool)

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

func (obj Instance) SetScript(script [1]gdclass.Script)

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

func (obj Instance) SetSignalsBlocked(enable bool)

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) SignalsBlocked

func (obj Instance) SignalsBlocked() bool

SignalsBlocked returns true if the object is blocking its signals from being emitted. See Instance.SetSignalsBlocked.

func (Instance) String

func (obj Instance) String() 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

func (obj Instance) Translate(message string) string

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

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (obj Instance) Virtual(name string) reflect.Value

Virtual method lookup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL