# C++ Convert UTextureRenderTarget2D to UTexture2D

**URL:** <https://forums.unrealengine.com/t/c-convert-utexturerendertarget2d-to-utexture2d/767911>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, c, question, Blueprint\
**Created:** [February 10, 2023, 9:18am UTC](https://forums.unrealengine.com/t/c-convert-utexturerendertarget2d-to-utexture2d/767911 "2023-02-10T09:18:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salvo\_Nostrato](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Salvo\_Nostrato](https://forums.unrealengine.com/u/Salvo_Nostrato)\
**Post date:** [February 10, 2023, 9:18am UTC](https://forums.unrealengine.com/t/c-convert-utexturerendertarget2d-to-utexture2d/767911/1 "2023-02-10T09:18:55Z")

</div>

Hi there I have a code where I want to convert Texture 2D Render Target to Texture 2D. The code Builds fine however the node I get needs a target connected because is a non-static function.  
I do I create a target for my BP Library? Or how can I remove ‘this’ if I make the function static?

.h

```auto
UFUNCTION(BlueprintCallable, Category = "Texture")
UTexture2D* GetTextureRenderTarget(UTextureRenderTarget2D* RTarget);

```

.cpp

```auto
UTexture2D* UTestBPLibrary::GetTextureRenderTarget(UTextureRenderTarget2D* RTarget)
{
	
	UTexture2D* Texture2D;

	Texture2D = RTarget->ConstructTexture2D(this, "texture", EObjectFlags::RF_NoFlags, CTF_DeferCompression);
	RTarget->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
#if WITH_EDITORONLY_DATA
	Texture2D->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif
	Texture2D->SRGB = 1;
	Texture2D->UpdateResource();

	return Texture2D;
}

```

---

<div class="post-metadata">

**Author:** ![EliasWick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eliaswick/32/1175208_2.png) [@EliasWick](https://forums.unrealengine.com/u/EliasWick)\
**Post date:** [February 10, 2023, 1:17pm UTC](https://forums.unrealengine.com/t/c-convert-utexturerendertarget2d-to-utexture2d/767911/2 "2023-02-10T13:17:15Z")

</div>

You can remove the `this` argument from the `ConstructTexture2D` function by making the `GetTextureRenderTarget` function static.

Here’s how you can do that:

**.h**

```auto
UFUNCTION(BlueprintCallable, Category = "Texture")
static UTexture2D* GetTextureRenderTarget(UTextureRenderTarget2D* RTarget);

```

**.cpp**

```auto
UTexture2D* UTestBPLibrary::GetTextureRenderTarget(UTextureRenderTarget2D* RTarget)
{
    UTexture2D* Texture2D;

    Texture2D = RTarget->ConstructTexture2D("texture", EObjectFlags::RF_NoFlags, CTF_DeferCompression);
    RTarget->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
#if WITH_EDITORONLY_DATA
    Texture2D->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif
    Texture2D->SRGB = 1;
    Texture2D->UpdateResource();

    return Texture2D;
}

```

The `this` argument is only needed for non-static member functions, and it refers to the instance of the object that the function is being called on. Since you don’t need to access any object-specific data in your `GetTextureRenderTarget` function, you can make it static, which allows you to call it without an instance of the object.
