How to sort scene components alphabetically or at least reorder them?

I’m getting really frustrated by this thing and I can’t seem to find a solution:

Scene components are randomly placed in the actor hierarchy, they don’t seem to follow any rule…

If I duplicate one of these, the new ones are added in the middle or in some random position:

They are declared and attached in the desired order, I also tried to add the metatags “DisplayPriority” and “DisplayAfter” but nothing changes

.h File
	AAntheaCharacter_Arkan_M();

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	class USkeletalMeshComponent *AntennaeComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *BladeComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *ChestAdditionComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *ChestComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *GauntletComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *GemComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *GloveComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *HornComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *KabutoComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *NeckComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *NecklaceComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *ShoulderAdditionComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *ShoulderComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *TrouserComponent;
.cpp File
AAntheaCharacter_Arkan_M::AAntheaCharacter_Arkan_M()                                                                                        
{                                                                                                                                           
	auto BodyMesh = ACharacter::GetMesh();                                                                                                  
                                                                                                                                            
	AntennaeComponent = CreateDefaultSubobject<USkeletalMeshComponent>("AntennaeComponent");                                                
	AntennaeComponent->SetupAttachment(BodyMesh);                                                                                           
                                                                                                                                            
	BladeComponent = CreateDefaultSubobject<USkeletalMeshComponent>("BladeComponent");                                                      
	BladeComponent->SetupAttachment(BodyMesh);                                                                                              
                                                                                                                                            
	ChestAdditionComponent = CreateDefaultSubobject<USkeletalMeshComponent>("ChestAdditionComponent");                                      
	ChestAdditionComponent->SetupAttachment(BodyMesh);                                                                                      
                                                                                                                                            
	ChestComponent = CreateDefaultSubobject<USkeletalMeshComponent>("ChestComponent");                                                      
	ChestComponent->SetupAttachment(BodyMesh);                                                                                              
                                                                                                                                            
	GauntletComponent = CreateDefaultSubobject<USkeletalMeshComponent>("GauntletComponent");                                                
	GauntletComponent->SetupAttachment(BodyMesh);                                                                                           
                                                                                                                                            
	GemComponent = CreateDefaultSubobject<USkeletalMeshComponent>("GemComponent");                                                          
	GemComponent->SetupAttachment(BodyMesh);                                                                                                
                                                                                                                                            
	GloveComponent = CreateDefaultSubobject<USkeletalMeshComponent>("GloveComponent");                                                      
	GloveComponent->SetupAttachment(BodyMesh);                                                                                              
                                                                                                                                            
	HornComponent = CreateDefaultSubobject<USkeletalMeshComponent>("HornComponent");                                                        
	HornComponent->SetupAttachment(BodyMesh);                                                                                               
                                                                                                                                            
	KabutoComponent = CreateDefaultSubobject<USkeletalMeshComponent>("KabutoComponent");                                                    
	KabutoComponent->SetupAttachment(BodyMesh);                                                                                             
                                                                                                                                            
	NeckComponent = CreateDefaultSubobject<USkeletalMeshComponent>("NeckComponent");                                                        
	NeckComponent->SetupAttachment(BodyMesh);                                                                                               
                                                                                                                                            
	NecklaceComponent = CreateDefaultSubobject<USkeletalMeshComponent>("NecklaceComponent");                                                
	NecklaceComponent->SetupAttachment(BodyMesh);                                                                                           
                                                                                                                                            
	ShoulderAdditionComponent = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderAdditionComponent");                                
	ShoulderAdditionComponent->SetupAttachment(BodyMesh);                                                                                   
                                                                                                                                            
	ShoulderComponent = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderComponent");                                                
	ShoulderComponent->SetupAttachment(BodyMesh);                                                                                           
                                                                                                                                            
	TrouserComponent = CreateDefaultSubobject<USkeletalMeshComponent>("TrouserComponent");                                                  
	TrouserComponent->SetupAttachment(BodyMesh);                                                                                            
                                                                                                                                            
}                                                                                                                                           
                                                                                                                                            

Do you know if there’s a way to give them a custom order?
Thank you in advance!

It is painfully annoying when I have many components, do u have a good solution or workaround?

1 Like

Hi, I tried giving using the same name for components having different numbers, but it didn’t work, sometimes values are swapped (In an apparently random way, another user told me it could be caused by multithreading when creating the CDOs)

.h file
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component1;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component2;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component3;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component4;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component5;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component6;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component7;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component8;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component9;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component10;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component11;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component12;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component13;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
	USkeletalMeshComponent *Component14;
.cpp file
	Component1 = CreateDefaultSubobject<USkeletalMeshComponent>("AntennaeComponent");
	Component1->SetupAttachment(RootComponent);

	Component2 = CreateDefaultSubobject<USkeletalMeshComponent>("BladeComponent");
	Component2->SetupAttachment(RootComponent);

	Component3 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestAdditionComponent");
	Component3->SetupAttachment(RootComponent);

	Component4 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestComponent");
	Component4->SetupAttachment(RootComponent);

	Component5 = CreateDefaultSubobject<USkeletalMeshComponent>("GauntletComponent");
	Component5->SetupAttachment(RootComponent);

	Component6 = CreateDefaultSubobject<USkeletalMeshComponent>("GemComponent");
	Component6->SetupAttachment(RootComponent);

	Component7 = CreateDefaultSubobject<USkeletalMeshComponent>("GloveComponent");
	Component7->SetupAttachment(RootComponent);

	Component8 = CreateDefaultSubobject<USkeletalMeshComponent>("HornComponent");
	Component8->SetupAttachment(RootComponent);

	Component9 = CreateDefaultSubobject<USkeletalMeshComponent>("KabutoComponent");
	Component9->SetupAttachment(RootComponent);

	Component10 = CreateDefaultSubobject<USkeletalMeshComponent>("NeckComponent");
	Component10->SetupAttachment(RootComponent);

	Component11 = CreateDefaultSubobject<USkeletalMeshComponent>("NecklaceComponent");
	Component11->SetupAttachment(RootComponent);

	Component12 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderAdditionComponent");
	Component12->SetupAttachment(RootComponent);

	Component13 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderComponent");
	Component13->SetupAttachment(RootComponent);

	Component14 = CreateDefaultSubobject<USkeletalMeshComponent>("TrouserComponent");
	Component14->SetupAttachment(RootComponent);

The only workaround I found was creating all components then attaching them in a specific order, one by one, to another component.

By the way this is not a good solution because it’s not scalable and if you add component in BP they are added in a random point and in a random order.

My suggestion is to create an array of scene components pointers and add every component to it when you create it:

.h file
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
USceneComponent* NewRoot;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character Components")
TArray<USceneComponent*> OrderedComponents;
.cpp file
	NewRoot = CreateDefaultSubobject<USkeletalMeshComponent>("NewRoot");
	NewRoot->SetupAttachment(GetRootComponent());

	Component1 = CreateDefaultSubobject<USkeletalMeshComponent>("AntennaeComponent");
	OrderedComponents.Add(Component1);

	Component2 = CreateDefaultSubobject<USkeletalMeshComponent>("BladeComponent");
	OrderedComponents.Add(Component2);

	Component3 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestAdditionComponent");
	OrderedComponents.Add(Component3);

	Component4 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestComponent");
	OrderedComponents.Add(Component4);

	Component5 = CreateDefaultSubobject<USkeletalMeshComponent>("GauntletComponent");
	OrderedComponents.Add(Component5);

	Component6 = CreateDefaultSubobject<USkeletalMeshComponent>("GemComponent");
	OrderedComponents.Add(Component6);

	Component7 = CreateDefaultSubobject<USkeletalMeshComponent>("GloveComponent");
	OrderedComponents.Add(Component7);

	Component8 = CreateDefaultSubobject<USkeletalMeshComponent>("HornComponent");
	OrderedComponents.Add(Component8);

	Component9 = CreateDefaultSubobject<USkeletalMeshComponent>("KabutoComponent");
	OrderedComponents.Add(Component9);

	Component10 = CreateDefaultSubobject<USkeletalMeshComponent>("NeckComponent");
	OrderedComponents.Add(Component10);

	Component11 = CreateDefaultSubobject<USkeletalMeshComponent>("NecklaceComponent");
	OrderedComponents.Add(Component11);

	Component12 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderAdditionComponent");
	OrderedComponents.Add(Component12);

	Component13 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderComponent");
	OrderedComponents.Add(Component13);

	Component14 = CreateDefaultSubobject<USkeletalMeshComponent>("TrouserComponent");
	OrderedComponents.Add(Component14);

	// Do a for loop in OrderedComponents starting from the last value
	//for(int Index = OrderedComponents.Num()-1; Index >= 0; Index--)
	//{
	//	OrderedComponents[Index]->SetupAttachment(NewRoot);
	//}

	for(USceneComponent* Component : OrderedComponents)
	{
		Component->SetupAttachment(NewRoot);
	}

As you can see the components are now ordered, but from the last to the first, if you look inside the .cpp file, I also tried to attach them from the last to the first with a reverse foreach loop but the order remains the same (very strange)

The Order in which you declare the components in the .h file doesn’t matter, the order in which you add them to array also doesn’t matter, it looks like it only cares about the creation order, so…

This ■■■■■■■■ (Components created from last to first, and then added to the array in a random order):

	NewRoot = CreateDefaultSubobject<USkeletalMeshComponent>("NewRoot");
	NewRoot->SetupAttachment(GetRootComponent());

	Component14 = CreateDefaultSubobject<USkeletalMeshComponent>("TrouserComponent");
	Component13 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderComponent");
	Component12 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderAdditionComponent");
	Component11 = CreateDefaultSubobject<USkeletalMeshComponent>("NecklaceComponent");
	Component10 = CreateDefaultSubobject<USkeletalMeshComponent>("NeckComponent");
	Component9 = CreateDefaultSubobject<USkeletalMeshComponent>("KabutoComponent");
	Component8 = CreateDefaultSubobject<USkeletalMeshComponent>("HornComponent");
	Component7 = CreateDefaultSubobject<USkeletalMeshComponent>("GloveComponent");
	Component6 = CreateDefaultSubobject<USkeletalMeshComponent>("GemComponent");
	Component5 = CreateDefaultSubobject<USkeletalMeshComponent>("GauntletComponent");
	Component4 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestComponent");
	Component3 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestAdditionComponent");
	Component2 = CreateDefaultSubobject<USkeletalMeshComponent>("BladeComponent");
	Component1 = CreateDefaultSubobject<USkeletalMeshComponent>("AntennaeComponent");

	OrderedComponents.Add(Component6);
	OrderedComponents.Add(Component3);
	OrderedComponents.Add(Component7);
	OrderedComponents.Add(Component13);
	OrderedComponents.Add(Component12);
	OrderedComponents.Add(Component14);
	OrderedComponents.Add(Component10);
	OrderedComponents.Add(Component5);
	OrderedComponents.Add(Component1);
	OrderedComponents.Add(Component8);
	OrderedComponents.Add(Component2);
	OrderedComponents.Add(Component4);
	OrderedComponents.Add(Component9);
	OrderedComponents.Add(Component11);

	for(USceneComponent* Component : OrderedComponents)
	{
		Component->SetupAttachment(NewRoot);
	}

Returns this perfectly ordered list:

Now, if I create some components from BP, they are automatically added in the middle of the list and destroy the order of other components placed in C++ (PURE NONSENSE :exploding_head:):

You won’t be able to reorder them in the BP constructor because it’s not a real constructor, as you can see nothing happens:

The only “working” solution is creating all the components in C++ and avoid touching them in BPs as much as possible if you want to keep a decent order

Thanks for the detailed reply, my experience is

  1. even in C++, the order is not defined if you add components
  2. The drag drop for scene components doesn’t work for components with children. It just orders them in a random order when moving them around

Shorter version:

Just add the actor to the array directly when you create it (It will drastically reduce the number of lines and improve readability and scalability):

	NewRoot = CreateDefaultSubobject<USkeletalMeshComponent>("NewRoot");
	NewRoot->SetupAttachment(GetRootComponent());

	OrderedComponents.Add(Component14 = CreateDefaultSubobject<USkeletalMeshComponent>("TrouserComponent"));
	OrderedComponents.Add(Component13 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderComponent"));
	OrderedComponents.Add(Component12 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderAdditionComponent"));
	OrderedComponents.Add(Component11 = CreateDefaultSubobject<USkeletalMeshComponent>("NecklaceComponent"));
	OrderedComponents.Add(Component10 = CreateDefaultSubobject<USkeletalMeshComponent>("NeckComponent"));
	OrderedComponents.Add(Component9 = CreateDefaultSubobject<USkeletalMeshComponent>("KabutoComponent"));
	OrderedComponents.Add(Component8 = CreateDefaultSubobject<USkeletalMeshComponent>("HornComponent"));
	OrderedComponents.Add(Component7 = CreateDefaultSubobject<USkeletalMeshComponent>("GloveComponent"));
	OrderedComponents.Add(Component6 = CreateDefaultSubobject<USkeletalMeshComponent>("GemComponent"));
	OrderedComponents.Add(Component5 = CreateDefaultSubobject<USkeletalMeshComponent>("GauntletComponent"));
	OrderedComponents.Add(Component4 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestComponent"));
	OrderedComponents.Add(Component3 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestAdditionComponent"));
	OrderedComponents.Add(Component2 = CreateDefaultSubobject<USkeletalMeshComponent>("BladeComponent"));
	OrderedComponents.Add(Component1 = CreateDefaultSubobject<USkeletalMeshComponent>("AntennaeComponent"));

	for(USceneComponent* Component : OrderedComponents)
	{
		Component->SetupAttachment(NewRoot);
	}

The order of the components in the .h file doesn’t matter, just create them from the last to the first and then use SetupAttachment

That’s strange, I tried with different types of components and different names and it works:
image

Are you attaching them to a new component after you create them?

With children you have to repeat the same s**t, with a different array, and yes, the order in which you create them matters (If you create the children before the parent it will be moved to last, really don’t ask me why the f…):

	TArray<USceneComponent*> OrderedComponents;
	TArray<USceneComponent*> OrderedChildren;

	NewRoot = CreateDefaultSubobject<USkeletalMeshComponent>("NewRoot");
	NewRoot->SetupAttachment(GetRootComponent());
	OrderedComponents.Add(Component11 = CreateDefaultSubobject<USkeletalMeshComponent>("NecklaceComponent"));
	OrderedComponents.Add(Component10 = CreateDefaultSubobject<USkeletalMeshComponent>("NeckComponent"));
	OrderedComponents.Add(Component9 = CreateDefaultSubobject<USkeletalMeshComponent>("KabutoComponent"));
	OrderedComponents.Add(Component8 = CreateDefaultSubobject<USkeletalMeshComponent>("HornComponent"));
	OrderedComponents.Add(Component7 = CreateDefaultSubobject<USkeletalMeshComponent>("GloveComponent"));
	OrderedComponents.Add(Component6 = CreateDefaultSubobject<USkeletalMeshComponent>("GemComponent"));
	OrderedComponents.Add(Component5 = CreateDefaultSubobject<USkeletalMeshComponent>("GauntletComponent"));
	OrderedComponents.Add(Component4 = CreateDefaultSubobject<USkeletalMeshComponent>("ChestComponent"));
	OrderedComponents.Add(ComponentIII = CreateDefaultSubobject<USceneComponent>("ChestAdditionComponent"));
	OrderedComponents.Add(SecondComponent = CreateDefaultSubobject<UStaticMeshComponent>("BladeComponent"));
	OrderedComponents.Add(Component1 = CreateDefaultSubobject<USkeletalMeshComponent>("AntennaeComponent"));

	OrderedChildren.Add(Child3 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderAdditionComponent"));
	OrderedChildren.Add(Child2 = CreateDefaultSubobject<USkeletalMeshComponent>("ShoulderComponent"));
	OrderedChildren.Add(Child1 = CreateDefaultSubobject<USkeletalMeshComponent>("TrouserComponent"));

	for(USceneComponent* Component : OrderedChildren)
	{
		Component->SetupAttachment(SecondComponent);
	}

	for(USceneComponent* Component : OrderedComponents)
	{
		Component->SetupAttachment(NewRoot);
	}

I see. I was doing a bit differently. I was previously actor component, and the ordering didn’t work (in C++), I switched them to scene component. Then I was organizing it into scene nodes (with children). Moving them around screws up.

I was thinking of a editor tool to clone the components , remove , sort them by name and add them back.

If you manage to do it, I’d be very happy to use it! (even if I think that this is a huge engine issue and Epic should fix it…)

If you mean UChildActorComponent it works fine for me, I also tried with a UCameraComponent and the order seems to work, if you add stuff in BP everything will break:

Before adding components in BP:

After:

It’s simply ridiculous!

If you mean any subclass of UActorComponent, bad luck, since they can’t be attached to a parent and this topic it’s still unsolved despite it’s been created in 2016: Blueprint component reordering.
It looks like nobody cares about ordering components at all…

Are you sure C++ actorcomponents work? I tried before (as a test) insert new components in middle, the order is random.

You probably missed my answers because of the wall of text:

(I tried adding an UActorComponent to my previous code and everything gets messed up, no matter when I create the component)

oh wow, I didn’t even realize there is ChildActorComponent. I can’t seem to pick them as parent class from blueprint (that’s why I never knew about them). It seems to be a child of scenecomponent, so probably behaves like scene component.

1 Like

its a mess even in 5.2, there are a lot of features missing in in the BP editor, symbols for decals for example etc., its a very very simple editor

2 Likes

Just wanna bump, since it is still the same in 5.3 (likely also 5.4 even though I have not looked into it yet).

1 Like

Still the same in 5.4.
It’s ridiculous, computers allow to order things since 40 years, peoples complaint in unreal since years and still this simple things is completely ignored by devs.
It seem we are stuck with blueprint hell forever.

2 Likes

Why has this not been addressed? Even adding and renaming things as you go doesn’t keep any order - my "DropTarget1/2/3…"s are now spread throughout my DefaultSceneRoot like confetti…

2 Likes

Can an Epic Games Dev explain why this is, clearly, not a possibility at the moment?

I’m sure there is a reason, and I’d like to know why.

please find a solution, Epic. support