# Why does my Dynamic 2D Texture Show Up Blank?

**URL:** <https://forums.unrealengine.com/t/why-does-my-dynamic-2d-texture-show-up-blank/285688>\
**Category:** Rendering\
**Tags:** unreal-engine, Plugins, CPP, question\
**Created:** [June 12, 2014, 2:06pm UTC](https://forums.unrealengine.com/t/why-does-my-dynamic-2d-texture-show-up-blank/285688 "2014-06-12T14:06:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![druidsbane](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/druidsbane/32/1141411_2.png) [@druidsbane](https://forums.unrealengine.com/u/druidsbane)\
**Post date:** [June 12, 2014, 2:06pm UTC](https://forums.unrealengine.com/t/why-does-my-dynamic-2d-texture-show-up-blank/285688/1 "2014-06-12T14:06:57Z")

</div>

I’ve been trying to load up a dynamically created texture on a custom actor created as a plugin. Currently I can create a cube, load up my custom material and it shows up in the editor and game. If I then load up a 2D texture created dynamically (filled with noise so it is obvious it is being used) and set it on my material’a texture property it gets set but shows up as a blank grey or off-white. I’m using the method from the wiki to create and update the texture: [A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums](https://wiki.unrealengine.com/Dynamic_Textures)

Below is the relevant portion of the header:

```
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = StaticMeshComponents) TSubobjectPtr<UStaticMeshComponent> schwein;

UPROPERTY(EditDefaultsOnly, Category = Materials) UMaterialInterface *MasterMaterialRef;

UPROPERTY() UTexture2D *DynamicTexture;

UPROPERTY() UMaterialInstanceDynamic* RV_MatInst;

```

Below is the relevant portion of the actor implementation:

```
// create cube
schwein = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("schwein"));

// load material
static ConstructorHelpers::FObjectFinder<UStaticMesh>StaticMesh(TEXT("StaticMesh'/Game/Shapes/Shape_Cube.Shape_Cube'"));
static ConstructorHelpers::FObjectFinder<UMaterial> goldMaterial(TEXT("Material'/Game/Ibex/DesktopMaterial'"));

// create my custom material
MasterMaterialRef = goldMaterial.Object;
schwein->SetStaticMesh(StaticMesh.Object);

RootComponent = schwein;

// create random noise for texture
const int SizeX = 1024;
const int SizeY = 1024;
static uint8 data[SizeX * SizeY * 4] = { 0 };
srand(1982);
for (int i = 0; i < SizeX * SizeY * 4; ++i) {
	data[i] = rand() % 255;
}

// create dynamic texture
DynamicTexture = UTexture2D::CreateTransient(SizeX, SizeY);
DynamicTexture->AddToRoot();
DynamicTexture->UpdateResource();

// update dynamic texture
FUpdateTextureRegion2D r(0, 0, 0, 0, SizeX, SizeY);
UpdateTextureRegions(DynamicTexture, (int32)0, (uint32)1, &r, (uint32)(4 * SizeX), (uint32)4, data, false); // Using the UpdateTextureRegions from https://wiki.unrealengine.com/Dynamic_Textures
DynamicTexture->UpdateResource();

// update texture property on material and set object to use material
RV_MatInst->SetTextureParameterValue(FName("T2DTexture"), DynamicTexture);

schwein->SetMaterial(0, RV_MatInst);
```

---

<div class="post-metadata">

**Author:** ![druidsbane](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/druidsbane/32/1141411_2.png) [@druidsbane](https://forums.unrealengine.com/u/druidsbane)\
**Post date:** [June 12, 2014, 11:37pm UTC](https://forums.unrealengine.com/t/why-does-my-dynamic-2d-texture-show-up-blank/285688/2 "2014-06-12T23:37:11Z")

</div>

Interestingly enough it works now! I had code inside my actor’s tick class that got called once to initialize the texture with

> UpdateTextureRegions

If I just run the function on each update it works which means that the world wasn’t initialized on the first tick. Is there a recommended way of checking to know when one can start creating and updating textures?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9af1a529](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9af1a529](https://forums.unrealengine.com/u/anonymous_user_9af1a529)\
**Post date:** [July 13, 2014, 9:14pm UTC](https://forums.unrealengine.com/t/why-does-my-dynamic-2d-texture-show-up-blank/285688/3 "2014-07-13T21:14:22Z")

</div>

I’m having the same problem. Can you provide a bit more detail about how you were able to solve this? TIA.

Are you saying you called:

> **[UTexture2D::UpdateTextureRegions](https://docs.unrealengine.com/5.2/en-US/API/Runtime/Engine/Engine/UTexture2D/UpdateTextureRegions/)**
>
> Asynchronously update a set of regions of a texture with new data.

In your tick function? Or are you saying you called the function defined in:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![GerardD\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GerardD\_1](https://forums.unrealengine.com/u/GerardD_1)\
**Post date:** [July 21, 2014, 4:29am UTC](https://forums.unrealengine.com/t/why-does-my-dynamic-2d-texture-show-up-blank/285688/4 "2014-07-21T04:29:14Z")

</div>

I have been working with this Dynamic Textures function. I made a slight modification to the code to ensure that the texture is ready to use:

```
if (Texture && Texture->Resource)

```

replaces

```
if (Texture->Resource)

```

I found this removes some of the instability and ensures that the update function is only doing work when there is a texture to work upon
