How to create RenderTextures (or other assets) at runtime

Hello Fellow Devs

I want to show rotating objects in a ui list, to preview said objects.

The first difficulty is, that those objects can be created/changed at runtime. So I need to dynamically import them and cannot use AssetDatabase in editortime.
I found a solution for the import already in writing my own object (.obj) parser/importer.

To the question(s)
I load the objects into a separate layer and create an extra camera for each object. Then I want to dynamically create a RenderTexture from the cameras and add this render texture to RawImage elements in my ui list.

The problem is, how can I create a RenderTexture at runtime, that is connectable to the extra layer camera and the ui list elements?

(I want to avoid placing the objects directly into the ui and work with a scale fitter. It would be my last fallback option)
(I also want to avoid precreating a pool of rendertextures in editor time)

Question1:
Is this RenderTexture workflow good here or did I miss a better solution?
Question2:
How can I create the RenderTexture at runtime and connect it to the camera/ui element? (A bonus would be, how to create any AssetType at runtime, if they would share script parts)

Thx in advance :slight_smile:

Looks like you miss the entire workflow. One do not create render texture from camera. Instead, you create a render texture and assign it to camera. Creating render texture is as simple as

var rt = new RenderTexture(Screen.width, Screen.height, 24);
1 Like

Yes that is what I do. Maybe I wrote it in a bad way. Does your code work at runtime? So I can use “rt” as reference for my RawImage and establish the visual link between the extra camera and the ui?