Runtime Preview (Thumbnail) Generator (Open Source)

Hello there,

I’ve just posted a script that lets you generate thumbnails for your GameObject’s and/or materials during gameplay and wanted to share it here, as well. The generated thumbnail is in Texture2D format and supports transparent background.

Asset Store: Runtime Preview Generator | Camera | Unity Asset Store
Also available at: GitHub - yasirkula/UnityRuntimePreviewGenerator: Generate preview textures (thumbnails) for your GameObject's or materials on the fly in Unity
Discord: yasirkula Unity Assets
GitHub Sponsors :coffee:

Should work on pretty much any platform that Unity supports.

3253861--984891--example1.png 3253861--984894--example2.png

FAQ

  • Rendered thumbnail is empty, why?

If shouldIgnoreParticleSystems parameter is set to false, child particle systems of the model may force the camera to zoom out a lot. Or, on SRPs, your Forward Renderer asset’s Opaque Layer Mask and/or Transparent Layer Mask might be excluding layer 22 (preview objects are temporarily assigned to this layer).

  • Rendered thumbnail doesn’t look correct, why?

If there are lighting issues and you’re generating thumbnails in Awake, try Start instead. Otherwise, try disabling post-processing effects and see if it makes any difference. If it does, then you should temporarily disable post-processing while capturing thumbnails.

Enjoy!

10 Likes

Now available on Asset Store!

This is perfect ! You saved me a big headache. This is exactly what I was searching for my inventory system.

If you are interested I would like to offer you a special account into my video game. You can find my game at www.citywars.ca. We are still far away from having a playable game but piece by piece we get further from a prototype. Your system is now part of our inventory system. :smile:

1 Like

It’s nice to hear :slight_smile: Thank you for your offer. I don’t have free time for games nowadays but thanks again for your kindness, I appreciate it.

Yeah i understand. Well Thanks again. If you need anything lets us know !

Also if you change your mind latter you’re still welcome :stuck_out_tongue_winking_eye:
Have a nice day !

nice

Hello! First of all, thank you so much for sharing this asset, it’s wonderful and exactly what I needed.

I am having an issue however - has anybody figured the issue with this asset and Unity 2018? After upgrading, I recall seeing an error or warning about it, and since seeing that it’s stopped working - annoyingly, there has been no error/warning since then, (I really wish I addressed it immediately - my next step is to make a new project and import to see if I can catch the error a second time) so I’m having trouble troubleshooting the issue.

I tried finding an upgrade guide for 2018 with changes/deprecation but couldn’t - if anyone could help I’d be very thankful! And I’ll post here if I find the solution myself of course.

I was able to test the following code with success on a new scene with no post-processing applied on Unity 2018.1.3f1:

public RawImage img;
public Transform obj;
private void Start()
{
    img.texture = RuntimePreviewGenerator.GenerateModelPreview( obj );
}

There were no error or warning messages for me while importing the plugin.

1 Like

Thanks for the help. I found that it actually no longer occurs on 2018.2.0f1. We’ve moved builds a few times in the last few weeks, so it must have been some temporary issue that resolved itself - works just fine after testing again (should’ve done that before posting. My apologies!)

1 Like

Any idea about soft shadows but transparent backgrounds? My best solution so far is just having a fake shadow, a sprite, that is resized to the bounding box of the object you’re rendering, and repositioned to right below the bounding box. You can probably do it with ‘real’ shadows if you use some special shader on a plane below the object (?)

Yes you could use such a special shader ( this could be a good starting point ). However, as an object’s shadow may overflow its bounding box, parts of the shadow may not be visible in the generated thumbnail.

Yeah, depends on which direction you cast the shadow. I think a way to go around that issue would be to feather the thumbnail near the edges :smile:

Hi there, I just had a question regarding this thumbnail generator. Right now I have a video player, and I save the texture of the video player to a RawImage. I want to generate a thumbnail based on the texture of the RawImage, but every time I try calling RuntimePreviewGenerator.GenerateModelPreview I get a null object.

image.texture = videoPlayer.texture;
thumbnail = RuntimePreviewGenerator.GenerateModelPreview(image.transform, 64, 64, true);

Am I calling runtime preview generator right or am I missing something?

RuntimePreviewGenerator can only work on objects with Renderer components. For a thumbnail of an existing texture, you may want to use the TextureOps.Scale function here: GitHub - yasirkula/UnityTextureOps: A basic image processing plugin for Unity

Hello,

thanks a lot for this asset :slight_smile:

Is there a way to get the grey background completly transparent (Alpha)?

Thanks!

RuntimePreviewGenerator.TransparentBackground = true; should do it.

1 Like

Please checkout an In Editor and Component that allows merging of background images, etc. at GitHub - Super-Genius/UnityPreviewGenerator: Generates preview textures for sprites, icons of Unity models

Wiki Documentation forthcoming

1 Like

Perfect! Thanks :slight_smile:

Hi, this tool is great and I see you have a ton of other clever content available. Thank you for that!

I do have a question though, do you think there’s a way for GenerateMaterialPreview to ignore the Ambient Lighting so it always looks the same, similar to the Unity Inspector Material Preview?

Thanks

Ok so I seem to be successful by changing the ambient mode and then changing it back again:

RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
float oldIntensity = RenderSettings.ambientIntensity;
RenderSettings.ambientIntensity = 1f;

sourceTexture = RuntimePreviewGenerator.GenerateMaterialPreview(prefab, PrimitiveType.Quad, 512, 512);

RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox;
RenderSettings.ambientIntensity = oldIntensity;

I’ve also added a Layer to the GameObject, so I can exclude it from the Directional Light.

Perfect I would say.
Thanks!

1 Like