Search code examples
game-developmentgdscriptgodot4

load a scene that Pack Scene at runtime with nodes that have script added at runtime


I add some nodes with script at runtime in godot4 and want to make scn from them then load them. the issue is when I load scn file node that has script missing. I save and load scn at runtime. also nodes added at runtime.

the interesting part is if I drag and drop scn file in edit time, the script of that scn file is attached. when I want to pack scene, I change owner of node to grand parent (parent of all of them).


Solution

  • I found the answer, the issue is I build nodes from script at runtime with code which has classes that has parameters with _init. I saved that node in .scn format and when I load node which has script, because constructor of script take parameters and node is read from file and not instantiated from code, error raised.