Add_child issue in tool script.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Inces

I have a GridMap extending tool script. I populate grid with mesh intances, and when I set save var to true GridMap is supposed to save placeholders locations and data into file. That works. The same goes for loading, when it is set to true, GridMap is reading saved file, and its child serving as container ( Spatial ) is supposed to add_child of recreated mesh instances placeholders.

Problem is, upon loading, placeholders are recreated but not seen as children of Spatial node. They are visible on the map, I suspect they are orphaned, perhaps only “placeholder.new()” code was resolved, without “Spatial.add_child()”. No error is shown in console, visible mesh instances are unselectable in editor. I menaged to redo tool code, so I get references to placeholders into array, and clearing this array in setget tool script is the only way to get rid of those orphans.

I have avoided using tool in the past. Can anyone recognize this issue ? Is adding children in tool script bad practice ?