ProjectileClass is NULL - First Person Template

Hi all,

I’ve run into a bit of a weird issue. While expanding on the functionality of the c++ first person starter project, at a certain point I built the project, and the ProjectileClass declared in the ProjectCharater.h file was suddenly null at runtime.
After reverting the code added since the previous functional build, the issue still persisted.

The declaration hasn’t changed:

UPROPERTY(EditDefaultsOnly, Category = Projectile)
	TSubclassOf<class ABlink_ArenaProjectile> ProjectileClass;

Checking the class at runtime confirms its null value, printing ‘No projectile class’ :

void ABlink_ArenaCharacter::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

	if (ProjectileClass)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Has projectile class"));
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No projectile class"));
	}
	...
}

By altering the UPROPERTY to:

UPROPERTY(EditAnywhere, Category = Projectile)

and setting the ProjectileClass in the editor, it isn’t null anymore, but crashes on this SetRelativeScale3D call in ABlink_ArenaProjectile.cpp:

UParticleSystemComponent* Explosion = UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionParticles, GetActorTransform(), true);
	Explosion->SetRelativeScale3D(FVector(4.f));

The crash report:

Access violation - code c0000005 (first/second chance not available)
UE4Editor_Blink_Arena!ABlink_ArenaProjectile::OnDetonate() [d:\documents\unreal projects\blink_arena\source\blink_arena\blink_arenaprojectile.cpp:75]
UE4Editor_Blink_Arena!ABlink_ArenaProjectile::OnHit() [d:\documents\unreal projects\blink_arena\source\blink_arena\blink_arenaprojectile.cpp:54]
UE4Editor_Blink_Arena!ABlink_ArenaProjectile::execOnHit()
UE4Editor_CoreUObject

Removing that line stops any errors, but the projectile mesh and particle system don’t render. It functions as if the projectile has fired (destroys specific types of actors as it has been designed to, with expected travel-time delays, physics etc.)

So in summation: I’m confused.

Tried cleaning and rebuilding the project, stripping out most of the code I’ve added to the classes etc.

Has anyone else come across anything like this?

You need to set a default class for your projectile class don’t be empty, you can do this in constructor or in editor itself. You don’t need to use set world scale, there is an overload of SpawnEmitterAtLocation which accepts scale as parameter:

SpawnEmitterAtLocation
(
    const UObject * WorldContextObj...,
    UParticleSystem * EmitterTempla...,
    FVector Location,
    FRotator Rotation,
    FVector Scale,
    bool bAutoDestroy
)