I created an equipment class that I’m trying to spawn in a character’s inventory. I setup the inventory via an inventory initialize function on the character:
//Initialize player equipment, check for first weapon, then set it as default current weapon
void ADefaultCharacter::InitializeEquipment()
{
UWorld* const World = GetWorld();
bool bFoundFirstWeapon = false;
AEquipment* NewEquipment;
if (World)
{
for (int i = 0; i < MaxEquipmentSlots; i++)
{
NewEquipment = GetWorld()->SpawnActor<AEquipment>(AEquipment::StaticClass());
EquipmentInventory[i]= NewEquipment;
checkf(EquipmentInventory[i], TEXT("FOUND AN INVENTORY ENTRY THAT POINTS TO NOTHING!"));
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, FString::FromInt(i));
//If this new item is a weapon, set the current weapon
if (!bFoundFirstWeapon)
{
print("Checking if the item is a weapon");
if (NewEquipment->IsWeapon())
{
print("Found a weapon");
bFoundFirstWeapon = true;
SetCurrentWeapon(NewEquipment);
}
}
}
}
if (!bFoundFirstWeapon)
{
print("First weapon wasn't found during initialization. Something's wrong.");
}
}
This compiles fine, supposedly fills the inventory array with something (not instances of equipment references?), but informs me that no current weapon is set. This is despite that fact that all equipment items currently just use default values, including the value that IsWeapon() returns (should be true), and therefore should set the current weapon after the first item is created. Even more perplexing, despite current weapon never being set, I can still call equipment functions, like CurrentWeapon->UseMainAttack(), successfully.
I’ve referenced the shooter project and looked at similar problems, but I just can’t figure it out. I’m still new to c++, but I assume I’m doing something wrong when I’m spawning the equipment actor…? A field I need to specify, perhaps?