# How to properly use DrawMaterialToRenderTarget in C++?

**URL:** <https://forums.unrealengine.com/t/how-to-properly-use-drawmaterialtorendertarget-in-c/428482>\
**Category:** Asset Creation\
**Tags:** draw, unreal-engine, Scripting, render-target, question\
**Created:** [July 1, 2018, 5:16pm UTC](https://forums.unrealengine.com/t/how-to-properly-use-drawmaterialtorendertarget-in-c/428482 "2018-07-01T17:16:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShiftZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShiftZ](https://forums.unrealengine.com/u/ShiftZ)\
**Post date:** [July 1, 2018, 5:16pm UTC](https://forums.unrealengine.com/t/how-to-properly-use-drawmaterialtorendertarget-in-c/428482/1 "2018-07-01T17:16:11Z")

</div>

“Renders a quad with the material applied to the specified render target.”

Sound quite straight simple, let’s try it:

```
UTexture2D* MakeTexture( const FString& name, UWorld* world )
{
	UStaticMesh* plane = LoadObject<UStaticMesh>(nullptr, TEXT("/Engine/BasicShapes/Plane"));
	UTextureRenderTarget2D* target = LoadObject<UTextureRenderTarget2D>(nullptr, TEXT("/Game/Target"));
	UKismetRenderingLibrary::DrawMaterialToRenderTarget(world, target, plane->GetMaterial(0));
	return target->ConstructTexture2D(world, name, EObjectFlags::RF_NoFlags, CTF_DeferCompression);
}

```

The code above gives a blank texture instead of a quad with applied material.

---

<div class="post-metadata">

**Author:** ![iithron](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@iithron](https://forums.unrealengine.com/u/iithron)\
**Post date:** [August 2, 2023, 4:53pm UTC](https://forums.unrealengine.com/t/how-to-properly-use-drawmaterialtorendertarget-in-c/428482/2 "2023-08-02T16:53:05Z")

</div>

I’ve the same problem. Still trying to figure it out.  
When I use the node in blueprint with the material and render target created by c++ everything works as expected (the rendered texture seems a bit blurred, though).  
But when I call the node’s function in c++ I get at most a render target with a uniform color.

One thin: it seems that you have to use an unlit material and connect your color to the “Emissive Color” output.

That said, it works for me with single color debug materials.  
Somehow, it also works with a more complex material, but the render target is just filled with a single color. Could be a problem with UVs, somehow. But then I don’t understand why it works in blueprint…

---

<div class="post-metadata">

**Author:** ![\_NoDeath](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_NoDeath](https://forums.unrealengine.com/u/_NoDeath)\
**Post date:** [August 6, 2023, 10:34am UTC](https://forums.unrealengine.com/t/how-to-properly-use-drawmaterialtorendertarget-in-c/428482/3 "2023-08-06T10:34:56Z")

</div>

I have the exact same problem.  
could you find a solution for it ?

---

<div class="post-metadata">

**Author:** ![MarkEntingh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/markentingh/32/984569_2.png) [@MarkEntingh](https://forums.unrealengine.com/u/MarkEntingh)\
**Post date:** [April 9, 2024, 6:53am UTC](https://forums.unrealengine.com/t/how-to-properly-use-drawmaterialtorendertarget-in-c/428482/4 "2024-04-09T06:53:19Z")

</div>

I’m pretty sure that you have to wait until the material is done rendering to the render target before constructing a texture 2D or else it will be blank.
