Can't spawn actor of class

I have a function spawning projectiles to shoot, but they came out as NULL , what am I doing wrong?

FTransform SpawnTM(ShootDir.Rotation(), Origin);
	TSubclassOf<class AProjectile> projectileClass;
	AProjectile* Projectile = Cast<AProjectile>(UGameplayStatics::BeginDeferredActorSpawnFromClass(this, projectileClass, SpawnTM));
	
	if (Projectile)
	{
		Projectile->Instigator = Instigator;
		Projectile->SetOwner(this);
		Projectile->InitVelocity(ShootDir);

		UGameplayStatics::FinishSpawningActor(Projectile, SpawnTM);
		
	}

To spawn an actor, you’ll need to use the SpawnActor function, from the UWorld class. Instead of using FinishSpawningActor, first make a location for the projectile to be spawned, a rotation, a FActorSpawnParameters variable, and a variable to store the class to spawn. Heres an example.

FVector SpawnLocation = FVector(0, 0, 0);
FRotator SpawnRotation = FRotator(0, 0, 0);
FActorSpawnParameters SpawnParams;
SpawnParams.Other = this;
SapwnParams.Instigator = Instigator;
GetWorld()->SpawnActor<AProjectile>(ProjectileToSpawn, SpawnLocation, SpawnRotation, SpawnParams)

ProjectileToSpawn can be declared/initialized elsewhere, such as the following line to make it editable in the editor.

UPROPERTY(EditAnywhere, Category = "Projectile")
 TSubclassOf<class AProjectile> ProjectileToSpawn;

You got a NULL because in Line 2, you declare your variable (TSubclassOf< class AProjectile> projectileClass;) but you do not give any value to that variable, like:

	TSubclassOf<class AProjectile> projectileClass = ASpecificProjectile::StaticClass();

Where ASpecificProjectile is one of your projectile class.

However, in your case, aside from the class of projectile to be spawned, you do not seem to need any specific parameter to be set before spawning (like a mesh, a color, damage parameter or whatever).

If you only want to select the class of projectile to be spawned, then is right and you should use the SpawnActor method instead: GetWorld()->SpawnActor(ASpecificProjectile::StaticClass(), …)

Bests,