thanks in Advance
What is meant by packedScene? how it differ from normal? i am little confused.
pardon me. if i posted the question on the wrong forum. I'm new here.
- Edited
@Zrcl13 said: pardon me. if i posted the question on the wrong forum. I'm new here.
No problem, I moved it. Alas i haven't really used packedScene so not entirely sure what it is. From a quick glance at the docs it seems like a way to save a node and it's children to disk, I guess an example use case might be nodes you have created during run-time(from code) that you want to be preserved between sessions perhaps.
you can se how kidsCanCode are using it in this example :dizzy:
From what I understand, a PackedScene is the entire scene stored in memory and/or on the file system. You cannot directly edit in code PackedScene, and so you need to instance it to turn it into a normal Scene. Once the PackedScene is a normal Scene, you can edit, change, or do whatever you need to it like normal.
Where you mainly interact and use PackedScene objects is when you use Load("path_to_scene.tscn")
or preload("path_to_scene.tscn")
, as both of these return PackedScene objects when loading scene files. That is why you have to do something like this: add_child(load("path_to_scene").instance())
to add a different scene into another from code.
(You can also exported PackedScene's if you want to set them from the editor: exported(PackedScene) var scene_file
. This works similar to load
, but instead of putting in the resource path, you can select the scene you want to load from the editor)
As far as I know, PackedScene objects are pretty much used exclusively for saving/loading scene files to and from memory and the file system. Personally I have not really used PackedScene, at least not directly. I think I have only used it once and that was to in a exported variable, but in the couple years or so I have used Godot I cannot really remember using it that much outside of load
and preload
.
Hopefully this helps :smile: