- Home /
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!
Answer by DiegoSLTS · Aug 15, 2016 at 02:11 AM
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.
Answer by SunnyChow · Aug 15, 2016 at 03:23 AM
. 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.
Answer by TheDawningLegend · Aug 15, 2016 at 05:08 PM
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?
You should copy the compiler error when you say there's a compiler error... but I guess it's a UnityEditor namespace not found or something like that. You can't use UnityEditor classes in runtime by design. You have to use something else, GetAssetPreview is intended for use in a custom window or inspector, not to use in your game.
Also, use the "Add comment" button below an answer to reply to that user ins$$anonymous$$d of posting a new answer.