Function Node.getNodeAndResource
Fetches a node and one of its resources as specified by the NodePath
's subname (e.g. Area2D/CollisionShape2D:shape
). If several nested resources are specified in the NodePath
, the last one will be fetched.
The return value is an array of size 3: the first index points to the Node
(or null
if not found), the second index points to the Resource
(or null
if not found), and the third index is the remaining NodePath
, if any.
For example, assuming that Area2D/CollisionShape2D
is a valid node and that its shape
property has been assigned a RectangleShape2D
resource, one could have this kind of output:
print(get_node_and_resource("Area2D/CollisionShape2D")) # [CollisionShape2D:1161
, Null, ]
print(get_node_and_resource("Area2D/CollisionShape2D:shape")) # [CollisionShape2D:1161
, RectangleShape2D:1156
, ]
print(get_node_and_resource("Area2D/CollisionShape2D:shape:extents")) # [CollisionShape2D:1161
, RectangleShape2D:1156
, :extents]