Hi,
I’d like to make custom material from editor, everything works perfectly fine except the one thing - Setting SamplerType crashes editor with assertion:
Assertion failed: TextureReferenceIndex != INDEX_NONE [File:D:\Build\++UE4\Sync\Engine\Source\Runtime\Engine\Private\Materials/HLSLMaterialTranslator.h] [Line: 3992] Material expression called Compiler->TextureParameter() without implementing UMaterialExpression::GetReferencedTexture properly
Full stacktrace: SamplerType_Stacktrace - Pastebin.com
Short reproduced code:
void ABugCoder::CreateMaterial()
{
UPackage* Package = CreatePackage(NULL, TEXT("/Game/SomeFolder/M_MyMaterial"));
UPackage* OutermostPkg = Package->GetOutermost();
UMaterialFactoryNew* Factory = NewObject<UMaterialFactoryNew>();
UMaterial* Mat = Cast<UMaterial>(Factory->FactoryCreateNew(UMaterial::StaticClass(), OutermostPkg, TEXT("M_MyMaterial"), RF_Standalone | RF_Public, NULL, GWarn));
FAssetRegistryModule::AssetCreated(Mat);
Mat->MarkPackageDirty();
Package->SetDirtyFlag(true);
UMaterialExpressionTextureSampleParameter2D* NormalTexture = NewObject<UMaterialExpressionTextureSampleParameter2D>(Mat);
NormalTexture->SetParameterName(TEXT("NormalParam"));
NormalTexture->Texture = LoadObject<UTexture2D>(NULL, TEXT("/Engine/EngineMaterials/FlatNormal"), NULL, LOAD_None, NULL);
NormalTexture->SamplerType = EMaterialSamplerType::SAMPLERTYPE_Normal; // Line that will affect in crash in PostEditChange();
// it works without this line, but need to set SamplerType manually (from material editor) in created material
Mat->Normal.Connect(0, NormalTexture);
Mat->PostEditChange();
}