- Home /
Render a list of objects into a Texture2D array
I have an array of game prefabs and I want to make thumbnails of them (in runtime) like in the editor. I have a coroutine that is supposed to take care of things. However I can't seem to render the objects properly, all of the thumbnails appear empty (just the camera background).
This is the code: IEnumerator RTRoutine(){ if(previewCamera != null) Destroy (previewCamera); Camera cam; previewCamera = new GameObject("_AssetCamera"); previewCamera.transform.position = -Vector3.forward*10f; cam = previewCamera.AddComponent (); cam.depth = 100; cam.cullingMask = (1 << 19); cam.clearFlags = CameraClearFlags.Depth; cam.enabled = false; for(int i = 0; i < gamePrefabs.Length; i ++){ GameObject previewObj = (GameObject)Instantiate (gamePrefabs[i], Vector3.zero, Quaternion.identity); yield return new WaitForSeconds(0.1f); yield return new WaitForEndOfFrame(); previewObj.layer = 19; cam.targetTexture = assetPreviewTexture; cam.Render(); RenderTexture.active = assetPreviewTexture; assetPreviews[i] = new Texture2D(64, 64, TextureFormat.RGB24, false); assetPreviews[i].ReadPixels(new Rect(0, 0, RenderTexture.active.width, RenderTexture.active.height), 0, 0); assetPreviews[i].Apply(); Destroy (previewObj); } Destroy (previewCamera); previewCamera = null; }
Why are the thumbnails appearing empty ? I can see in the editor that assetPreviewTexture updates with all of the objects ontop of each other (yeah, it's like they just stack up and don't destroy).
Your answer
![](https://koobas.hobune.stream/wayback/20220613163259im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Render Android device camera from native pointer 0 Answers
OpenGLES error 0x0502 when TextureFormat.BGRA32 is used 0 Answers
Imported Plane Mesh Not Rendering Textures Properly 1 Answer
why texture2d sprite rendering not showing in game 0 Answers
Pixels not equal size and thin white stripes between pixels 2 Answers