So I’m a little confused at this one. I have two blueprints I’m trying to spawn, both written the same way, one works ,the other crashes. And I checked, they both exist!
Basically, I have a debugging setup inside the Editor to spawn various inventory setups as if they were “classes” you find in standad games. Assault class, Sniper class, etc. Using Blueprints. Inside the World Settings, I have a class that I can set my Blueprint to as the current spawning class for PIE play
UPROPERTY(EditAnywhere, BlueprintReadWrite, CATEGORY = "Testing & Debugging")
TSubclassOf<class AROTSoldierInfo> EditorSoldier;
and inside the Pawn class during my LoadCharacter() function, I spawn that Blueprint like so:
AROTWorldSettings* World = Cast<AROTWorldSettings>(GetWorldSettings());
SoldierInfo = GetWorld()->SpawnActor<AROTSoldierInfo>(World->EditorSoldier);
Works fine, and it it all shows up in the logs. INSIDE my SoldierInfo, I have another variable set for weapons (which are also blueprinted from a single class).
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Inventory)
TSubclassOf<class AROTWeapon> PrimaryWeap;
So I blueprinted this SoldierInfo, and set the Primary Weapon to my blueprinted Weapon. And then I try to spawn it with the SAME write up as I did for the actual SoldierInfo and it causes an instant crash, with no-outputs of why. Logs are empty of any crash details. I don’t understand!
Primary = GetWorld()->SpawnActor<AROTWeapon>(SoldierInfo->PrimaryWeap);
And full code so you can see
void AROTPlayerSoldier::LoadCharacter()
{
UE_LOG(SoldierLog, All, TEXT("===AROTPlayerSoldier::LoadCharacter==="));
UE_LOG(SoldierLog, All, TEXT("Loading Character...."))
AROTWorldSettings* World = Cast<AROTWorldSettings>(GetWorldSettings());
SoldierInfo = GetWorld()->SpawnActor<AROTSoldierInfo>(World->EditorSoldier);
if (!SoldierInfo)
{
UE_LOG(SoldierLog, Warning, TEXT("No Soldier Info!!!!!"))
return;
}
UE_LOG(SoldierLog, All, TEXT("Loading Inventory..."));
if (SoldierInfo->PrimaryWeap)
{
UE_LOG(SoldierLog, All, TEXT("SoldierInfo's Primary = '%s'"), *SoldierInfo->PrimaryWeap->GetName());
Primary = GetWorld()->SpawnActor<AROTWeapon>(SoldierInfo->PrimaryWeap); //Logs display the name of the Primary Weapon, then crash on the spawn!
}
else
{
UE_LOG(SoldierLog, All, TEXT("No Primary Weapon Found"));
}
//UE_LOG(SoldierLog, Log, SoldierInfo);
}