UTexture2D::CreateTransient and SRGB

I have a simple dynamic user interface material instance with a texture sampler connected directly to the Final Color node, and that’s all

At runtime I call UTexture2D::CreateTransient and write to the Texture2D->GetPlatformData()->Mips[0].BulkData; and it all works, and the texture displays with the right colors on the HUD.

What’s really odd though is that I have to set Texture->SRGB to false to get the texture to display correctly - even though I am writing SRGB encoded values to the bytes of the texture. ???

If I set Texture->SRGB to true then the color gets incorrectly passed through an srgb to linear conversion twice - and so the colors come out much darker than they are supposed to.

Does anyone understand what’s going on? When I set SRGB to true, where are the two places it is getting an srgb to linear conversion applied, and which one is incorrect ?

Take my answer with salt.

If I understand correctly, It’ related to Texture RHI Resource.

On sRGB texture sampler type, The hardware converse sRGB space to linear color when texture sample.
When you write to texture through render target, You write linear color and hardware converse it back to sRGB space.

Try check your texture sampler type in your material.