Table of Contents

Class ObjectRef

Namespace
Cobilas.GodotEngine.Utility
Assembly
com.cobilas.godot.utility.dll

Represents a reference to a Godot node with automatic path resolution and node caching.

[Serializable]
public class ObjectRef
Inheritance
ObjectRef
Derived
Inherited Members

Remarks

This class provides a convenient way to store and resolve node references in Godot, with implicit conversions between NodePath, string, and Node types.

Constructors

ObjectRef()

Initializes a new instance of the ObjectRef class with empty path and null node.

public ObjectRef()

ObjectRef(NodePath)

Initializes a new instance of the ObjectRef class with the specified node path.

protected ObjectRef(NodePath path)

Parameters

path NodePath

The node path to initialize the reference with.

Fields

node

The cached node instance resolved from the path.

protected Node node

Field Value

Node

path

The path to the node in the Godot scene tree.

protected NodePath path

Field Value

NodePath

Operators

implicit operator Node(ObjectRef?)

Implicitly converts an ObjectRef to a Godot.Node.

public static implicit operator Node(ObjectRef? obj)

Parameters

obj ObjectRef

The ObjectRef to convert.

Returns

Node

The resolved Node instance.

Remarks

This operator automatically resolves the node from the stored path and caches it. If the node's path has changed, it will re-resolve the node from the stored path.

Exceptions

ArgumentNullException

Thrown when obj is null.

implicit operator NodePath(ObjectRef?)

Implicitly converts an ObjectRef to a Godot.NodePath.

public static implicit operator NodePath(ObjectRef? obj)

Parameters

obj ObjectRef

The ObjectRef to convert.

Returns

NodePath

The NodePath stored in the ObjectRef.

Exceptions

ArgumentNullException

Thrown when obj is null.

implicit operator string(ObjectRef?)

Implicitly converts an ObjectRef to a string.

public static implicit operator string(ObjectRef? obj)

Parameters

obj ObjectRef

The ObjectRef to convert.

Returns

string

The string representation of the NodePath.

Exceptions

ArgumentNullException

Thrown when obj is null.

implicit operator ObjectRef(NodePath?)

Implicitly converts a Godot.NodePath to an ObjectRef.

public static implicit operator ObjectRef(NodePath? obj)

Parameters

obj NodePath

The NodePath to convert.

Returns

ObjectRef

A new ObjectRef instance with the specified NodePath.

Exceptions

ArgumentNullException

Thrown when obj is null.

implicit operator ObjectRef(string?)

Implicitly converts a string to an ObjectRef.

public static implicit operator ObjectRef(string? obj)

Parameters

obj string

The string representing a node path to convert.

Returns

ObjectRef

A new ObjectRef instance with the specified node path.

Exceptions

ArgumentNullException

Thrown when obj is null.