Trying to Recreate Transform Child Heirarchy to a List

Hi,

I have spent most of the day trying to work out how to ‘copy’ the structure/hierarchy of a transform and all it’s children, grandchildren, etc, but to a different class (structure example below).

I have tried recursion but can’t maintain the order. A ‘flat’ list for example is easy to get but I just can’t get it how I need. Here is an example of the simple class structure I am experimenting with:

        [Serializable]
        public class BasicCopy
        {
            public string Name;
            public List<Transform> Transforms;
        }
    
        public List<BasicCopy> Test;

        public Transform Target;

        void Start()
        {
        	// Iterate through Target and ALL it's children and generate a matching hierarchy/structure using the BasicCopy class
        }

The whole process keeps tying me in knots, and is now driving me insane lol! Any help will be much appreciated.

EDIT: I may have worded this badly. For clarity, I am looking to specify my ‘Target’ transform then recursively find all child transforms, as I find them, they are added to my BasicCopy class, maintaining the same hierarchy/structure as the children.

Here you have an example:

[SerializeField]
public class BasicCopy
{
    public string Name;
    public List<Transform> Transforms;
}

public List<BasicCopy> Test;

public Transform Target;

private void Start()
{
    Test = new List<BasicCopy>();
    Test.Add(GetBasicCopy(Target));
}

private BasicCopy GetBasicCopy(Transform currentTarget)
{
    BasicCopy result = new BasicCopy();
    result.Name = currentTarget.name;
    result.Transforms = new List<Transform>();

    Transform[] childs = currentTarget.GetComponentsInChildren<Transform>();
    foreach (Transform current in childs)
        if (current.parent != null && current.parent.GetInstanceID() == currentTarget.GetInstanceID())
        {
            result.Transforms.Add(current);
            Test.Add(GetBasicCopy(current));
        }

    return result;
}

Try using GetChild and incrementing the index