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:
- Tracking uses a thread-local pointer assignment (
@[ThreadLocal]). - Zero heap allocations (0.0 B/op).
- Single machine instruction latency (~0.4 ns in release builds).
- 100% thread-safe across OS threads and multi-threaded worker pools.
Defined in:
libgodot/node_context.crClass Method Summary
-
.current : Node | Nil
Returns the currently executing Godot::Node, if any
-
.current=(node : Node | Nil)
Sets the currently executing Godot::Node
-
.resolve_active_node(path : String) : Node
Resolves a node path against the active node context.
-
.resolve_active_node_as(type : T.class, preferred_name : String | Nil = nil) : T forall T
Resolves a typed node against the active node context.
-
.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).
-
.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.
-
.scope(obj : Object, &)
Scopes execution of a block if the object is a Node, or executes directly.
Class Method Detail
Resolves a node path against the active node context.
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.
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?
Scopes execution of a block to the specified node context, restoring previous context upon exit even if an exception is raised.