- Home /
How can I display Asset Prefab preview image on an UI image in my game?
I am trying to display the asset preview image on the UI image in my game. To do this, I first imported using UnityEditor;
to my script. However, I was told this will not work in the actual build. Additionally, I used this code below to display the asset preview:
Texture2D t2D = AssetPreview.GetAssetPreview(_displayGameObjects[0]);
Sprite displaySprite = Sprite.Create(t2D, new Rect(0, 0, t2D.width, t2D.height), new Vector2(.5f, .5f);
displayImage.sprite = displaySprite;
This too only shows the image correctly if t2D is initialized in the Start(); method.
Would appreciate some help if someone can point out to me how to get the asset preview image, or retrieve it from the projects files and copy it over to assets.
Comment
Your answer
Follow this Question
Related Questions
Custom Thumbnails for Prefabs 0 Answers
Previewing mesh before instantiating 1 Answer
Change angle of camera in prefab preview 1 Answer
The associated script cannot be loaded using UI prefab 0 Answers