module Godot::NodeContext

Overview

=========================================================================== NodeContext: Active Execution Context for Ergonomic Node Lookups

Manages the active Godot::Node context on the calling thread/fiber, allowing bare/unary operators like ~("$Path") and ~("%Unique") to resolve relative to self without explicit receiver notation.

Performance & Zero-Cost Guarantees:

Defined in:

libgodot/node_context.cr

Class Method Summary

Class Method Detail

def self.current : Node | Nil #

Returns the currently executing Godot::Node, if any


def self.current=(node : Node | Nil) #

Sets the currently executing Godot::Node


def self.resolve_active_node(path : String) : Node #

Resolves a node path against the active node context.


def self.resolve_active_node_as(type : T.class, preferred_name : String | Nil = nil) : T forall T #

Resolves a typed node against the active node context. Tries finding by name first, then scene unique name (%Name), and falls back to searching children of the current self for the first child matching type T.


def self.resolve_active_node_or_nil(type : T.class, preferred_name : String | Nil = nil) : T | Nil forall T #

Resolves a node against the active node context or returns nil (get_node_or_null parity). Handles Class types and nilable union types like (Sprite2D | Nil), returning typed T?


def self.scope(node : Node | Nil, &) #

Scopes execution of a block to the specified node context, restoring previous context upon exit even if an exception is raised.


def self.scope(obj : Object, &) #

Scopes execution of a block if the object is a Node, or executes directly.