I have a parent class of weapon, weapon has its chidreen that is rifle, sniper, pistol and sword(still not implemented , but each of those 4 will have it’s childreen so i can , in example, have 1 rifle class but an AK-47 and a M4A1 that inherits from those).
My point is: if one of those four is equipped(in player hand to be used) unequip it then equip the item you want.
The way i’m doing this is create a custom event on the weapon blueprint that check what item type of item is equipped(ou can only have 1 equipped) then unequip it.
On the item i want to equip i check if an item is already equipped, if not you just equip it, if some item is already equipped you call this custom event to de-equip the equipped item , and then you equip your item.
The way i’m doing it i need a cast to the rifleBP to get the item that is attached(on the custom event), same for the other types.
How i know how to do it is : get all actors of class -> for each loop> attach the array element on the cast object. It works “perfectly”, but with only one condition : there’s only one type of this item in the WHOLE level, otherse it’ll still work, but it’ll attach everything to you, even those you don’t have.
How can i get this cast to work to get only the item that the player have?
Also, if this way is harder or unpractictal, there would be a better way to doing it?