Im painting a texture at run time. The texture changes but then I cant export it or save it permanently:

I tried saving it and exporting several times this way, and it always reverts back to the original texture…

This is the code that im using to paint the texture:

void ATextureReader::PaintPixel(UTexture2D* MyTexture2D, FColor Color, FVector2D Coords) {
    UTexture2D* Texture = MyTexture2D;
    Texture->MipGenSettings = TMGS_NoMipmaps;
    Texture->Filter = TF_Nearest;
    int32 SizeX = Texture->GetSizeX();
    FColor* Pixels = (FColor*)Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
    Pixels[(int32)Coords.X + (int32)Coords.Y * SizeX] = Color;
    Texture->PlatformData->Mips[0].BulkData.Unlock();
    Texture->UpdateResource();
}

Call TextureAsset->Modify()

1 Like

Just did at the end it changes nothing. Texture still the same in the source and when i export.

Asset icon changed after calling? :thinking:

image

1 Like

Nothing… I wish that single line did it though. You can see by the commented code the stuff im trying its quite messy :open_mouth:

Are you sure you’re calling the function on a texture ASSET?

1 Like

thats a UTexture2D* Texture. Do i have to “create an asset”? Why cant we just save the texture and call it a day :lion:

Can you compare the texture you are modifying (MyTexture2D param) and the texture asset from the content browser?

image

Do they have the same GetPathName()?

Although this is of course VERY strange, because the picture changes, but as if it does not belong to the asset…

1 Like

Yes i basically store that texture as a Texture2D in blueprints and send it as a parameter to a function in C++.
Then in C++, i modify the texture, paint it as i need.
Until here its all good. The texture is visible with the new modifications and this you can see in game and everywhere.
Except i cant save or export the texture with the new modifications. Its there always temporarily. So when i reopen Unreal its back to its former self :lion:.
Is there even a solution for this, maybe its not possible?

Can you show this?

Or try calling TransactObject on the blueprint for the same texture reference that you are modifying with your function.

1 Like

Sure its just a variable where i store the texture and then send it to the function as
UTexture2D*

image

This doesn’t work?:
image

P.S. It seems Modify only works in Editor objects (utility widget, utility object etc.)… :sweat_smile:
So if you do this in an actor, then this is probably the reason.

1 Like

just tried it. It doesnt work, unfortunately.
It just so weird that i can change the texture in the game, but cant save it as is, or export it.
This boggling my mind.

:melting_face:

Can you repeat step by step? There’s no way it won’t work…




It doesnt work with a texture that you paint. It will revert back to its original self, no matter what you do.
The only solution so far, that i can think of, is to create a new texture, and copy the old texture, and save it somehow in C++. This is a complicated process though i already found some sources that may solve this by copying each pixel to the new texture.

This is my trying the Transact Object node:

It WILL NOT work in Actor. Create an Editor Utility Widget/Object and call it there.