Did 5.2.1 change SetOverlayMaterial? Getting error since update...

I was basically turning my overlay material on/off by setting it to a nullptr when ‘off’. But directly after the update, I am now getting a crash every time it calls TileMesh->SetOverlayMaterial(nullptr); and it directly states the error is that it’s a nullptr. This is straight up recommended in documentation and pretty much any tutorial or what have you out there. Is anyone else experiencing this?

Do I just set the material to a blank one? I was going to just change the Opacity attribute but to be totally honest, I can’t figure out how to do it in c++.

I think this might be a conversion error.

Just made a test project where I added functions that worked as intended.
Characters mesh adds material or removes it.

void  AMyPlayer::ToggleOn() {
	GetMesh()->SetOverlayMaterial(overlayMaterial);
}

void AMyPlayer::ToggleOff(){
	GetMesh()->SetOverlayMaterial(nullptr);
}

1 Like

Ah, you think it’s because my project was originally 5.2? I mean that’s totally possible.

Still kind of annoying, though.

Maybe try deleting temp folders

  • DerivedDataCache
  • Intermediate
  • Binaries
  • .vs

& files
.vsconfig
your sln file

and then right click your uproject and regenerate the code.

I didn’t think to regenerate, but honestly I probably should have done that anyway with the update! Thanks, I’ll give it a shot.

Did you find a solution to this issue? I’m doing the same thing. Setting the material when outline is on and setting to nullptr when it is off. Occasionally I get a crash which leads back to the material as the culprit.

The only way I found around it was to create an empty material and assign it to that rather than null. It’s slightly more expensive, but I haven’t had a crash since.

That still doesn’t work for me. It will work for a short duration and then crash. The only thing that works for me is a parameter in the material which turns the opacity on and off. Feel free to share if you think I’m missing something.

If the object you are setting the overlay on has been changed in some ways, you might need to reset it first.

I don’t know if you are using bp or c++, but this is what I have. It runs a lot of checks, but essentially ensures I will never have a crash. Should also be easy to replicate in BP.

void ADungeonBuilding::Highlight(const bool Highlight)
{
	if (Highlight)
	{
		if (OverlayMat->IsValidLowLevel())
		{
			if (!IsValid(BuildingMesh))
			{
				TArray<UStaticMeshComponent*> StaticMeshItems;
				GetComponents(StaticMeshItems);

				if (!StaticMeshItems.IsEmpty())
				{
					BuildingMesh = StaticMeshItems[0];
					BuildingMesh->SetIsReplicated(true);
				}
				else
				{
					UE_LOG(LogTemp, Warning, TEXT("DungeonBuilding::Highlight -> No mesh was found!"));
					return;
				}

			}

			BuildingMesh->SetOverlayMaterial(OverlayMat);
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("DungeonBuilding::Highlight -> No overlay material was found!"));
		}
	}
	else
	{
		if (IsValid(BuildingMesh))
		{
			if (EmptyOverlayMat->IsValidLowLevel())
			{
				BuildingMesh->SetOverlayMaterial(EmptyOverlayMat);
			}
			else
			{
				UE_LOG(LogTemp, Warning, TEXT("DungeonBuilding::Highlight -> No EmptyOverlayMat found on deselect! (1)"));
			}
		}
		else
		{
			BuildingMesh = GetComponentByClass<UStaticMeshComponent>();
			if (IsValid(BuildingMesh))
			{
				BuildingMesh->SetIsReplicated(true);

				if (EmptyOverlayMat->IsValidLowLevel())
				{
					BuildingMesh->SetOverlayMaterial(EmptyOverlayMat);
				}
				else
				{
					UE_LOG(LogTemp, Warning, TEXT("DungeonBuilding::Highlight -> No EmptyOverlayMat found on deselect! (2)"));
				}
			}
			else
			{
				UE_LOG(LogTemp, Warning, TEXT("DungeonBuilding::Highlight -> No mesh found on deselect!"));
			}
		}
		
	}
}
1 Like