I’ve been stuck trying to create an old school weapon system like in Doom or Half-Life where you’re running around with 10+ weapons that you can switch between at any time. I would like some guidance on how I’m supposed to implement something like this. Please let me know where I’m wrong.
What I currently have is a C++ base class for my weapons that holds pretty much everything I need for the weapon like damage values and all that. All the different weapon classes are blueprint classes that derive from the base class. I’m having trouble figuring out how to access those weapons.
On the player class I have a TSubclassOf<BaseWeapon> variable for each weapon that I want, so that I can easily change the class if I want to, and as far as I know you can’t reference a blueprint class through code. I intend on using that class to get its damage and all the other stats. But since it’s a TSubclassOf<BaseWeapon> it could be any child class of that, so the code doesn’t know exactly what class it is and therefore cannot be used to call functions from it, right? And casting has so far just crashed the whole engine, although I’ve never used casting in actual code before, only blueprints, so I could be doing something wrong there. My cast looks like this:
ABaseWeapon* PistolCast = Cast<ABaseWeapon>(PistolClass);
(“PistolClass” is a TSubclassOf<ABaseWeapon> like I said)
I have a mesh component on the player that I intend to set to the model of the weapon class (I haven’t gotten here yet, though, due to to the problem above).
So, ultimately: Should I be using TSubclassOf<>?
I feel really dumb right now.