Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Siflou · Jul 31, 2014 at 06:00 PM · pivotsprite editormultiple textures

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
8

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bamboy · Aug 09, 2018 at 09:26 PM 0
Share

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

avatar image StellarVeil Bamboy · Sep 26, 2018 at 01:27 PM 0
Share

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

avatar image StellarVeil · Sep 26, 2018 at 01:25 PM 0
Share

Thank you !

avatar image MUGIK · Dec 15, 2018 at 10:45 AM 3
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges