Hi, i want to build a inventory system like rust, i have a question, i need a array to store all items? but if i have different type of items like weapons, eat, drink. What type of array i need if i have a differents classes for Weapon is SSWeapon, for eat and drink is SSConsumable.
And if i have five player item slots how i can know if a item is SSWeapon class or SSConsumable to spawn or do other things depends of type of item.
You could create a base class for inventory items that holds all relevant information, such as an image to be shown, a description text etc. There you could also determine what to do based on what kind of item you have currently equiped.
Either you create a base class that SSWeapon and SSConsumable extend from or you create a class, e.g. SSItem, that holds all relevant information. There you could also store what type of item it is, just as you said. However, this is only one way to do it.
I’d probably create a base class for both that has a pure virtual method like “OnUse” (in C++, I don’t know if there is something like that in Blueprints, I only use them for small tasks). That way your inventory doesn’t even need to know what kind of item it is, you can just call Item->OnUse() and the overriden method from your child class will get called.
I don’t know if you already did so but googling “Ue4 inventory system” will also bring up some nice tutorials.
I want to do a RPG Inventory System in ShooterGame, to store weapons and items in the same inventory, and 6 inventory slots to use with 1, 2 ,3, 4, 5, 6 keyboard numeric keys. If in 2 slot have a weapon when press [2] key in keyboard check what type of item i have in the 2 slot and if is weapon call to function to spawn.
But the ShooterGame have a Weapon Base class and Instant and Proyectile derived weapon class. if i add a new class to Items. Whats type of array i need to store items and weapons?
How i can build inventory? and what classes i need to structure?
Think about the items in the inventory different than the actual Actors in Game or things that give abilities. They are items, they aren’t the actual Actor with Code and Art that are used in the Game. So, an Item class should be fine and you have an Array of Items. You can give your Item class a property which tells what type of Item it is. Then the PlayerController code that uses an item can match it up with what is supposed to happen, such as equipping a weapon, dropping an object in the world, etc. which will probably spawn the needed Actor based on properties in the Item class.