Dynamically create SceneCapture2D and render an image when creating a UI Widget, used for an image inside the Widget.

Hello dear other UE5 Devs,

The Title basically sums it up already very well. I will support some additional screenshots here and further go into detail in the hope that some of you that are more talented than me can help me out.

My problem that needs a solution:
I’m making an Inventory UI, I’d like to use rendered images of 3D objects I’m using ingame instead of tediously creating images in photoshop and importing them to the game.

what I tried so far:
I followed some tutorials on how to use the SceneCapture2D, render that to a texturetarget and use it inside a material which I then use inside the Widget.

Inventory UI, using the Widgets
image

Mesh and SceneCapture2D

But I not only have one mesh but I could technically have 100 or more. I could add a Silencer or other attachment to this or other meshes and it should correctly display in the Widget.

So basically what I need:
So instead of preplacing all the components needed, I’d like to dymically create those rendered textures and set the brush of the image from a dynamic material instance.

what I think has to be done when an item Widget is created inside the Inventory:

  1. Create the Mesh somewhere in the world, outside the sky box
  2. Create the SceneCapture2D
  3. Create and Set the Texture Target
  4. Create the Material
  5. Apply the Material to the Widget’s Image Brush

So I tried around, watched some other tutorials but I couldn’t figure it out. There is a tutorial on Portals, they used scene capture components inside an actor blueprint but it wasn’t covering widgets, the material was very complicated and also used Niagara. That was too much for my Unreal Engine newbie brain.’
I hope someone can give me a detailed guide on how I could solve this particular problem.

Ok, I did some progress.
image

I actually added the SceneCapture2D as component to a pawn which I then create on the construct event of the widget.


but I have one last problem. I only want to render the image once. It only works when one of those two flags are set.
I guess the on movement means, if there is any movement in the scene, or the camera moves it captures? If it only renders on camera movement, and I don’t move the camera anymore it should be ok for performance?
But is there a way to only render when the pawn is created?