Hey guys, so I have a question. I am currently trying to implement a combat system between the A.I. and the player that I have created. My A.I. class is a child class of the Character c++ base class. However, I have kind of messed up, and instead of also making a child class for the player, I have essentially just been using the parent class for the player. This is a pretty large project by this point, and I do not want to try and chase down everything and change them all to a new child class for the player. So, here is my issue:
I am creating collision boxes for the A.I. and the player, but obviously since they are not the same meshes, the collision box needs to be in different places for each. I have already created the one for the A.I. class since it’s a child without issues. But now I need to make one for the player, but since it is the parent class, will it not also add it to the A.I. class since it is a child?
If this is the case, how can I go about creating a collision box for the player in the parent class w.o it also being added to the A.I. child class? If I am understanding virtual and override correctly, could I simply create the collision box and all of the functionality into a virtual function in the parent class, and then create an override w.o any implementation in the child class?
Did you not create a blueprint for the Player Character? The best I can gather from your description is that you placed a lot of functionality in the base C++ class. You can just derive another class and reparent your Player Character BP to that and put your collision in the derived C++ class if setting stuff up in C++ is your worry. If you’re setting up collision in BP or in editor, you shouldn’t have to do anything with your classes.
If you mentioned what your COMPLETE class hierarchy was up to ACharacter for both Player and AI and if each one is C++ or BP, we could better help you.
But you need to confirm what you have. There’s also class redirects you can set in one of your ini files to redirect to a base class for your player character. There are lots of options available but need more details.
I know that setting up a new child class and reparenting the bp player would work, but as I said in the question, this is a large project where many things are working off each other, and I do not want to have to chase down every single thing that works with the base character class + the bp player and change them all to the new child class as that not only would take a lot of time, but could create problems if I miss something. I also do not want to add a collision box through the editor because I mainly work in c++ and this will make things confusing when coding the combat system as well as just eligibility purposes.
I gave the other stuff for context, but my question is with virtual/override. If I have a parent class that I want to add functionality too without also affecting the child classes, can I do it by declaring a function virtual in the parent class, and then overriding the function I do not want the child classes to use in the child classes.
I told you UE supports class redirects. So you can avoid those issues you mention. You have lots of options. But we still don’t know your exact class hierarchy to see if this is viable.
As for the override, you could potentially do it. In the base class, have your Player setup in a virtual method. In the AI derived class, just implement it as usual WITHOUT calling the base class method. This is usually bad practice, but I think it would do what you want.
I think you’re saying you’ve already set some stuff up in the AI class. So you want to only set it up for the player. Then yeah, the AI implementation would just be empty. BTW, it would have taken two minutes to try it.
So you’re saying UE can essentially redirect everything in a project that uses a specific parent to a new child class of your choosing without having to manually redirect each individual thing? Do you know of any resources that explain how this works since your mentioned you have to mess with the ini files, I would prefer to do some reading so I don’t mess things up.
This was needed when I renamed a C++ class. Since you can’t open Blueprints if it can’t find its base class, you’re kind of screwed. This lets you redirect it to the new class and then if you save the file, you don’t need this redirect anymore (as long as you saved ALL the blueprints that use the old class).
Most BP classes are in the form of
/Script/MyProject/MyFolder/MyClass_C
In your case, it’s a little more problematic. You have the AI class using the same class as the Player. So something has to be changed. I can’t see anyone using a player character without a blueprint. So you could reparent the BP and nothing has to change. Just start adding Player specific stuff into the Player derived class. No need to change what you already have. And spawning is done with the BP class, not the C++ class. I think it’s doable, but without knowing the details, it’s unclear if this is even remotely close to how you’re doing things. In the event you need to rename a class, you can update all your BP with the redirects mentioned above, etc. Like I said, lots of options, but unclear what you have.
Ty for your help. And yes your had the correct hiearchy that you mentioned above. Thats why I was running into the problems was because I was basically using the parent of the A.I. class for the player. And I do have a bp for for the player, but I was thinking by creating a derived and changing the bp parent, if anything else in the project that is linked to the BP and the origional parent, it would cause it to no longer work/updated with any new code I add to the derived class. So if this happens, now I can just redirect said classes/bps to the new derived class.