I was wondering how to change your characters movement speed in C++. from what I found they just stated all you need is CharacterMovement->MaxWalkSpeed, but the complier is saying it is private member and can’t be accessed.
From CharacterMovementComponent.h …
You can see that MaxWalkSpeed is defined as “public”.
I think what’s going on here is the fact that the CharacterMovement member of the ACharacter class is in fact defined as private…
This implies that you cannot modify it (or it’s contents) inside of a child class. Notice they have the “AllowPrivateAccess” meta property set which is what allows you to change the members of the component within blueprint.
In short, I think what that means is that if you’re sub-classing ACharacter within C++ then you will not be able to modify this component within C++…you will instead need to sub-class ACharacter in C++ then sub-class your C++ sub-class in BP…make sense?
my Character is a subclass of ACharacter created inside unreal by right clicking and choosing character as parent class, and my blueprint is a child of my Character from C++.
Unless I am understanding you wrong, what you explained is exactly how I have it setup, my character is called SurvivalCharacter which is derived from ACharacter, and I have a BP_SurvivalCharacter for blueprint interaction.
For some reason, every reply is super complicated, the simpler version here.
inside your character’s .cpp file, go to the constructor and insert:
GetCharacterMovement()->MaxWalkSpeed = 300.f; // replace 300 with your desired speed
don’t forget to #include "GameFramework/CharacterMovementComponent.h"
inside your .h file before the last include.
I was so focused on the compiler error that I never thought to look further. Thanks for calling out the simplicity.
@shotty46290, @LegendaryDonkey5 is correct (and a “legend” ). There is of course a “getter” for the privately declared component so you can do exactly what you’re trying to do.
As for what I was suggesting, you do have it setup correctly but what I was getting at was that you would change the movement speed within the BP sub-class. Which of course will work but does not answer your question properly which was how to change it in c++.
sorry for the late reply, thank you for this, I saw multiple “previews” to setting walk speed without the () so I was not thinking about that.