Download

Compilation problem with loading texture from material in slate




class GameResources
{
public:
    GameResources() = default;
    void Initialize();
    void Shutdown();
    void ReloadTextures() {}
    TSharedPtr<FSlateGameResources> GetSlateGameResources();
    static TSharedPtr<FSlateGameResources> Get();
private:
    TSharedPtr<FSlateGameResources> mMyUIResources = nullptr;
};

#define TEXTURE_BRUSH(PathName, Size) FSlateDynamicImageBrush(Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), nullptr, TEXT(PathName))), Size, PathName)

void GameResources::Initialize()
{
    ...
    mMyUIResources->Set("WoodTexture", new TEXTURE_BRUSH("/Game/TestCubes/WoodTexture", FVector2D(100.0f, 100.0f)));
    ...
}

void GameResources::Shutdown()
{
    FSlateStyleRegistry::UnRegisterSlateStyle(*mMyUIResources);

    ensure(mMyUIResources.IsUnique());

    mMyUIResources.Reset();
}




Everything is fine and works, but sometimes i’ve got errors in VS2017:

Next recompile will be without erorrs.
If i’ll close UE Editor it will compile without errors from first time.

It is not depended of other code or build type. It depends of running game before rebuilding.
Any ideas how to handle this annoying messages?
May be it is a known bug in the builder?