I am making a FPS survival horror game and I had a question on how should I continue my item/inventory system:
I have a table row FItemData(FTableRowBase) that contains some properties for each item: mesh, icon and some text inventory data(name, interaction text, …).
Then for creating the item I have a UItemBase that extends UObject that is initialized from the one row of the table with the same data.
I have a APickup actor that is created in the world with a reference to the table row and on initialization creates a ItemBase that is what is passed to the inventory if pickup.
My question is: What are some correct ways to give each item its functionality, I mean in the inventory?
Like if i have a gun i should have a static mesh saved somewhere. Or add the functionality of a flashlight.
An item can have reference to an actor class which can be used to spawn the actor in game. But be sure to not use the class directly.
Use what is called a soft class reference. It will not impact memory but will require you to load the asset by hand before the spawn via "Async Load Class Asset”.
If you want to call a function on an item, like a heal spell on a vial or something then try this
Thank you for the response. Another part that I cannot figure Is how I can still have the system still dynamic, I mean I have a weapon class maybe but at the end every weapon is the same the various variable change, like shooting distance, projectile shot, maganize, animations, etc… How can I store that data dynamically?
I was thinking of two ways:
I save the data to a different table like WeaponData but then I will find myself bloating the table with data for the other items. I mean if I add a WeaponData and then a MagicItemData, ConsumableData each row will have a lot of not usable stuff. Because here is never going to be a weapon that is a consumable for example.
The other is I have a Enum and a Instanced Struct.
The Enum is used to check which type of struct will be in the instanced struct.
I don’t know, let me know what do you think, or if you have any other idea. Thanks
You would need to add tarray / array of structs => attributes that could modify the base item.
This could then be saved in your inventory through an itemStruct that could have an ID that directs it to the base class in the datatable and has the attribute modifier array. Then you would need a function to calculate the items final output based on the allotted attributes adding naming suffixes / prefixes etc, changing art.
So in the final game in your save file / or sql database you would only save the id and serialized attributes as well as stuff like current durability and special cases etc.