Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • 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, while 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 this, 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 = slice$$anonymous$$etaData[].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.

Follow this Question

Answers Answers and Comments

41 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 avatar image

Related Questions

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

Sprite generated and sliced programatically does not show its sliced children sprites on the project folder 1 Answer

Unity 5.0 Sprite slicing messes up with much vertices. 0 Answers

Unity 2D Sprite Blurred 2 Answers

Cant save anim from spritesheet 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