Okay, well I saw that there is a different way to create textures that seems to work for me, going along the lines of:
// Create 2x2 texture with red, green, blue, white texels
FColor Data[4] = {FColor::Red, FColor::Green, FColor::Blue, FColor::White};
MyTexture = Cast<UTexture2D>(NewObject<UObject>(GetTransientPackage(), UTexture2D::StaticClass(), NAME_None, RF_Transient));
MyTexture->Source.Init(2, 2, 1, 1, TSF_BGRA8, reinterpret_cast<uint8*>(Data));
MyTexture->UpdateResource();
This one seems to work for me – for now at least.
I will however not be closing this topic until someone can provide an explanation to me what is the difference between the above two approaches, and why one of them works while the other one doesn’t.
P.S.: There is another weird issue where IsValid(MyTexture)
returns true in C++ immediatelly after the code above, however in a blueprint that same call to IsValid will return false for this 1 frame until becoming valid on the next. Great.