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 <em>= AssetPreview.GetAssetPreview(_sprites*);*</em>

* }*
* }*
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 :frowning:
Here is a picture of my selection grid of the preview images:
[21062-screen+shot+2014-01-23+at+6.43.27+pm.png|21062]_
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…
_
[21064-screen+shot+2014-01-23+at+8.11.51+pm.png*|21064]*
_*
_*

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 :slight_smile: