Whenever I duplicate objects it puts it in a strange and wrong order inside the hierarchy. How to change this?

Whenever I duplicate objects it puts it in a strange and wrong order inside the hierarchy.

Anybody know why and how to solve this?

Or you could write some easy Editor script like:

using UnityEditor;
using UnityEngine;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public class HierarchySorter : Editor
{
    [MenuItem("GameObject/Sort Children Alphabetically", false, 0)]
    private static void SortChildrenAlphabetically()
    {
        if (Selection.activeGameObject == null)
        {
            Debug.LogWarning("No GameObject selected.");
            return;
        }

        GameObject selectedObject = Selection.activeGameObject;
        var children = selectedObject.transform.Cast<Transform>().ToList();

        children = children.OrderBy(child => child.name).ToList();

        for (int i = 0; i < children.Count; i++)
        {
            children[i].SetSiblingIndex(i);
        }
    }

    [MenuItem("GameObject/Sort Children by Index", false, 1)]
    private static void SortChildrenByIndex()
    {
        if (Selection.activeGameObject == null)
        {
            Debug.LogWarning("No GameObject selected.");
            return;
        }

        GameObject selectedObject = Selection.activeGameObject;
        var children = selectedObject.transform.Cast<Transform>().ToList();

        children = children.OrderBy(child => ExtractNumber(child.name)).ToList();

        for (int i = 0; i < children.Count; i++)
        {
            children[i].SetSiblingIndex(i);
        }
    }

    private static int ExtractNumber(string name)
    {
        // Extract the number from the end of the string using a regular expression
        var match = Regex.Match(name, @"\d+$");
        return match.Success ? int.Parse(match.Value) : int.MaxValue;
    }
}

Rember to drop it into Editor folder, then right click and chose Sort Children Alphabetically or Sort Children by Index… maybe this will do

This is just how unity duplicates, one way of keeping them in correct numbering Is when you duplicate, unity makes you select all the new duplicates, So you can drag those to the bottom, Then the ordering will be correct.

Maybe this will help:

https://forum.unity.com/threads/how-to-alphabetically-sort-your-hierarchy-unity-5.371567/