Problem with Dynamic Materials

I started having problems with them after moving to 4.14. I thought I had fixed it, but now it’s still happening in no-editor builds… It’s been some time and I don’t exactly remember what I did back then, except I moved some code sections in a different order.

This is the console output:

Ensure condition failed: Materials[MaterialIndex].UVChannelData.bInitialized [File:D:\Build\++UE4+Release-4.14+Compile\Sync\Engine\Source\Runtime\Engine\Private\SkeletalMesh.cpp] [Line: 2620] 

For some reason, MSVC won’t let me look at the code, telling me sources are not available.

Call Stack:
    >	Project02-Win64-DebugGame.exe!USkeletalMesh::GetUVChannelData(int)	C++
     	Project02-Win64-DebugGame.exe!USkinnedMeshComponent::GetStreamingTextureInfo(class FStreamingTextureLevelContext &,class TArray<struct FStreamingTexturePrimitiveInfo,class FDefaultAllocator> &)	C++
     	Project02-Win64-DebugGame.exe!UPrimitiveComponent::GetStreamingTextureInfoWithNULLRemoval(class FStreamingTextureLevelContext &,class TArray<struct FStreamingTexturePrimitiveInfo,class FDefaultAllocator> &)	C++
     	Project02-Win64-DebugGame.exe!FTextureInstanceState::AddComponent(class UPrimitiveComponent const *)	C++
     	Project02-Win64-DebugGame.exe!FDynamicComponentTextureManager::IncrementalUpdate(class TArray<class UTexture2D const *,class TInlineAllocator<12,class FDefaultAllocator> > &,float)	C++
     	Project02-Win64-DebugGame.exe!FStreamingManagerTexture::IncrementalUpdate(float)	C++
     	Project02-Win64-DebugGame.exe!FStreamingManagerTexture::UpdateThreadData(bool)	C++
     	Project02-Win64-DebugGame.exe!FStreamingManagerTexture::UpdateResourceStreaming(float,bool)	C++
     	Project02-Win64-DebugGame.exe!FStreamingManagerCollection::UpdateResourceStreaming(float,bool)	C++
     	Project02-Win64-DebugGame.exe!FStreamingManagerCollection::Tick(float,bool)	C++
     	Project02-Win64-DebugGame.exe!UGameEngine::Tick(float,bool)	C++
     	Project02-Win64-DebugGame.exe!FEngineLoop::Tick(void)	C++
     	Project02-Win64-DebugGame.exe!GuardedMain(wchar_t const *,struct HINSTANCE__ *,struct HINSTANCE__ *,int)	C++
     	Project02-Win64-DebugGame.exe!WinMain()	C++
     	Project02-Win64-DebugGame.exe!__scrt_common_main_seh() Line 264	C++
     	kernel32.dll!00000000775759cd()	Unknown
     	ntdll.dll!00000000776aa561()	Unknown

When I run in debug-mode, I can just continue after the “ensure” and everything works and looks fine. How am I supposed to initialize the material’s UVChannelData? Why isn’t it happening automatically?..

So I had a closer look at what’s happening with my MIDs. They get initialized (the UVChannelData) when calling SkeletalMesh->InitResources(), but only in editor builds!!

So I looked at “InitResources” and it calls a function named UpdateUVChannelData, which does absolutely nothing without editor. Now, I think it’s safe to assume that’s why my MIDs don’t get their UVChannelData initialized either and produce an “ensure”-error.

What’s the point of this? What am I supposed to do?..

// UV density is not supported to be generated at runtime for now. We fake that it has been initialized so that we don’t trigger ensures.
StaticMesh->GetStaticMaterials()[MaterialSlotIndex].UVChannelData = FMeshUVChannelInfo(1.f);