Hello everyone!
If this is the wrong forum for this type of question, please guide me in the right direction =)
Anyhow, I might be missing something but when saving a scene in a packedScene, I need to set the owner of instanced scenes to be the same as the scene I'm packing, right? I also have to set the owner of all the children of the instanced scene otherwise these will be discarded and not packed, right?
If this is the correct way to pack a scene, then there might be a bug or I'm missing something(probably the case). Any help/rubber ducking would be appreciated.
I Have set up a small Testproject to test this and I get the same weird result as in my main project.
What I'm doing:
I have set up a main scene with a Node2D as "root" carrying a Kinematic2D with a sprite and a collisionShape2D as children.
so Main Scene:
--MainScene
----Player
-------CollisionShape2D
-------Sprite
I have also set up a secondary scene, the scene I'm instancing during _ready()
the Secondary Scene Tree is identical to the MainScene.
So Secondary Scene:
-SecondScene
---FakePlayer
-----CollisionShape2D
-----Sprite
As I just mentioned, I instance the SecondScene in MainScene _ready() function.
I add this scene as a child on Player. I set the owner to "self.get_tree().current_scene", as this is the scene I'm packing.
I do this for all the children in the instanced scene, as said in the docs.
I pack my Scene with OK results.
I change the scene to the packedScene with a "change_scene_to(packed_scene)"
What I expect the scene tree to look like when loading is done:
MainScene
--Player
----CollisionShape2D
----Sprite
----SecondScene
------FakePlayer(correct values)
--------CollisionShape2D
--------Sprite
What I get:
MainScene
-Player
---CollisionShape2D
---Sprite
-----SecondScene
--------FakePlayer(Incorrect values)
----------CollisionShape2D
----------Sprite
--------FakePlayer(Correct values)
----------CollisionShape2D
----------Sprite
I end up with two copies of the first child of the instanced scene. I didn't mention that i change a variable in the FakePlayer before saving to make sure the values are carried with the save. That's what I mean with "Correct/incorrect Values)
There seems to be a parsing issue because in my saved .tscn
If I remove "instance=ExtResource(2)" from [node name="SecondScene" type="Node2D" parent="Player" instance=ExtResource( 2 )]
I Get the result I expected. So for some reason, the parser decides to add a copy of the SecondScene node(and it's children).
Is this intended or am I doing something wrong?
I apologize for the lengthy post but I tried to be as clear as possible.
Kind regards,
The Toad