Changing the order of Components

In some cases the order affects the end result. For instance when stacking a blur on a noise, or the other way around. Does Unity have an ability to change the order? I've been looking around in the docs and Google, but couldn't find it. I was even a bit surprised that I couldn't find anything :)

Since Unity 4, you can move components up and down by right-clicking on them (or clicking on the small gear in the right corner) and selecting the appropriate option in the context menu that is popping up.

New plugin on the Asset Store, doing just what you need with a drag and drop interface:

Posting this as an answer (instead of as a reply to a somewhat different answer), along with an example for an editor script that can be used to re-order components by type.

There is an option to sort components programmatically (only in the editor), though it is not documented:

UnityEditorInternal.ComponentUtility.MoveComponentDown(Component);
UnityEditorInternal.ComponentUtility.MoveComponentUp(Component);

There are also other functions in there, for copying and pasting components.

Here is an example for a useful script which provides a menu item (shortcut alt+ctrl+a) that sorts the components in the currently selected game-object according to type:

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEngine.Networking;

public class ComponentsSorter : ScriptableObject
{
	private class ComponentComparer : IComparer<Component>
	{
		private static readonly Type[] TypesOrder =
		{
			// Transform is always first (though that doesn't really matter, as we can't 
			// move it anyway).
			typeof (Transform),

			// Add your types here in the order you want them to be in the inspector.
			typeof (MeshFilter),
			typeof (MeshRenderer),
			typeof (SpriteRenderer),
			typeof (Rigidbody2D),
			typeof (Collider2D),
		};

		private Int32 GetIndex(Component Component)
		{
			var Type = Component.GetType();

			Type BestMatch = typeof(UnityEngine.Object);
			var BestIndex = Int32.MaxValue;
			for (int Index = 0; Index < TypesOrder.Length; Index++)
			{
				// If we found the exact type in the list, then this is the right index.
				var TypeOrder = TypesOrder[Index];
				if (Type == TypeOrder)
					return Index;

				// If we found a parent, then we switch to its place if it is more
				// "recent" (in the inheritance tree) than previously found parents.
				if (Type.IsSubclassOf(TypeOrder))
				{
					if (TypeOrder.IsSubclassOf(BestMatch))
					{
						BestMatch = TypeOrder;
						BestIndex = Index;
					}
				}
			}

			return BestIndex;
		}

		public int Compare(Component First, Component Second)
		{
			return Comparer<Int32>.Default.Compare(GetIndex(First), GetIndex(Second));
		}
	}

	[MenuItem("Edit/Sort Components %&a")]
	private static void SortComponents()
	{
		var GameObject = Selection.activeGameObject;
		var SortedComponents = GameObject.GetComponents<Component>()
			.Where(Component => Component.GetType() != typeof(Transform)).ToList();
		SortedComponents.Sort(new ComponentComparer());

		for (var Index = 0; Index < SortedComponents.Count; Index++)
		{
			var SortedComponent = SortedComponents[Index];
			var Components = GameObject.GetComponents<Component>()
				.Where(Component => Component.GetType() != typeof (Transform)).ToList();
			var CurrentIndex = Components.IndexOf(SortedComponent);
			if (CurrentIndex < Index)
			{
				for (var MoveIndex = CurrentIndex; MoveIndex < Index; MoveIndex++)
					UnityEditorInternal.ComponentUtility.MoveComponentDown(SortedComponent);
			}
			else
			{
				for (var MoveIndex = CurrentIndex; MoveIndex > Index; MoveIndex--)
					UnityEditorInternal.ComponentUtility.MoveComponentUp(SortedComponent);
			}
		}
	}
}

The code is a little ugly, but it works. Just add it under an ‘Editor’ folder and it should appear under the ‘Edit’ menu.

Now, you can simply click & drag a component to change its order…

Yes you can! At least in Unity 5. Click a gear icon next to component’s name

Hi! I just published this little utility on the Asset Store to make the reordering of components less painfully.
Hope you like it :wink:

Actually You can do this now. I’m not sure about previous Unity versions but in Unity 5.2 you can right click the component and select “Move Up” or “Move Down” to move the component wherever you need it.

This plugin does exactly that in the most possible intuitive way

http://forum.unity3d.com/threads/released-component-tool-panel-compact-seamlessly-intergated-component-utils.404588/

Check the new version of XT Reorder available now on the Unity Asset Store. It supports direct drag and drop of the Components in the Inspector and shortcuts for expand/collapse all:

https://www.assetstore.unity3d.com/en/#!/content/39677