Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created July 23, 2021 17:37
Show Gist options
  • Save kurtdekker/e626e1f06fd5133b4d6951e6e1f3d87b to your computer and use it in GitHub Desktop.
Save kurtdekker/e626e1f06fd5133b4d6951e6e1f3d87b to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
// @kurtdekker
// Make sure this is in an Editor folder!
public static class DuplicationHelpers
{
// duplicates the current object and puts it back right after the original.
[MenuItem( "Assets/Dupe Here FFS")]
static void DupeSelectedItemHereFFS()
{
foreach( var item in Selection.gameObjects)
{
int siblingOrder = item.transform.GetSiblingIndex();
var originalName = item.name;
var copy = GameObject.Instantiate<GameObject>( item, item.transform.parent);
// TODO: do anything clever you want with the name, such as suffix it with +1, etc.
copy.name = originalName;
copy.transform.SetSiblingIndex( siblingOrder + 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment