I am currently starting work on an inventory system for my game.
There will be two primary weapon slots within the inventory.
The actor blueprints that are stored within this slot will change depending on the weapon stored.
I’m not quite sure on the best way to handle this. Should I just make the inventory slot variable of type actor and then cast to the specific blueprint type when I need to manipulate it?
I currently have a master blueprint for my weapons and will be copying an editing this for various different weapons going forwards.
You may create a base class , for example “item” class, with all the functionalities for inventory system, pick up , market etc…
This will be the mother class of all your items, they will inherit those functionalities , you’ll have to create specific children classes from this class and add extra functionalities inside the derived class…
For example :
Weapons with attack behaviour
Armour with defense
Food with healing features
Child classes of your base item class should have all the same variables and functions as the base class does. Furthermore, you can use blueprint interfaces when you want different classes that are not inherited to have the same function definition(s). Even furthermore, you can use Event Dispatchers to broadcast an event firing to anything that has registered to listen to it.
So there are at least three ways you can approach making a large number of different BP classes know how to handle being manipulated in the inventory, without having to duplicate and vary the code across every single one of them, and without needing a bunch of Cast nodes.