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
3
Question by $$anonymous$$ · Jul 01, 2014 at 11:47 AM · c#texture2dprefabspreview

How to generate a Texture2D of the thumbnail of a prefab?

Hi, I'm quite new to Unity3D and I use C#. I'm making a inventory system. I want to know how can I use the thumbnail of a prefab and convert it into a Texture2D and attach it to each item in the inventory. I want to know if that is possible with scripts or plugins, please notify me. I dont mind if its a at run time script or not. Thank for reading.

screenshot.png (285.5 kB)
Comment
Add comment · Show 1
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 Klarax · Jul 01, 2014 at 03:57 PM 0
Share

i don't personally know of a way to do this on the fly, or if it is possible... i always created an icon in photo editing software.

1 Reply

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

Answer by roojerry · Jul 01, 2014 at 04:05 PM

Within the editor, you could write a script using AssetPreview.GetAssetPreview to get the preview Texture2D's from your assets, then encode those textures into PNGs and save them out to be used as assets in your game.

Other than that, I don't believe there is any quick or efficient way of doing this at runtime.

Comment
Add comment · Show 4 · 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 observerOne · Nov 04, 2014 at 06:09 PM 0
Share

I have been trying to figure this out for the past 2 days, I was trying to get AssetPreview then Create.Asset and couldn't really figure out why I kept co$$anonymous$$g up with a blank item, unless I had it create a raw image. You sir have saved my day!

avatar image DiebeImDunkeln · Feb 01, 2015 at 09:51 AM 0
Share

I have the same problem here. I try to create a list of Texture2D with AssetPreview.GetAssetPreview, but some work and some give NULL in return. Seems that the previews are not ready at the moment when I try to use them.

avatar image nixac · Feb 15, 2017 at 06:29 AM 0
Share

I tried this approach. I was able to get the texture2d using GetAssetPreview as well, but the problem is that after that I am not able to save it as a png file. I am getting the following error.

UnityException: Texture 'Prefab$$anonymous$$odel Icon' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings. UnityEngine.Texture2D.EncodeToJPG () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/TextureBindings.gen.cs:371) AssetPackageCreator.export () (at Assets/Editor/AssetPackageCreator.cs:60)

After this I tried to make it readable as suggested in this SO answer How to make asset readable . This failed as well.

Is there any workaround for saving the thumbnail or preview to disk ?

avatar image Erathor nixac · Mar 17, 2017 at 12:08 PM 0
Share

@nixac I don´t know if you create a new png file but if you want to read/write into an existing one you will have to do the following. 1. Go under your image settings in the unity inspector 2. Change the texture type to advanced 3. Check "Read/Write Enabled" to true 4. Now you should be able to read/write into the file

I hope I could help :)

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

GetAssetPreview Transparent background with higher resolution 0 Answers

Problem when loading texture from folder 0 Answers

Checking for null against Texture2D 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