Download

Changing wireframe color at runtime

I have a camera in my scene rendering in wireframe with ShowFlags.SetWireframe(true). It works great. However, every mesh has a default wireframe color based on its physics state, and I want them all to be the same color. After my level loads (the first tick after BeginPlay()), I’m running the following code:


	for (TActorIterator<AActor> Iter(GetWorld()); Iter; ++Iter) {
		if (true) {
			UStaticMeshComponent* Mesh = Cast<UStaticMeshComponent>(Iter->GetComponentByClass(UStaticMeshComponent::StaticClass()));
			if (Mesh != nullptr) {
				Mesh->bOverrideWireframeColor = true;
				Mesh->WireframeColorOverride = FColor::Red;
			}
		}
	}

Unfortunately, this doesn’t seem to do anything. Looking at UStaticMeshComponent.cpp, I see


FColor UStaticMeshComponent::GetWireframeColor() const
{
	if(bOverrideWireframeColor)
	{
		return WireframeColorOverride;
	}
	...
}

I’ve also confirmed by looping through all static mesh components in the scene later to ensure that they’re all set to override with my custom color. So it seems like it should be working, yet the camera is still rendering the default colors. If I set the override on the mesh in the level editor, it works fine, so it’s only a problem with how I’m doing it through code. I’ve ensured that the camera is redrawing every tick. I’ve also tried making sure the bool and color are set before the camera is even spawned.

Anyone have ideas?

I actually managed to figure this out. You need to call Mesh->MarkRenderStateDirty() to get it to update.