Crash when spawning actors in 20 player net game

Getting this crash when spawning actors in a 20 player network game test.
This code runs many times per mininute in the game, so does not fail every time, and has never crashed when testing networked in the editor.
Due to the way the build is being made, it’s hard to debug any of these lines that are in the engine code, only 2 of the lines i the below stack are in the code written for the game.

TSet<class UObjectBase *,struct DefaultKeyFuncs<class UObjectBase *,0>,class FDefaultSetAllocator>::FindId(class UObjectBase *)	C++
TSet<class UObjectBase *,struct DefaultKeyFuncs<class UObjectBase *,0>,class FDefaultSetAllocator>::Emplace<class UObjectBase * const &>(class UObjectBase * const &,bool *)	C++
HashObject(class UObjectBase *)	C++
UObjectBase::AddObject(class FName,enum EInternalObjectFlags)	C++
StaticAllocateObject(class UClass *,class UObject *,class FName,enum EObjectFlags,enum EInternalObjectFlags,bool,bool *)	C++
StaticConstructObject_Internal(class UClass *,class UObject *,class FName,enum EObjectFlags,enum EInternalObjectFlags,class UObject *,bool,struct FObjectInstancingGraph *,bool)	C++
UWorld::SpawnActor(class UClass *,struct FTransform const *,struct FActorSpawnParameters const &)	C++
ARangedWeapon::BeginPlay() Line 52	C++
ARangedWeaponProjectile::BeginPlay() Line 34	C++
AActor::DispatchBeginPlay(void)	C++
AActor::PostNetInit(void)	C++
UActorChannel::ProcessBunch(class FInBunch &)	C++
UActorChannel::ReceivedBunch(class FInBunch &)	C++
UChannel::ReceivedNextBunch(class FInBunch &,bool &)	C++
UChannel::ReceivedRawBunch(class FInBunch &,bool &)	C++
UNetConnection::ReceivedPacket(struct FBitReader &)	C++
UNetConnection::ReceivedRawPacket(void *,int)	C++
UIpNetDriver::TickDispatch(float)	C++
TBaseUObjectMethodDelegateInstance<0,class UNetDriver,void >::ExecuteIfSafe(float)	C++
TBaseMulticastDelegate<void,float>::Broadcast(float)	C++
UWorld::Tick(enum ELevelTick,float)	C++
UGameEngine::Tick(float,bool)	C++
FEngineLoop::Tick(void)	C++
GuardedMain(wchar_t const *,struct HINSTANCE__ *,struct HINSTANCE__ *,int)	C++
GuardedMainWrapper(wchar_t const *,struct HINSTANCE__ *,struct HINSTANCE__ *,int)	C++
WinMain()	C++

The code in question was this…

.h

/** the weapon sound fx to use when the weapon is fired. This is the blueprint that responds to weapon events to play the sounds. */
UPROPERTY( EditDefaultsOnly, Category = Sound )
TSubclassOf<AWeaponSoundFX> WeaponSoundFX_Template;

.cpp

void ARangedWeapon::BeginPlay()
{
	Super::BeginPlay();

	if ( WeaponSoundFX_Template != nullptr && GetNetMode() != NM_DedicatedServer )
	{		
		FTransform SpawnTransform = FTransform::Identity;
		WeaponSoundFX = GetWorld()->SpawnActor<AWeaponSoundFX>(	WeaponSoundFX_Template, SpawnTransform );
	}
}

So the only things i can see is…

GetWorld() - so this can return null? is this supposed to be checked, if so, there are places in the engine itself where this is never checked. It seems it can be null when the world is shutting down or when the object is being destroyed, but i verified from the crash dump that neither of these situations were happening.

The issue is WeaponSoundFX_Template and not GetWorld, you need to dereference TSubClassOf to get the UClass it may or may not have.

 void ARangedWeapon::BeginPlay()
 {
     Super::BeginPlay();
 
     if ( *WeaponSoundFX_Template != nullptr && GetNetMode() != NM_DedicatedServer )
     {        
         FTransform SpawnTransform = FTransform::Identity;
         WeaponSoundFX = GetWorld()->SpawnActor<AWeaponSoundFX>(    *WeaponSoundFX_Template, SpawnTransform );
     }
 }

Thanks for the answer, but without changing any code and stepping through this code in the editor shows that the dereference is implicitly happening anyway…

[Inline Frame] UE4Editor-.dll!TSubclassOf<AWeaponSoundFX>::operator*() Line 55	C++
[Inline Frame] UE4Editor-.dll!TSubclassOf<AWeaponSoundFX>::operator class UClass *() Line 77	C++
UE4Editor-.dll!ARangedWeapon::BeginPlay() Line 50	C++
UE4Editor-Engine.dll!AActor::DispatchBeginPlay() Line 3343	C++

Which is good, as if you need to dereference this to use it and it silently compiles without any errors or warnings, that would be really bad.

Right, but is that If check doing the implicit conversion? Otherwise you may be dereferencing it and passing in a nullptr as the UClass.