Skip to content

Instantly share code, notes, and snippets.

@SiarheiPilat
Created October 30, 2020 18:25
Show Gist options
  • Save SiarheiPilat/4ed2c47a8d0882f266d676afd4b4fa48 to your computer and use it in GitHub Desktop.
Save SiarheiPilat/4ed2c47a8d0882f266d676afd4b4fa48 to your computer and use it in GitHub Desktop.
Move a prefab instance to the bottom of the hierarchy whenever you drag and drop it to the scene.
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public static class NewObjectBottomOfHierarchy
{
static NewObjectBottomOfHierarchy()
{
SceneView.duringSceneGui += PlaceDroppedObjectToTheBottom;
}
static void PlaceDroppedObjectToTheBottom(SceneView sceneView)
{
if(Event.current.type == EventType.DragExited)
{
if(Selection.gameObjects.Length > 0)
{
// this checks out because it's only possible to drag and drop a single prefab to the scene at a time!
Selection.gameObjects[0].transform.SetAsLastSibling();
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment