godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.82k stars 21.14k forks source link

CheckBox: `ButtonGroup` is `local_to_scene` by default #71440

Open Scony opened 1 year ago

Scony commented 1 year ago

Godot version

4.0 beta (master @ 14.01.2023)

System information

Linux Manjaro

Issue description

When trying to create radio buttons one has to create ButtonGroup resource and copy-paste it to other nodes from the group.

However, since the ButtonGroup resource is local_to_scene by default at the moment, simple copy-pasting won't work. local_to_scene will make copy-pasted resource actually different.

Therefore to make radio buttons working, one has to remove local_to_scene flag from ButtonGroup resource and then copy-paste.

Steps to reproduce

  1. Create a simple Control scene
  2. Add 2x CheckBox
  3. Create ButtonGroup on 1st CheckBox
  4. Copy-paste the ButtonGroup resource from 1st to 2nd CheckBox
  5. Run and observe the issue

Minimal reproduction project

N/A

KoBeWi commented 1 year ago

This has nothing to do with CheckBox being local_to_scene by default, but it was like that since a503f8aadcb8cbc85bde589fb25ea06e599b367b Seems like copying a local_to_scene resource makes it unique. It's a new thing, it wasn't like that before. It works correctly if you duplicate the node with the resource.

RedMser commented 1 year ago

@KoBeWi This is caused by the logic added in #59472, since this ends up running Make Unique on the pasted resource. Here's some debug prints:

print_line(edited_resource->is_built_in());     // true
print_line(edited_resource->get_path());        // ""
print_line(EditorNode::get_singleton()->
    get_edited_scene()->get_scene_file_path()); // "res://node.tscn"

The resource has an empty path, which breaks this logic. After saving, the resource's path is filled, and the logic works as expected.