Hi Folks,
I’m trying to experiment with dynamic mesh, using the tutorials by Ryan here: https://github.com/gradientspace/UnrealMeshProcessingTools
It all works fine, But then I try to change something on it, such as the static material to dynamic one. Like here:
At begin play I do this:
DynamicMatInstance = UMaterialInstanceDynamic::Create(Material, this);
if (NULL != DynamicMatInstance)
{
DynamicMatInstance->SetTextureParameterValue(ImageTexParamName, Image2D); // it is UCanvasRenderTarget2D obj
DynamicMatInstance->TwoSided = 1;
}
And in the update SDMC mesh I do this:
UpdateSDMCMesh()
{
if (MeshComponent && DynamicMatInstance)
{
*(MeshComponent->GetMesh()) = SourceMesh;
MeshComponent->NotifyMeshUpdated();
// update material on new section
//UMaterialInterface* UseMaterial = (this->Material != nullptr) ? this->Material : UMaterial::GetDefaultMaterial(MD_Surface);
MeshComponent->SetMaterial(0, DynamicMatInstance);
//MeshComponent->bExplicitShowWireframe = true;
}
But when I move around inside the viewport, often it is all right. I can see the material correctly. But then after a while I consistently I get this error from inside the Engine class FBaseDynamicMeshSceneProxy. The snippet below is from the function GetDynamicMeshElements, the last line is where I get access violation exception, as if the UseMaterial is null , but I inspect it in the debugger to be not null, so something is going on. Please advice.
// Draw the mesh.
for (FMeshRenderBufferSet* BufferSet : Buffers)
{
UMaterialInterface* UseMaterial = BufferSet->Material;
if (ParentBaseComponent->HasOverrideRenderMaterial(0))
{
UseMaterial = ParentBaseComponent->GetOverrideRenderMaterial(0);
}
FMaterialRenderProxy* MaterialProxy = UseMaterial->GetRenderProxy();