• 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 /
  • Help Room /
avatar image
0
Question by artwen · Nov 19, 2015 at 02:22 PM · spritespritesheetmetatextureimportermetafiles

How to rename individual sprite slice without creating new fileID in meta file using code?

Hi guys, after sliced a sprite sheet, I noticed that if I rename each individual sprite slice manually in Unity, the 'fileIDToRecycleName' session of the meta file for that sprite will stay cool (only name changes, w$$anonymous$$le the fileID remains the same). However, if I do it using code, the 'fileIDToRecycleName' session will expand, reassigning the new name to a new fileID. See below:

 fileIDToRecycleName:
             21300000: name_0
             21300002: name_1
             21300004: name_2
 //if manually rename in unity the above will change to:
 fileIDToRecycleName:
             21300000: newname_0
             21300002: newname_1
             21300004: newname_2
 //if rename in code then:
 fileIDToRecycleName:
             21300000: name_0
             21300002: name_1
             21300004: name_2
             21300006: newname_0
             21300008: newname_1
             21300010: newname_2

My code is like t$$anonymous$$s, similar to line 215-267 of https://github.com/eppz/Unity.Library.eppz_kit/blob/master/Editor/EPPZEditor_SliceRenamer.cs

         ...
         // Locate asset, get meta.
         path = AssetDatabase.GetAssetPath(texture);
         textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
         SpriteMetaData[] sliceMetaData = textureImporter.spritesheet;
 
         // Naming loop.
          for (i...)
         {
             string eachName = ...;
             ...
             sliceMetaData[i].name = eachName; 
         }
 
         // Save settings.
         textureImporter.spritesheet = sliceMetaData;
         EditorUtility.SetDirty(textureImporter);
         textureImporter.SaveAndReimport();
 
         // Reimport/refresh asset.
         AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
Comment
Add comment · Show 3
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 artwen · Nov 19, 2015 at 02:27 PM 0
Share

I try to change line 16 to something like:

         textureImporter.spritesheet[].name = sliceMetaData[].name;

What is the right way of doing this? And will it work?

avatar image artwen · Nov 20, 2015 at 03:16 AM 0
Share

Or, is it possible to use Packer.GetAtlasDataForSprite and atlasName variable to rename the slices without creating new fileID?

avatar image TDMJ · Mar 14, 2018 at 06:32 AM 0
Share

this can simply change the sliced sprite, but the resources which use the sliced sprite with old name will not change at same time.

Like a prefab A, use sliced sprite named [a_01], but you change it into [a_001],it's will not show the right sliced sprite.

I wonder if there's API work like Sprite Editor, change sliced sprite's name, and click Apply button, and deal with dependencies with Unity itself.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

40 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 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

Unity is rescaling my texture when I try and import it? 0 Answers

Sprite editor problems due to sprite pixel size? 0 Answers

Animate a quad using a sprite sheet? 0 Answers

Is there a way to transpose a sprite sheet or have a sheet be spliced top to bottom instead of left to right? 0 Answers

So when i use the sprite editor, i can't get the sprite editor to import the separate sprites into my project. 0 Answers


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