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
4
Question by Mogrinnar · Apr 27, 2015 at 01:58 PM · spriteassetbundletexture2dbundle

Sprite in Asset Bundles returned a Texture2D

Using the Bundle Manager I bundled sprites (images with sprite as their texture type). When I load the sprites at run time and I inspect (by loading all the objects in a Object array) the assets in my asset bundle, all my images are there but in a Texture2D format. I know how to create a sprite from a texture2d, but I wish the asset bundle simply gave me back sprites like I put in initially.

Is this working as intended or am I doing something wrong ?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bystander333 · Jun 28, 2018 at 02:36 PM

Waking this up with an actual answer (and Ignoring the slightly patronising one above.) I had the same issue, the solution is to use LoadAssetWithSubAssets or the async version. Same applies when using Resources - the method there is called LoadAllAssetsAtPath. Sprites are considered sub assets of the main asset (png, jpg etc), Unity encodes the details in the meta file - it does this for all assets that arrive in native format. Note, to be clear AssetBundle.LoadAllAssets() is different and probably not what you want, that loads all assets in the bundle into memory. LoadAssetWithSubAssets just loads the single asset you've requested (and any embedded sub assets).

To extract the sprite from the returned array use a helper function, e.g ...

     public static T GetSubAsset<T>(UnityEngine.Object[] allAssets) where T : class
     {
         for (int i=0;i<allAssets.Length;i++)
         {
             if (allAssets[i].GetType() == typeof(T))
             {
                 return allAssets[i] as T;
             }
         }
         return null;
     }
 
     public static T[] GetSubAssets<T>(UnityEngine.Object[] allAssets) where T : class
     {
         List<T> ret = new List<T>();
         for (int i = 0; i < allAssets.Length; i++)
         {
             if (allAssets[i].GetType() == typeof(T))
             {
                 ret.Add(allAssets[i] as T);
             }
         }
         return ret.ToArray();
     }

and call it like

 Sprite mySprite = GetSubAsset<Sprite>(subAssetArray);

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

Answer by wildtapirapps · Jul 23, 2016 at 07:44 PM

@Mogrinnar I am seeing the same with Unity 5.3.5: I have put sprites (made of jpg files) into AssetBundle. When I inspect it I can see for each sprite corresponding Texture2D type, for example:

loaded asset cat of type UnityEngine.Texture2D

loaded asset cat of type UnityEngine.Sprite

I check this with following code:

     foreach (Object asset in assets)
     {
         Debug.Log("loaded asset " + asset.name + " of type " + asset.GetType());
     }
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
avatar image
0

Answer by FireBoltStudios · Sep 11, 2017 at 11:01 AM

This is because a 'Sprite' is essentially just bunch of settings to tell Unity how to handle them. If you are able to modify the 'Sprite' to produce sprite sheets and supply borders there must be a source texture aswell, just like materials. For the way sprites are used in unity it would be near impossible to create one file for this without sacrificing functionality. If you think about how splitting a sprite works into multiple elements it would be counter-intuative to take one texture and split it up into how many textures you wanted in the sheet, so unity stores that one texture2d and splits it up at for you using your defined 'Sprite' parameters. This is how Sprites should work!

It's pretty easy to overlook something like this when nearly all other resources are dealt with on a 'what you see is what you get' basis.

Sprite(API) - https://docs.unity3d.com/ScriptReference/Sprite.html

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

23 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

Related Questions

Load Unity 4.3 Sprites with AssetBundles 5 Answers

Multiple draw calls from a single Sprite atlas when loading from Asset bundle 0 Answers

How do I fill a Texture2D with pixels and display a sprite with that texture using script? 1 Answer

Unity UpdateExternalTexture from MovieTexture windows crash 0 Answers

Resize a sprite by giving it more transparent pixels 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