Skip to content

Add a way to append a component to NodePath #13777

@timothyqiu

Description

@timothyqiu

Describe the project you are working on

An in-game inspector.

Describe the problem or limitation you are having in your project

When trying to build a NodePath from Tree hierarchy, I found that NodePath API is lacking.

var path := ^"Hello"

# You can't do any of this currently.
path = path.join("World")
path += "/World"

# It has to be converted to String, changed, then converted to NodePath again.
path = str(path).path_join("World")
path = str(path) + "/World"

NodePath stores path components as a vector. Converting it to a string involves string concatenation.

It's a waste converting back and forth for appending a component to the path.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add APIs for NodePath manipulation.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

var path := ^"Hello"

# Add operator+ to append a NodePath / StringName / String
var another := ^"World"
another += path
# `another` is now `World/Hello`
# operator+ acts the same as `join()` described below

# Use `join()` to append a NodePath / StringName / String
path.join("World")
# Hello/World

# If conditions permit, support for variadic arguments may also be provided.
path.join("foo", "bar", "baz")
# Hello/foo/bar/baz

If this enhancement will not be used often, can it be worked around with a few lines of script?

No.

Is there a reason why this should be core and not an add-on in the asset library?

Core API related.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions