So I am following this tutorial: - YouTube
but I am doing more things in C++. I have a character class, a weapon class, and a projectile class.
I have successfully spawned my weapon without a problem: Screenshot - 94f2a7748b2852e1f244bc1c6fbc573c - Gyazo
but when I go to spawn my bullet by shooting my gun, the game crashes. It specifically crashes on this line:
ATutorialProjectile* SpawnActor = GetWorld()->SpawnActor<ATutorialProjectile>(MyProjectile, MyArrow->GetComponentLocation(), MyArrow->GetComponentRotation());
The blueprint is set up like this:
(.h)
class ATutorialProjectile; // forward declaration, this is above the UCLASS()
TSubclassOf<class ATutorialProjectile> MyProjectile;
(.cpp)
//in constructor
static ConstructorHelpers::FObjectFinder<UBlueprint> ProjectileBlueprint(TEXT("Blueprint'/Game/Blueprints/BP_Projectile.BP_Projectile'"));
if (ProjectileBlueprint.Object)
{
MyProjectile = (UClass*)ProjectileBlueprint.Object->GeneratedClass;
}
//in void Fire() function
if (MyProjectile != nullptr)
{
ATutorialProjectile* SpawnActor = GetWorld()->SpawnActor<ATutorialProjectile>(MyProjectile, MyArrow->GetComponentLocation(), MyArrow->GetComponentRotation());
}
I’ve already tested to see if it was maybe the MyArrow component that was crashing me, but it wasn’t. I replaced the FVector location and FRotator rotation with 0.0f, 0.0f, 0.0f just to see, and it still crashed. It’s 100% the MyProjectile object, but I don’t see what I’m doing wrong. I did the exact same thing for my Weapon in another class, and it works perfectly. I’ve also done this before without a problem. It’s almost like it just doesn’t like my blueprint for my projectile.
Is this some sort of bug? I used this method of spawning actors a ton of times before and not had problems. It’s like the engine selectively chooses when it wants to accept a blueprint.
ALSO, MyProjectile, my projectile blueprint, isn’t returning nullptr, so I honestly have no idea what is going on.