First UGameplayStatics use causes long lag

Hello! Been tracking down a mystifying bug, and finally isolated it.

My game suffers from a long hang – 3-4 seconds on my machine – when the player first steps in water and spawns particles and sounds. After the first footstep, this hang doesn’t occur until the engine is re-started.

I at first thought this was a loading problem, but have since managed to preload the relevant assets and place them in the world.

After commenting out one line at a time, I managed to isolate the problem: the hang occurs the first time I use UGameplayStatics::SpawnEmitterAtLocation(...) or UGameplayStatics::SpawnSoundAtLocation(...). It doesn’t seem to particularly care what exactly particle or sound I’m spawning through it, the several second hang occurs whether that asset is loaded or not.

Is there some initialization or set-up I have to do to use UGameplayStatics properly? Has anyone else encountered this issue?

Edit: Upon further investigation, I only seem to get this hang when I’m calling UGameplayStatics from a physical material. I was able to spawn particles from the gamemode and not encounter the hang.

Here is the relevant code that causes the hang:

void UsbPhysicalMaterial::HandleImpact(EImpactStrength ImpactStrength, FVector Location, bool bPlaySound)
{
	UParticleSystem* ParticleAssetToSpawn = nullptr;
	USoundCue* SoundAssetToSpawn = nullptr;
	
	switch (ImpactStrength)
	{
	case EImpactStrength::Small:
		ParticleAssetToSpawn = AssetSmallImpactParticle;
		SoundAssetToSpawn = AssetSmallImpactSound;
		break;

	case EImpactStrength::Medium:
		ParticleAssetToSpawn = AssetMediumImpactParticle;
		SoundAssetToSpawn = AssetMediumImpactSound;
		break;

	case EImpactStrength::Large:
		ParticleAssetToSpawn = AssetLargeImpactParticle;
		SoundAssetToSpawn = AssetLargeImpactSound;
		break;
	}

	if (ParticleAssetToSpawn)
	{
		UGameplayStatics::SpawnEmitterAtLocation(this, ParticleAssetToSpawn, Location);
	}
	if (SoundAssetToSpawn && bPlaySound)
	{
		UGameplayStatics::SpawnSoundAtLocation(this, SoundAssetToSpawn, Location);
	}
}

I have my pawn do a line trace, cast to my physical material, and then run this HandleImpact(...) function. What’s so special about physical materials?