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 ks13 · Dec 22, 2011 at 03:43 PM · assetbundletexture2dloadcast

AssetBundle.Load() to Texture2D

Hello, these assetbundles are really hard to understand how to use. Here's my current problem :
I got an asset bundle, i load an object, it's a texture 2D, and i cast it into Texture2D, but i get the folloxing error :

 Instantiating a non-readable 'de_1__main' texture is not allowed! Please mark the texture readable in the inspector or don't instantiate it.
 UnityEngine.Object:Instantiate(Object)
 LoadGallery:Update() (at Assets/Script/LoadGallery.cs:57)

This is the code calling it :

 Object obj;
             for (int i = 0; i < galleryObjects.Length; i++)
             {
                 obj = tmp.assetBundle.Load(pars.Country.ToLower() + "_" + (i + 1).ToString() + "__main");
                 galleryObjects[i].renderer.material.mainTexture = (Texture2D)Instantiate(obj);
                 galleryObjects[i].transform.Rotate(new Vector3(0, 0, 45));
             }

Have i misunderstood the Load() part of the assetbundles? Because i don't see other ways to cast an Object into a Texture2D.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by cregox · Dec 22, 2011 at 05:00 PM

I'm just guessing here, but maybe you want to do this instead (as advised by the error):

             galleryObjects[i].renderer.material.mainTexture = (Texture2D)obj;
Comment
Add comment · Show 2 · 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 ks13 · Dec 23, 2011 at 08:20 AM 1
Share

Hi, thank you for the answer, i already tried it, but i still got an error, which is found also with the code above :

 InvalidCastException: Cannot cast from source type to destination type.

That's why i thought what i did was wrong. The error occurs on the last image, image 8. "i" goes from 0 to 7, and images go from 1 to 8, so i shouldn't get an error with (i + 1). But somehow the last image seems to be the problem here.

Edit : After checking the images folders, i found out the error comes from the fact that the 8th image is in fact a video. So, i suppose i'll go try to find how to distinguish images from videos in assetbundles. Anyway, validating this answer.

avatar image cregox · Dec 23, 2011 at 11:09 AM 0
Share

Thanks for the feedback! And yeah, sometimes we just need a little shaking. :)

avatar image
1

Answer by flamy · Dec 23, 2011 at 08:53 AM

did you try

  galleryObjects[i].renderer.material.mainTexture = obj as Texture2D;


this should work!

Comment
Add comment · Show 1 · 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 ks13 · Dec 23, 2011 at 09:29 AM 0
Share

Actually, the problem is solved, but thank you for your concern nonetheless.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

the texture appear rubbish 1 Answer

How to, tell apart, Instance or Instantiated GameObject vs Loaded GameObject. 0 Answers

Getting variables after Resources.LoadAll 1 Answer

Load Unity 4.3 Sprites with AssetBundles 5 Answers

Getting the assets inside a bundle from unity 5 vs Unity 4 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