I have added a custom character class to my simple test project.
The aim right now is to understand how the ACharacter class works.
So what I have tried to do is to just copy the ACharacter class content 1:1 into my MySimpleCharacter class
I then assigned my character class as the default pawn in the gamemode class constructor. I have added a couple of debug messages in the MySimpleCharacter constructor to see if it was being used.
in the Editor I have created a custom MySimpleCharacter_BP and made it derive off MySimpleCharacter. So far so good.
I setup all my animTree BP, skeleton and idlerun blend tree. (I basically followed the official Epic tutorial video about creating custom characters via the Editor).
I then drag an instance of MySimpleCharacter_BP into the level and Launch the game.
The problem I have now is that the character instance which I placed in mid air , stays in mid air → it doesnt fall down and the player character has no control whatsoever.
I thought maybe I did something wrong , so I re-created another MySimpleCharacter_BP but this time deriving it off ACharacter to see if all my data is setup correctly. Doing this , makes my instanced NPC fall down to the ground and I gain control over my character as a player.
So my question is: Is there some magic involved with ACharacter that isn’t obvious from the code ?
I mean there seems to be two problems here.
the physics for MySimpleCharacter doesn’t seem to work (NPC not falling down to the ground)
I have no player control
I think my data is otherwise setup correctly, in fact if I just substitute MySimpleCharacter with a regular AACharacter then it all works fine. But codewise the two characters are identical. Am I missing something ?
just make this clear I am able to have AMyCharacter derived from ACharacter and it works perfectly.
BUT if I try to make AMyCharacter just derive off APawn then it compiles but nothing works even though I copy exactly the code from AACharacter.
Just for clarity sake AMyCharacter is exactly the same as ACharacter. (It is not what my final code would look like its just something I am doing to understand how ACharacter works and because eventually I want to implement my own character class.).
Would be great if someone could tell me if there is some ACharacter “Magic” that isn’t obvious in code that I might be missing.
Yes I did add my custom controller to the custom game mode.
As I stated above I have everything running fine as long as I implement my AMyCharacter class derived from ACharacter.
But for various reasons I am trying to reverse engeneer the original ACharacter class to see how it works. So what I did is basically a copy & paste of the entire content of the ACharacter class into AMyCharacter class.
that does compile (with the exception of two build errors that I can’t explain - I comment out those 2 lines that give an error) and it launches fine. The character just doesn’t have any physics and no player control.
So I suspect there must be something else like a hidden Blueprint or other class that makes the ACharacter actually work. In the class comments it says the class is heavily dependent on the movementcomponent but I copy the constructor of the ACharacter as well as the rest of its implementation.
I hesitate posting the code of AMyCharacter here because it is a direct copy & paste of the original ACharacter class and this being a somewhat public forum I think it would violate the terms and conditions of Epic,
I am looking at the CharacterMovementComponent code and it is Referncing ACharacter as its owner. So I think this could be the culprit of my problams here, I am basically using it for AMyCharacter but AMyCharacter isnta ACharacter so the movement component almost certainly doesn’t work as it should. I will probably need to write my own.
“But for various reasons I am trying to reverse engeneer the original ACharacter class to see how it works. So what I did is basically a copy & paste of the entire content of the ACharacter class into AMyCharacter class.”
this is beyond my scope of assisting you if you are going in that deep
you do realize that when Epic makes improvements to ACharacter or required changes you wont know and could get in a big mess right ?
I am not changing the original ACharacter class merely copying it for the purpose of understanding it. I want to strip everything I don’t need from it and see what is left and then add what I need. I think I got a bit closer yesterday, I will keep trying today.
Alright, so I just wanted to update here with what I ended up doing.
I had to abandon my plans of creating my own CharacterBase derived purely from AActor. The reason is somewhat bad as in bad design imho. The engine code assumes that the player is always having an APawn as its base and worse it assumes that the player controller is of type PlayerController which internally uses APawn too. I would have liked to see a more generic interface than that from Epic. I wanted to share code between classes by creating base classes i.e. something like AMyEntity which then allows me to be a base class to AMyCharacter , AMyVehicle AMyHorse, etc.
as it seems right now all my stuff needs to be at least a Pawn.
further as I have very special networking needs I really would love to see a way to get rid of all the network related code on an #ifdef USING_UNREAL_NETWORKING like this I could ust remove a ton of code. I understand why they haven’t got one but to be honest I was hoping that the game_layer of unreal was a bit more generic than it is.
I have now gone back to implement UINTERFACEs , not ideal but its the unreal way AFAIK so I try to conform to it.
I hope this helps other people getting some ideas about what problems you could encounter trying to avoid using APawn as your base class.