Saving complex scene as packedscene at runtime

Godot Version

Godot V4.3 mono stable win64

Question

I’m trying to make a sudoku game.

I have a board GridContainer with 3x3 box PackedScenes instantiated on it. Each box GridContainer has 3x3 tile PackedScenes instantiated as children. Each tile GridContainer has 3x3 possibilityLabel PackedScenes instantiated as children.

The issue is it takes a while to spawn, especially for large boards.
I first thought I could stop the GridContainers from updating while spawning, then allow updates after, but that didn’t work.
I then tried spawning in one box, and duplicating it, but it was missing it’s children.
I then tried spawning in one box, saving it to file as a PackedScene, and then using it in the future, and it was missing all the children.
I tried changing object ownership but that led to a bunch of mess. My code:

private void TestSaveScene(Control cont)
{
    SetOwnerRecursive(cont, cont);
    PackedScene scene = new PackedScene();
    scene.Pack(cont);
    ResourceSaver.Save(scene, $"res://AutoGenerated/box_{width}x{height}.tscn");
}

private void SetOwnerRecursive(Node node, Node owner)
{
    if (node.Owner == null && node != owner)
        node.Owner = owner;
    foreach (Node child in node.GetChildren())
        SetOwnerRecursive(child, owner);
}

Is there a way to save a scene with a bunch of PackedScene children as a PackedScene at runtime? Or a better approach to spawning in my board? Thanks.

Without seeing how your game is actually designed, using co-routines yield and deferring each frame with an animation would be one way to break it up.

I had considered breaking it up into an animation, since this code is just for spawning the board before the game starts, but I wouldn’t want it to take more than a couple seconds. The code that spawns it right now takes 11 to 12 seconds.

Is there a way I could spawn one chunk of the board, then duplicate it instead?