Create material or texture from a render target in C++

There are many tutorials to do this in Blueprint. But I want to dynamically change the render target in runtime. The number of render targets is also unknown before runtime. So I prefer using C++. I do not want to use an editor-only feature because I need it during gameplay.

All I want is to display what a scene capture component sees on UImage. Maybe what I am trying to do is not the right way. Thank you for your advice in advance!