Skip to content

Unique name search finds node outside the subscene if not found in the subscene #107678

Open
@Klaim

Description

@Klaim

Tested versions

Tested with Godot 4.4.1-stable, on Windows only

System information

Godot v4.4.1.stable - Windows 11 (build 26100) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 Ti (NVIDIA; 32.0.15.7270) - AMD Ryzen 9 5900X 12-Core Processor (24 threads)

Issue description

The following setup is basically what I have seen in my game project:

Image

Note that some_object is not marked with a unique name. In the original project that was a mistake, but the bug made it very much harder to spot, because it finds a node from somewhere else and manipulates it, which lead to surprisingly obscure behaviors.

Here is a scene using that A scene as a subscene:

Image

Note that some_object is marked with a unique name.

The script from A's node:

extends Node2D

@onready var some_object = %some_object

func _ready() -> void:
	print("some_object = ", some_object)
	if some_object:
		print("where: ", some_object.get_path())

results in:

some_object = some_object:<Node#29276243270>
where: /root/main/some_object

But we expect:

some_object = null

This behavior directly contradicts the documentation:
Both the tooltip and the documentation for unique scene names explicitly specifies that in this case the scene A being a subscene should not find a node which exists outside of it's children, same name or not.

Image

Image

Steps to reproduce

In a new project:

  • create a main scene
  • create another scene, say A.tscn
  • in A scene, add a child node and name it some_object DO NOT MAKE IT UNIQUE
  • add the script above to A's root node
  • add A.tscn as child node of the main scene
  • add a Node to the main scene with the name some_object and make it a unique scene name
  • run the project

Minimal reproduction project (MRP)

test_repro_unique_name.zip

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