Wondering if somebody can point me in the right direction.
I want to create a Dynamic Texture Render Target at runtime within a users HUD (only their HUD will be able to access it, or use it. I don’t want every player in a game to be adding all this overhead multiple times). Ideally, I want to be able to access this in UMG and draw it as a regular image, while filling it from a Camera.
The Camera Component would ideally be created as a sub-component of the Player Controller, since I doubt the HUD has the ability to do this.
Essentially it’s for a targeting Camera. When a player hits the ‘T’ key, I want it to ‘Target’ whatever the reticle is over, spawning a camera that orbits the target and a small view in the users viewport of that cameras view. The orbiting camera should be easy enough, I just can’t figure out how to create the RenderTarget at runtime.
Also, this is for Multiplayer, hence the need for keeping it as local as possible.
If possible, I’d also like to ONLY draw the object I’m targeting in that render texture. I realise that may not be possible, but it would probably heavily reduce the amount of rendering overhead.
Send code related to this to Rama for his Blueprint nodes pack a while ago.
If you haven’t already, download it.
In the C++ source, look for CreateTextureRenderTarget2D().
Its pretty straight forward
I’d suggest you create a dedicated actor to hold your camera component instead of making it part of the player controller. Spawn it client side and use its tick function, rather than the player controllers, to update the cameras position/rotation relative to the target.
Ah nice! Just found that function, so where do you tell the camera to send it’s info to that Render Target? Assuming that’s part of the Camera Component itself?
Yep.
You set the TextureTarget of your scene capture component to the render target you just created.
When ever the scene component updates the texture - either per frame or when you move it, depending on the setup of the scene capture component - it’ll update the texture.
All good.
Looking at the C++, I noticed AddToRoot().
I think I did this to stop it from being garbage collected if it was unreferenced.
Just something to thing about
Yeah I used it as part of the Constructor, and then found I got a crash when I stopped playing. As it’s part of the object constructor I don’t need it, so I just took it out.