How to make thumbnails from GameObjects?

Hello, I am working on a character customization and I would like to know how I could make a thumbnail system for my selections. I believe it could take a picture of a GameObject in the resources folder and apply the image to a UI image. Is that possible?

Thanks for the help!

I know only 2 methods and both require a secondary camera, render textures and spawning all objects one after another for at least one frame. The difference is if you do everything in memory at runtime or if you create assets at edition time. Usually you don’t want the second option because it’s error prone and making thumbnails it’s usually tedious, but you can make an editor script that does everything for you. The runtime option is better for project organization, but it could take a lot of frames to create those thumbnails.

. Method 1

set a secondary camera, use it to render every items to their own thumbnail RenderTexture, use these RenderTexture in your ui. you can use enumerator to avoid a lag

. Method 2 (the logic is easy but bad for performance if in massive)

set your ui canvas to “Screen Space - Camera”, load your item model directly on the UI

. Method 3 (pre-render)

use PreviewRenderUtility to render every items to their own png file.

I cant use option 3 if I want to build the game because it launches a compile error. My code is :

Texture2D image = UnityEditor.AssetPreview.GetAssetPreview (Resources.Load ("Hair/" + copy.ToString ()));
selection.transform.GetChild (0).GetComponent<Image> ().sprite = Sprite.Create (image, new Rect (0, 0, image.width, image.height), new Vector2 (0.5f, 0.5f));

What could I do to fix that?