I have a weapon class that has a reference to a UI icon in it, and it’s a TSoftObjectPtr<>.
When I need to use this icon, I do Icon.LoadSynchronous() and use it to set a UI image, changing the size of the image to match the Texture size.
The issue is, the first time I load the project and try setting the image, the result is 32x32, although the correct asset is being loaded. All the subsequent times it sets to a correct size, but after relaunching the projects, the first time is always 32x32.
I’ve tried this with TSoftObjectRef<UObject> and TSoftObjectRef<UTexture2D>, the result is the same. If I use a regular pointer, everything works fine.
How do I make the object from the soft pointer load correctly for the first time?
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"