Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 Guennor · Aug 11, 2021 at 08:09 PM · spriteslicetextureimporter

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

I have an editor script that slices sprites automatically as they are imported into the project.

public void OnPostprocessTexture(Texture2D texture) { string spriteName = myScript.GetName() + "-"; int spriteSize = texture.width/8; int count = 8;

 List<SpriteMetaData> metas = new List<SpriteMetaData>();
 List<SpriteMetaData> finalMetas = new List<SpriteMetaData>();
 int i = -8;
 for (int y = count; y > 0; --y)
 {
     for (int x = 0; x < count; ++x)
     {
         SpriteMetaData meta = new SpriteMetaData();
         meta.rect = new Rect(x * spriteSize, (y * spriteSize) - spriteSize, spriteSize, spriteSize);
         meta.name = "a";
         i++;

         metas.Add(meta);
     }
 }
   
 TextureImporter textureImporter = (TextureImporter)assetImporter;
 textureImporter.spritesheet = finalMetas.ToArray();

}

This works perfectly, as can be seen here.

alt text

The problem is, even though the sprite is sliced, it does not show its children sliced sprites in the project folder. There is no arrow to click and expand the list of sliced sprites, even though it is clearly set to multiple and it is clearly sliced as can be seen on the preview, on the image above.

Strangely enough, when I duplicate (shift + D) the sprite, the duplicate will "update", realizing it has multiple children, but the original will not. alt text

I have already tried Assetdatabase.Refresh. I tried textureImporter.SaveAndReimport() to no avail. What is even stranger is that if I generate a sprite, close unity and open it again, the sprite will still not show its children. There is probably a very specific method somewhere I need to call to force update this sprite, but I don't know which.

Thanks in advance to whoever knows the answer to this niche problem.

spriteslice-01.png (55.9 kB)
spriteslice-03.png (9.7 kB)
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
0

Answer by Guennor · Aug 13, 2021 at 06:21 PM

I found a workaround, thought it is not ideal. I noticed that if I manually renamed the file with F2, when I renamed it, the children sliced sprites would appear. So what I do is I rename the texture programmatically after I generate it using

 AssetDatabase.RenameAsset(myPathString, "My_new_texture"); 

Just a thing though, if you rename it to the same name it already had, nothing happens so you need to rename it to something else.

Comment
Add comment · 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

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

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

Could use some help with slicing a sprite sheet 0 Answers

Auto Tiling Issue 1 Answer

TextureImporterType.Sprite does not work 0 Answers

Slice sprites in a build 0 Answers

How to rename individual sprite slice without creating new fileID in meta file using code? 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