Engine crashes when stop simulating while a dynamic material instance is being set to a sprite component

By inserting the C++ code below into the EndPlay function of a certain class, the crash no longer occurs.

#include "Materials/MaterialRenderProxy.h"

void ASampleViewer::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);

#if WITH_EDITOR
	if (EndPlayReason == EEndPlayReason::EndPlayInEditor)
	{
		FUniformExpressionCacheAsyncUpdateScope AsyncUpdateScope;
	}
#endif
}

There is no doubt that this is not the correct way to deal with it, but I have found a way to avoid it as a workaround, so I would like to share it with you.

4 Likes