How to call a function in a TsubclassOf
essentially what my current system is, is I have a manager that's supposed to manage primary, secondary and grenades. All this class is supposed to do be able to switch out weapons on the fly and call reload, fire, switch (between primary and secondary) I use the tsubclass so have a base weapon (which is a separate file), that contains actions like the reload and fire, so that the manager says "I want to fire this weapon" and the base weapon class has the firing logic.
Problem is I can't call the firing logic, it instead gives me the error message that "class UClass has no member Fire", but it has it.
asked Oct 24 '18 at 12:50 PM in C++ Programming
Just as the error says, UClass does not have a member function called
TSubclassOf<...> is a wrapper around a type to allow it to be passed around with both compile-time and runtime safety. As Ali Akbar and Shadowriver have said, if you want to call a method on your weapon then you are going to need some kind of instance to call the method on. The most common approach to doing this is to, as you stated in a comment, spawn the weapon in the world yourself and attach it to a bone on your character.
If you would like a good example of an existing system that has multiple weapons, you can take a look at the ShooterGame project that comes with the engine.
answered Oct 25 '18 at 04:26 PMDarkwindRichard (suspended)
Your PrimaryWeapon variable doesn't hold the reference to the weapon actor spawned in the world, but instead holds the class type
Change from this:
and save it like so:
Did you try to call
answered Oct 25 '18 at 12:25 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here