What do you try to accomplish ?
From what can I deduce here, you are trying to create inventory, which will store weapons. And then you assign key for each weapon on keyboard.
If that is the case, I have simple solution for you.
First create Inventory for your weapons, for example in you character class:
TArray WeaponInventory;
How do add weapon to the inventory, is whole another matter, not relevant the issue at hand.
Create input functions like:
void WeaponSlotOne()
void WeaponSlotTwo()
etc.
And properties:
Weapon* WeaponObjectOne
Weapon* WeaponObjectTwo
etc.
Now sample implmentation of these functions would be:
WeaponSlotOne()
{
APlayerController* PC = Cast(Controller);
if(PC)
{
ActionButtonOneObj->EquipWeapon();
}
}
Where EquipWeapon is function inside weapon class that set the weapon active.
You can assign WeaponObject like this:
void ACharacter::SetWeaponToActionBar()
{
if(Inventory.Num() > 0)
{
for(AWeapon* weapon : Inventory)
{
if(weapon)
{
//we don't want to override already assigned object. So if it is null we pass
//it's very bad way of doing this. I think.
if(!WeaponObjectOne)
{
WeaponObjectOne = power;
}
else if (!WeaponObjectTwo)
{
WeaponObjectTwo = power;
}
}
}
}
}
It leave some place for randomness as you can’t predict order in which weapons will be stored in array.
To prevent that you can define enum in weapon, which will contain weapon types, and then instead of if, use switch, to assign weapon from array to the slot you want.
In blueprint you specify enum type for your class. And that class will be passed back to the code.