"SpawnActor failed because no class was specified"

"SpawnActor failed because no class was specified"
Hello, I have this problem since last lecture. Fixed it with blueprint. But now when I try add this in Projectile.cpp

ProjectileMovement->SetVelocityInLocalSpace(FVector::ForwardVector * Speed);
ProjectileMovement->Activate();

editor crash.

I tried to fix this class error, even copied files from course, and nothing work.

did you attach header file in Tank.cpp? #include “Projectile_C.h”

I had the same problem! When we changed the all the scripts to EditDefaultsOnly from EditAnywhere it changed some of the blueprints. Make sure the Projectile BP in tank is filled in. Just in case check the other blueprint filled members as well.

good luck

2 Likes

This is how I did it.

// Spawn a projectile at the socket location of the barrel
auto SocketLocation = Barrel->GetSocketLocation(FName("Projectile"));
auto SocketRotation = Barrel->GetSocketRotation(FName("Projectile"));
FActorSpawnParameters SpawnInfo;

GetWorld()->SpawnActor<AProjectile>(ProjectileBlueprint, SocketLocation, SocketRotation, SpawnInfo);

You need to #include the Projectile.h header file and the TankBarrel.h header file into Tank.cpp

And make sure you add the Projectile_BP in the Projectile Blueprint option we created in Tank_BP under Setup. Like this…
ProjectileBlueprint

Scratch that, you don’t need FActorSpawnParameters

// Spawn a projectile at the socket location of the barrel
auto SocketLocation = Barrel->GetSocketLocation(FName("Projectile"));
auto SocketRotation = Barrel->GetSocketRotation(FName("Projectile"));

GetWorld()->SpawnActor<AProjectile>(ProjectileBlueprint, SocketLocation, SocketRotation);
1 Like

You my good friend are an absolute STAR!

This quote was brought to you be “A disabled gamer and hopefully a future agent of the one and only El-Magic!”

You snippet of code worked wonders, if I ever need advice, I’ll be your agent any day!!!

Most kindly yours
Brandon

1 Like

Privacy & Terms