In the Shooter Game example, there are 2 weapons that the player starts with. Both classes (ShooterWeapon_Instant / ShooterWeapon_Projectile) are inheriting from ShooterWeapon. The thing that confuses me, is that in ShooterCharacter.cpp it only calls the SpawnActor method using DefaultInventoryClasses[i] as the class it spawns. When I use prints to debug, DefaultInventoryClasses is already initiated with both of the derived classes. Where is this happening? I don’t see anywhere that the DefaultInventoryClasses TArray is being populated by those variables.
–
ShooterCharacter.h
/** default inventory list */
UPROPERTY(EditDefaultsOnly, Category = Inventory)
TArray<TSubclassOf<class AShooterWeapon> > DefaultInventoryClasses;
ShooterCharacter.cpp
int32 NumWeaponClasses = DefaultInventoryClasses.Num();
for (int32 i = 0; i < NumWeaponClasses; i++)
{
if (DefaultInventoryClasses[i])
{
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AShooterWeapon* NewWeapon = GetWorld()->SpawnActor<AShooterWeapon>(DefaultInventoryClasses[i], SpawnInfo);
AddWeapon(NewWeapon);
}
}