How, or can an ACharacter class be extended to be used in Unreal Engine character objects

After previous times trying out and using Unreal Engine to hack around to test if some ideas and concepts I want to implement in a 3D environment, I am now ready and wanting to get serious and create something tangible and productive in Unreal Engine using C++.

The first thing I want to do is to extend and expand the existing ACharacter class so I can use this extended ACharacter class in the character object that the UE editor creates. I thought this should not be too difficult as all I needed to do would be to create a new class within a blank C++ file created by UE which inherits the ACharacter class as

class myUEprojectname_API ACharacter_extension : public ACharacter
{
       GENERATED_BODY()
Public:
        ACharacter_extension();
        ~ACharacter_extension();
}

add my own code and then modify the character generated .h file UE creates using the class wizard from

"#include "GameFramework/Character.h"

UCLASS(config = Game)
class myUEprojectname_API Amy_Character : public ACharacter

to

"#include "Character_extension.h"

UCLASS(config = Game)
class myUEprojectname_API Amy_Character : public ACharacter_extension

and changing references of ACharacter in the my_Character.generated and my_Character.gen files to ACharacter_extension.

In my naivity and ignorance of what UE does and how it works when creating a character using the class wizard, and what is involved in compiling a UE project, this failed.

I have spent a lot of time scouring the documentation, the internet, and google and have found scant and confusing information, and certainly no examples on if what I want to do can be possible, and if it can, how it can be done.

If it can be done, I suspect it it may be a line of code added to one of the .cs files that instructs the editor to substitute the GameFramework/Character.h and .cpp file with a specified pathname.

Is there anyone out there that can help indicate to me if using an extended ACharacter class can be substituted for the default ACharacter class the class wizard uses or can manually be assigned? If so how or where I can find the information on how to do so. I would much appreciate any help.

Thanks in advance.

Let me get this straight. Am I correct into assuming that you want the editor to use your character class when you select create blueprint and then select the character from the common classes list?

If so, that seems like a major waste of time. Just create a new blueprint and select your character class from all classes, below the common classes window. Sure, it takes a few seconds more, but I reckon you will waste those seconds anyway trying to reconfigure the common classes.

I have come up with the solution to what I wanted to achieve.

As usual, it is simple and I am kicking myself for not considering it from the start. I was too distracted in my thinking and was not considering an alternative method.

All that was needed was to use polymorphism to access the ACharacter class functions and variables in the UE generated Character class and add additional code as follows.

In the extended ACharacter_extension class add a pointer variable of type ACharacter

class myUEprojectname_API ACharacter_extension
{
Public:
ACharacter *character;

     ACharacter_extension();
     ~ACharacter_extension();

}

In the Amy_Character class generated by the UE editor class wizard, add a variable of type ACharacter_extension

class myUEprojectname_API Amy_Character : public ACharacter
{
Public:
ACharacter_extension Character_extension;

and in the constructor of Amy_Character have the assignment

Character_extension.character = this;

now the ACharacter_extension class can access all the ACharacter variables and funtions etc. of the Amy_Character class by simply referring to them as character->varaible_name, character->function_name etc.

In the Amy_Character class, to call these functions, use the expression

Character_extension.Function_Name;

It may not be the best way to do this but it works and gets the result I want which is not to have to have unnecessary functions and variables passing parameters and reassigning values in the Amy_Character class generated by UE. I have more to test using this technique as it was in the last hour of the day yesterday that I came up with this, but it looks to be promising and the way to go.

Thanks for the suggestion.

I have done it this way in the past when I was hacking around in UE and found it to be cumberson and having to write a lot of what I considered to be unnessary code which made tracking it more tedious. However I think I have found a solution get the result I want which is to directly access the functions and variables of ACharacter class so as to add additional code to as explained above.

Looks like the editor did not format my added comment above correctly in the code snippets. hope it is is eligible to read and understand.

Not sure this is readable, but this reply editor just doesn’t seem to be working that well in formatting.

I have come up with the solution to what I wanted to achieve.

As usual, it is simple and I am kicking myself for not considering it from the start. I was too distracted in my thinking and was not considering an alternative method.

All that was needed was to use polymorphism to access the ACharacter class functions and variables in the UE generated Character class and add additional code as follows.

In the extended ACharacter_extension class add a pointer variable of type ACharacter

class myUEprojectname_API ACharacter_extension
 {
 Public:
         ACharacter *character;

         ACharacter_extension();
         ~ACharacter_extension();
 }

In the Amy_Character class generated by the UE editor class wizard, add a variable of type ACharacter_extension

class myUEprojectname_API Amy_Character : public ACharacter
{
Public:
      ACharacter_extension Character_extension;

and in the constructor of Amy_Character have the assignment

Character_extension.character = this

;

now the ACharacter_extension class can access all the ACharacter variables and funtions etc. of the Amy_Character class by simply referring to them as

character->varaible_name, character->function_name etc.

In the Amy_Character class, to call these functions, use the expression

Character_extension.Function_Name;

It may not be the best way to do this but it works and gets the result I want which is not to have to have unnecessary functions and variables passing parameters and reassigning values in the Amy_Character class generated by UE. I have more to test using this technique as it was in the last hour of the day yesterday that I came up with this, but it looks to be promising and the way to go.