Generate preview textures (thumbnails) for your GameObject's or materials on the fly in Unity
Generate preview textures (thumbnails) for your GameObject's or materials on the fly in Unity
Available on Asset Store: https://assetstore.unity.com/packages/tools/camera/runtime-preview-generator-112860
Forum Thread: https://forum.unity.com/threads/runtime-preview-thumbnail-generator-open-source.500194/
Discord: https://discord.gg/UJJt549AaV
This plugin helps you generate preview textures (thumbnails) for your GameObjects or materials in Texture2D format on the fly.
There are 5 ways to install this plugin:
https://github.com/yasirkula/UnityRuntimePreviewGenerator.gitopenupm add com.yasirkula.runtimepreviewgeneratorThere are 2 main functions and on Unity 2018.2 or newer, their async variants:
…RuntimePreviewGenerator.GenerateMaterialPreview function generates thumbnail for a material using a primitive object whereas RuntimePreviewGenerator.GenerateModelPreview function generates thumbnail for a GameObject (can be either a prefab or a scene object).
The width and height parameters define the size of the thumbnail texture. To guarantee a clear shot from the model in GenerateModelPreview function, the model is moved far away from the origin of the world (if it is not static) and then returned to its original position after the thumbnail is generated (this effect won't be visible to any scene cameras).
If shouldCloneModel parameter in GenerateModelPreview function is set to true, the model is instantiated (cloned) and the clone is used to create the thumbnail texture. This parameter is automatically set to true for prefabs. Unless you absolutely do not want your scene object to be moved, keep it as false for increased performance.
When the model has a child Particle System, the returned thumbnail may look empty. That's because Particle Systems usually have ridiculously large bounds and the camera needs to zoom out a lot to compensate that. Therefore, by default, Particle Systems are ignored while capturing thumbnails. You can set shouldIgnoreParticleSystems to false to override this behaviour.
There are also 2 variants for these functions that use replacement shaders while rendering the thumbnails (see: https://docs.unity3d.com/Manual/SL-ShaderReplacement.html) (URP and HDRP aren't supported). These functions are:
…There are a few options to customize the generated thumbnails:
Please note that procedurally generated textures are not automatically garbage collected (until scene changes), so you are recommended to call Destroy(thumbnailTexture) or DestroyImmediate(thumbnailTexture) after you no longer need a thumbnail.
Here are two example thumbnails, one with perspective projection and grey background and the other with orthographic projection and transparent background:
DEBUG_BOUNDS Mode: the location of the preview render camera is calculated using the Renderer bounds of the target object. If you want, you can uncomment the first line of the RuntimePreviewGenerator script to see the bounds in the preview Textures
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).
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.
No open issues yet, or sync has not completed.