Ordering of scriptable objects added in asset with AssetDatabase.AddObjectToAsset

So, I made a simple example to test AssetDatabase.AddObjectToAsset. All is serializing perfectly, but I’ve got a weird issue with the ordering. Everytime I add another ScriptableObject to my asset and reimport it, it becomes the new root of my asset. The original root of the asset becomes a child, like that:

2756647--198926--Test.png

Here’s my code:

using UnityEngine;

public class TestParentSO : ScriptableObject
{
    public TestChildSO[] children;
}
using UnityEngine;

public class TestChildSO : ScriptableObject
{
    public int value = 5;
}
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;

[CustomEditor(typeof(TestParentSO))]
public class TestEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        var parent = (TestParentSO) target;
        List<TestChildSO> children = new List<TestChildSO>();
        if (GUILayout.Button("Populate"))
        {
            for (int i = 0; i < 5; i++)
            {
                var child = CreateInstance<TestChildSO>();
                AssetDatabase.AddObjectToAsset(child, parent);
                children.Add(child);
                   
            }
            serializedObject.Update();

            //Method to assign a list to a SerializedProperty Array. Not the issue here
            SerializedObjectUtil.AssignArrayProperty
                (serializedObject.FindProperty("children"), children);
            serializedObject.ApplyModifiedProperties();
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(parent));
        }
    }
}

It does the same thing in 5.3 and 5.4, so it seems it’s not related to a specific version of Unity.

I found that using hideFlags = HideFlags.HideInHierarchy on the children seems to at least prevent the problem, but now it’s impossible to select them in the Project hierarchy. Being able to see them, but in an order that makes sense, would be really nice.