TSoftObjectPtr<> (Texture2D) loads wrong size values.

I was having the same problem in 5.2.1 but I think I found a fix for it.

In the editor, when calling MyImage->SetBrushFromTexture(newTexture, true); for the first time, the image would always be 32 x 32. If I stopped the game and played it again, the image was the correct size. Image sizes would always be correct in packaged builds.

After tracing through the code, I found that GetSizeX() in Image.cpp was always returning a default checkerboard texture with a size of 32 x 32 in the editor, and that’s where I found this comment:

While compiling the platform data in editor, we will return the placeholders value to ensure rendering works as expected and that there are no thread-unsafe access to the platform data being built. Any process requiring a fully up-to-date platform data is expected to call FTextureCompiler:Get().FinishCompilation on UTexture first.

So, then I tried this line of code before using SetBrushFromTexture and now the size of the image is correct every time:
FTextureCompilingManager::Get().FinishCompilation({newTexture});

The include for the function is:
#include "TextureCompiler.h"

6 Likes