I’ll begin by saying I have little experience using Unreal/C++ and I come from Unity/C#. Because of that I haven’t grasped many of Unreal’s quirks or C++ in Unreal for that matter.
I want to make a weapon database. Weapons have different weapon types, and each weapon type has some core variables that every gun should have, but also, some added variables on top (Added variables depend on the type so each type has a different set of variables).
I want this data to be stored and be easily accessible.
On BeginPlay, I would like to access that data and instantiate a copy of a weapon (using an ID or name) on the player for him to use.
What I have done:
I have a class “WeaponBase” which extends “AActor” (Which is not a good idea since the mais purpose is to store data) and contains variables that every weapon should have (Name, Damage, Range, …).
Then I have several subclasses which extend “WeaponBase” and add more variables on top of it. They also override the firing methods but that logic can easily be relocated elsewhere so that’s not a problem.
But now I don’t know what to do with these classes, which brings me to another point.
Something that I still haven’t gotten used to, or perhaps, haven’t understood yet, is that constructors in Unreal don’t take parameters because of the UObject system. So I haven’t found a way to create weapons within the code.
Then I thought that If I don’t need methods, I could easily turn this class into a struct. Plus, I read that there’s struct inheritance in C++ which would be great in this case, but unfortunately, UStructs don’t have it.
I also researched the combined use of Structs and DataTables, but then I couldn’t store the different types of weapons on the same table. And if I made a table for each weapon type, I’m not sure if I can create a variable on my character to house any possible weapon, ence the use of the “BaseWeapon”.
If in this post I assumed anything that is incorrect about either Unreal or C++ don’t hesitate to correct me.
If I failed to explain any aspect sufficiently please say so.
Also, sorry for the long read.
Thanks in advance!
If it helps to better understand what I want to accomplish, here’s an example I actually got working while I was still using Unity. The way I would go about this would be to create “BaseWeapon” as a Scriptable Object Class, create some Scriptable Object Classes that extend “BaseWeapon” (one for each weapon type). Then I would create as many weapons as I wanted in the editor using those subclasses and add them to an “BaseWeapon” Array. Finally I would have a variable of type “BaseWeapon” in the player character to store the weapon the player currently holds.