- Home /
Unity2D Sprite editor multiple pivot point edit
Hey guys,
I wonder if there is a way in the sprite editor for a sprite that is set to multiple to set them all to a certain position without manually selecting them one by one ? I have like 50x sprites so it would be really convinient just to multi edit the pivot point. Any ideas ?
Thanks a lot for your time :)
Claude
Answer by VotaVader · Nov 25, 2014 at 03:51 PM
I've been using the following script for the editor which I found searching for the same thing in forums. It was written by David Robins (here's a video of how to use it, and where he posted the code on Reddit. You put it in a directory named "Editor" within your project structure, and it will be loaded to the top menu of the Unity Editor when you restart it. It has been very useful for spritesheets. I'm still trying to find a solution that works for a group of individual sprites. Might try to modify this script to do it. Here's the script within a class.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class MenuItems : MonoBehaviour {
[MenuItem("Sprites/Set Pivot(s)")]
static void SetPivots()
{
Object[] textures = GetSelectedTextures();
Selection.objects = new Object[0];
foreach (Texture2D texture in textures)
{
string path = AssetDatabase.GetAssetPath(texture);
TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;
ti.isReadable = true;
List<SpriteMetaData> newData = new List<SpriteMetaData>();
for (int i = 0; i < ti.spritesheet.Length; i++)
{
SpriteMetaData d = ti.spritesheet[i];
d.alignment = 9;
d.pivot = ti.spritesheet[0].pivot;
newData.Add(d);
}
ti.spritesheet = newData.ToArray();
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
}
}
static Object[] GetSelectedTextures()
{
return Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
}
}
EDIT: Actually for independent sprites, you can just select them all, and change their pivot at the same time in the inspector.
I can't seem to get the above code snippet to work, even with modifications to the code. It just sets all the pivots to (0, 0).
Debug.Logs don't show any problems????
Using 2017.4
Did you watch the vid? You set the wanted position for the pivot in the first frame of the sprite sheet, apply then you open Sprite->Set Pivot(s) in the editor's top left menu. Worked fine for me in Unity 2018.2.7f1
This doesn't work for 2018.3
To make it work change code to this:
ti.isReadable = false; // this 2 lines you need to add
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
ti.isReadable = true; // this line is present in original script
Your answer
![](https://koobas.hobune.stream/wayback/20220613155505im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Texture Import Settings problem! 1 Answer
2d sprite not showing in sprite editor 0 Answers
Unity2d : Spawning in Prefabs 1 Answer
How to slice sprite for GUI 2 Answers
Why does Sprite Creator make sprites without alpha channel? 1 Answer