the safest way is that you create another UTexture2D pointer and copy your generated texture to it when it is ready.
this way you are sure even if you are working on a separate thread there won’t be any conflict over accessing a locked texture.
after that you need to make a blueprint function that simply return a pointer to UTexture2D you have your texture stored in
I am trying to assign my own generated texture in C++ in an object in the scene in Unreal e.g. a cube.
The code with which I generate the texture is outlined below. I am using data from a Kinect device to create a color texture - just like a normal camera.