So, im working on a 3d " journal " interface, where the UI is drawn on a plane inside the journal model. I exposed the material instance on the UMGWidgetComponent so i can grab it and apply it to my mesh instead…My problem is that while i can apply the material just fine i cant get it to make the ui Somehow " fit " inside the plane, i also tried with a few different meshes with mixed results
Left is the UMG Widget material applied to a mesh, Right is the normal result on a widget component
Applying the Material to a plane, gives fairly good results ( although with some stretching , it " stretches " the UI based on the plane scale , ideally id like the UI to not be stretched )
And here is where the problem is. When using my own journal model . the pages have their own material slot and they are just planes… the problem is that the UI doesnt fit at all inside these
How did you expose the material instance? That’s really interesting!
For the UI in the page, I see some options:
Remap your pages UVs so that the page fills the UV completely, as the UI texture seems to do. Probably the most practical way of solving your problem.
See if the texture from the UI is passed to the material instance as a parameter. If it is, you could get that parameter and use it on a custom material of yours, with your own texture coordinates.
Just place the widget right in front of the page, really close, so it seems it’s in the page (this is the silly one XD)
This TextureFromWidget C++ function is great, but it seems to not work quite right in UE5.1. For some reason, the image is flipped vertically. Other than that, it looks good.
Does anyone have any idea why this is happening now in UE5, or how it can be fixed?
For example, if you want to flip it Horizontally:
// Lock and copies the data between the textures
TArray SurfData;
FRenderTarget* RenderTarget = TextureRenderTarget->GameThread_GetRenderTargetResource();
RenderTarget->ReadPixels(SurfData);
// Lock the texture so it can be modified
uint8* MipData = static_cast<uint8*>(Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
// Create base mip.
int32 Height = FMath::FloorToInt(DrawSize.Y);
int32 Width = FMath::FloorToInt(DrawSize.X);
uint8* DestPtr = NULL;
const FColor* SrcPtr = NULL;
for (int32 y = 0; y < Height; y++)
{
DestPtr = &MipData[(Height - 1 - y) * Width * sizeof(FColor)];
SrcPtr = const_cast<FColor*>(&SurfData[((Height - y) * Width)-1]);
for (int32 x = 0; x < Width; x++)
{
*DestPtr++ = SrcPtr->B;
*DestPtr++ = SrcPtr->G;
*DestPtr++ = SrcPtr->R;
*DestPtr++ = SrcPtr->A;
SrcPtr--;
}
}
// Unlock the texture
Texture->PlatformData->Mips[0].BulkData.Unlock();
Texture->UpdateResource();
If you want to flip it Vertically, it should be something like this: (I didn’t tried)
for (int32 y = 0; y < Height; y++)
{
DestPtr = &MipData[(Height - 1 - y) * Width * sizeof(FColor)];
int32 Line = FlipVertically ? y : (Height - 1 - y);
int32 LastColumnStart = FlipHorizontally ? Width - 1 : 0;
int32 Index = Line * Width + LastColumnStart;
SrcPtr = const_cast<FColor*>(&SurfData[Index]);
for (int32 x = 0; x < Width; x++)
{
*DestPtr++ = SrcPtr->B;
*DestPtr++ = SrcPtr->G;
*DestPtr++ = SrcPtr->R;
*DestPtr++ = SrcPtr->A;
FlipHorizontally ? SrcPtr-- : SrcPtr++;
}