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
1
Question by Jeff-Kesselman · Jan 23, 2014 at 11:42 PM · 2dspritepreviewload asset

Why do only some of my sprites generate preview images?

I'm trying to load all the sub-sprites in a 2D gridded sprite and make them available o na menu. Since there is no way to convert a sprite directly to a texture2D that I could see, I thought I'd try AssetPreview.GetAssetPreview(..)

Problem is that it's half working and half not. Some of my sprites seem to get proper preview images while others seem to be blank. I have checked and all sprites DO show up when used on screen.

This is my code

 void Update () {
         if (clearPreviews){
         LoadSpritePreviews();
         clearPreviews=false;
     }
 
         if (tilesetSprite != _oldTilesetprite){
             _oldTilesetprite = tilesetSprite;
             // load tiles and tielset image
             string path = AssetDatabase.GetAssetPath(tilesetSprite);
             Object[] rawAssets = AssetDatabase.LoadAllAssetsAtPath(path);
             _tilesetImage = (Texture2D) rawAssets[0];
             _sprites = new Sprite[rawAssets.Length-1];
             System.Array.Copy(rawAssets,1,_sprites,0,_sprites.Length);
             LoadSpritePreviews ();
         }
     }
 
     private void LoadSpritePreviews(){
         // laod previews
         _spritePreviews = new Texture2D[_sprites.Length];
         for(int i=0;i<_sprites.Length;i++){
             _spritePreviews[i] = AssetPreview.GetAssetPreview(_sprites[i]);
         }
     }

I thought maybe it was a timing thing, that the asset load was happening asynchronously, so I added a check box i could check to force it to regenerate the previews, but I still get the same results :(

Here is a picture of my selection grid of the preview images:

alt text

This is what the sprite importer looks like in the project window, so apparently the editor is successfully creating previews for all the sprite images..

alt text

screen shot 2014-01-23 at 8.11.51 pm.png (325.8 kB)
screen shot 2014-01-23 at 6.43.27 pm.png (116.9 kB)
Comment
Add comment · Show 6
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 Jeff-Kesselman · Jan 24, 2014 at 02:00 AM 0
Share

On further analysis, it looks like later calls are returning null.

I am wondering if this is a memory usage issue? Are there ways to see/tune the memory used in the editor?

avatar image Jeff-Kesselman · Jan 24, 2014 at 02:15 AM 0
Share

Alright this is really starting to look like a memory issue. I assume its because I am loading 255 sprites.

Is there another way to get an image of them short of loading them into memory and using AssetPreview?

avatar image Eric5h5 · Jan 24, 2014 at 02:37 AM 0
Share

I seriously doubt that's a memory issue unless the sprites are massive in size. 255 is not very many.

avatar image Jeff-Kesselman · Jan 24, 2014 at 03:00 AM 0
Share

Well, I'm not sure what else could be causing it then. Its either memory or ti$$anonymous$$g because its acting like a hiesenbug-- changing the number of previews i get changes which ones do and don't show up.

I've decided to try to use the cached icons ins$$anonymous$$d... but I can't figure out how I specify the path of a sub asset to GetCachedIcon(). Guess Ill post a new question.

avatar image HappyMoo · Jan 24, 2014 at 10:13 AM 0
Share

You're creating and trashing a full array of textures every frame? That can't be good...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by RDeluxe · Feb 14, 2016 at 05:54 PM

I know it's an old question, but I found myself with the same problem.

The trick is to change AssetPreview.SetPreviewTextureCacheSize ! Set the this cache size to your array lenght (_sprites.Length in your case), and it should work :)

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

21 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

Related Questions

Cannot see full view of Screen in Unity preview 2 Answers

Prevent 2D mask to impact other gameobjects ? 3 Answers

Finding the centre of two touches 2 Answers

Should sprites in the same layer but different order incur additional draw calls? 0 Answers

How to make not smooth animation? 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