godotengine / godotengine/godot

Packed child scenes with same UID will not work in a confusing way (one wins out, race condition as to which)

Open
#91,097 13 comments 0 reactions 0 assignees View on GitHub
discussion enhancement topic:editor
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

i've reproduced in 4.2.2 and 4.2.1 and 4.2 stable

### System information

Godot v4.2.2.stable - Pop!_OS 22.04 LTS - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Laptop GPU () - 13th Gen Intel(R) Core(TM) i9-13900H (20 Threads)

### Issue description

i've created a PackedScene with different PackedScenes inside, but the packed scenes don't retain their packed scene type when running the game. they will convert into one or the other when running the game.

### Steps to reproduce

starting with https://github.com/lowagner/triangle/commit/5ee6351fbadedfec994f52531356dd6ba6a576e1 and loading the project in the godot4 subdirectory. opening the project is fine, if you go into the `Room` packed scene, it's an instance of TestRoom. inside the room are a bunch of boxes plus a "MagicBox" at the end.

according to the editor, they are all the same type of PackedScene, a terrain/static-box.tscn scene (TerrainStaticBox class). however, i have created this test scene by creating a bunch of the TerrainStaticBox packed scenes, plus adding a MagicBox scene (from characters/magic-box/magic-box.tscn). it's saved at this point in the git versioning. you can see this if you look at the levels/test-room.tscn file, which has both MagicBox and TerrainStaticBox scenes loaded (e.g., inspect the commit above).

now's where it gets interesting/annoying. after opening up TestRoom in the editor, start the game. all the static boxes in the test room should remain static; the magic box should be a dynamic rigid body. HOWEVER, what actually happens is that everyone becomes either the MagicBox scene or the TerrainStaticBox scene. (if the former, since the magic box has rigidbody physics, everything will start dropping under the influence of gravity. if the latter, everything is static, including the magic box.) even without saving, you'll notice a `git diff` -- it removed the MagicBox external resource type and made everything a StaticBox type (even if everyone was acting as the MagicBox scene). if i clear my godot cache (rm -r .godot) and reload the project, then everything is static of course.

you can also try to add another MagicBox to the TestRoom scene (Ctrl+Shift+A -> then add magic-box.tscn). it will look correct until you try running the game, at which point it will convert into a TerrainStaticBox.

it's clear that i don't want this behavior; i want the editor to know that the MagicBox is a different scene and shouldn't affect the other packed scenes, and similarly for TerrainStaticBox. here is an example git diff after running the game, even without changing anything in the editor. you need to open TestRoom in the editor before it will show this diff:

```
diff --git a/godot4/levels/test-room.tscn b/godot4/levels/test-room.tscn
index 97fc818..6adb555 100644
--- a/godot4/levels/test-room.tscn
+++ b/godot4/levels/test-room.tscn
@@ -1,8 +1,7 @@
-[gd_scene load_steps=4 format=3 uid="uid://b0fpxqceogy4a"]
+[gd_scene load_steps=3 format=3 uid="uid://b0fpxqceogy4a"]

[ext_resource type="Script" path="res://levels/test-room.gd" id="1_0n2oq"]
-[ext_resource type="PackedScene" uid="uid://7dqtlcu57oiv" path="res://characters/magic-box/magic-box.tscn" id="3_8rxya"]
-[ext_resource type="PackedScene" uid="uid://7dqtlcu57oiv" path="res://terrain/static-box.tscn" id="3_yhpnb"]
+[ext_resource type="PackedScene" uid="uid://7dqtlcu57oiv" path="res://terrain/static-box.tscn" id="3_8rxya"]

[node name="TestRoom" type="Node2D"]
script = ExtResource("1_0n2oq")
@@ -14,22 +13,22 @@ z_index = -100
color = Color(0.419608, 0.784314, 0.643137, 1)
polygon = PackedVector2Array(-2048, 2048, 2048, 2048, 2048, -2048, -2048, -2048)

-[node name="StartBox" parent="." instance=ExtResource("3_yhpnb")]
+[node name="StartBox" parent="." instance=ExtResource("3_8rxya")]
position = Vector2(150, 350)
size = Vector2(256, 128)

-[node name="CrookedBox" parent="." instance=ExtResource("3_yhpnb")]
+[node name="CrookedBox" parent="." instance=ExtResource("3_8rxya")]
position = Vector2(284, 604)
rotation = 0.785398
size = Vector2(50, 128)
color = Color(0.858824, 0.188235, 0.466667, 1)

-[node name="ThinBox" parent="." instance=ExtResource("3_yhpnb")]
+[node name="ThinBox" parent="." instance=ExtResource("3_8rxya")]
position = Vector2(518, 434)
size = Vector2(64, 256)
color = Color(0.882353, 0.882353, 0.882353, 1)

-[node name="GroundBox" parent="." instance=ExtResource("3_yhpnb")]
+[node name="GroundBox" parent="." instance=ExtResource("3_8rxya")]
position = Vector2(451, 806)
size = Vector2(2000, 96)
color = Color(0.737255, 0.396078, 0.211765, 1)
```

### Minimal reproduction project (MRP)

N/A yet. i'll work on seeing if i can simplify https://github.com/lowagner/triangle/commit/5ee6351fbadedfec994f52531356dd6ba6a576e1 if this issue isn't already known.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.