InventorySlot array is declared as:
TArray<class AInventory*> InventorySlot;
I have tried: TArray<class AWeapon*> Weapon = Cast <AWeapon*>(InventorySlot) but it says arguments don’t match.
What am I doing wrong?
InventorySlot array is declared as:
TArray<class AInventory*> InventorySlot;
I have tried: TArray<class AWeapon*> Weapon = Cast <AWeapon*>(InventorySlot) but it says arguments don’t match.
What am I doing wrong?
I assume AInventory is the base class for AWeapon?
In any event, you won’t be able to cast that way. The language doesn’t support it because it is unsafe. What if, for instance, you had an inventory item that is not a weapon?
Instead, if you want to iterate over weapons in your inventory array, you should iterate normally and cast each individual element:
for( AInventory* InventoryItem : InventorySlot )
{
AWeapon* InventoryWeapon = Cast<AWeapon>( InventoryItem );
if( InventoryWeapon != nullptr )
{
// do weaponey stuff here
}
}