Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by rubeng · Nov 27, 2016 at 08:18 AM · editorcustom editorpreview

How can I create a custom AssetPreview for a prefab

The core of the question is, how can I customize the Texture that is returned by the AssetPreview.GetAssetPreview method?

A detailed explanation of my use case follows:

I have some prefabs that contain a components that creates a mesh from sprites info and some data. (its a tool similar to spine, spriter, etc)

Right now I am making a custom level editor, and in the palette tool I am showing prefabs with the AssetPreview, so using AssetPreview.GetAssetPreview (item.gameObject) I am able to show a nice icon for the prefabs.

This works perfectly for prefabs that have just regular sprites in them, like, trees, rocks, houses, grass decals, etc, but when I want to add a prefab that is a character using our custom mesh based component the preview is not generated. Even in the project view when using the resize slider, the sprite based prefabs show nice icons, but the character prefabs show just the default prefab icon.

I tried using the CustomPreview attribute and ObjectPreview class to generate a preview using OnPreviewGUI and OnInteractivePreviewGUI but even though they work fine in the preview view of the inspector, they fail to work on the project view, or the AssetPreview.GetAssetPreview method call.

Thanks for any information

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 rubeng · Dec 05, 2016 at 08:37 PM 0
Share

I added a sample project to show the issue and the current solutions I am trying https://github.com/rgarat/AssetPreviewTest/

1 Reply

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

Answer by Adam-Mechtley · Dec 05, 2016 at 10:45 AM

Hi @rubeng! So this is not documented very well, but AssetPreview.GetAssetPreview () is actually looking for your definition of Editor.RenderStaticPreview () on the custom editor class defined for the target type in question.

Comment
Add comment · Show 15 · 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 rubeng · Dec 05, 2016 at 08:38 PM 0
Share

Thanks for your help, I tried your solution but I couldn't make it work, the method never gets called, at least how I tried it. I added a test project https://github.com/rgarat/AssetPreviewTest/ so you can see if what I am doing is right, or I am making some obvious mistake.

avatar image Adam-Mechtley rubeng · Dec 06, 2016 at 07:53 AM 0
Share

One possibility: The code path here prefers to take a cached result, and will exit early if the target object is not dirty. I didn't dig into it in too much depth but I think the problem is it never generates an initial cached result the first time you create an object.

TLDR: For your object with AnotherCustomObjectComponent added to it, try assigning something to one of its serialized fields (e.g., sprite) and see if it then generates the preview texture. If so, it would be terrific if you could also file a bug report with the example scripts and steps to reproduce :)

avatar image rubeng Adam-Mechtley · Dec 06, 2016 at 01:47 PM 0
Share

I added an integer field to the CustomObjectComponent, and to AnotherCustomObjectComponent, changed the values, updated the prefabs, but it was still not being generated.

Also the palette window has buttons to set the AssetPreview.SetPreviewTextureCacheSize to 1, and to 1000 so you can also try to clear the cache that way (not sure if that really clears it or not)

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

layout serializable objects in unity 1 Answer

Change angle of camera in prefab preview 1 Answer

Drag from custom editor ObjectField 0 Answers

The ‘ContextClick’ event of the ‘TreeView’ class does not fire from a custom inspector; but if you do it from an editor window it fires. 0 Answers

Cannot close Preview Scene 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