Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Get character to use custom character movement component

Hello! I've fiddled around for quite a while with blueprints and I'm trying to make a transition over to C++. My learning project involves a character with a couple unique movement options like a double-jump and an air-dash, so I figured I'd create a class that inherits from the character movement component.

Now that I've successfully made my custom character movement component, I am attempting to get my character to use it. I first tried:

 CharacterMovement = CreateDefaultSubobject<USTCharacterMovementComponent>(ACharacter::CharacterMovementComponentName);

within my character, but turns out CharacterMovement cannot be accessed, because it is private. What is the correct way to instruct my custom character to use my custom charactermovementcomponent in c++?

I'm pretty new to C++ specifically, so sorry for any obvious oversights. Thank you!

Product Version: UE 4.11
more ▼

asked May 02 '16 at 09:31 PM in C++ Programming

avatar image

43 5 10 11

avatar image zimzimdz May 02 '16 at 09:42 PM

Can you paste the exact error ?

avatar image OhNoLab May 02 '16 at 09:45 PM


 error C2248: 'ACharacter::CharacterMovement': cannot access private member declared in class 'ACharacter'

Fairly certain this is because CharacterMovement was declared privately. I am just wondering what the 'proper' way to change the CharacterMovementComponent to a different component that inherits from CharacterMovementComponent is.

avatar image zimzimdz May 02 '16 at 09:58 PM

You're right CharacterMovement is set to private. You will not be able to override it unless you modify the Character source code, which I guess, is not something you want to do. Instead you should find another spot to put your custom movement logic, like why not in your derived character class directly ? Otherwise you can attach your custom component to your character without specifically overriding CharacterMovement. I am curious about how complex is your code you placed in your custom component ? I mean, what is the exact reason you need to derive and override the CharacterMovement ?

avatar image OhNoLab May 02 '16 at 10:07 PM

The custom movement code I have is very simple. To be honest, I just thought that was the 'correct' way to go about things, to put custom movement code in a module that handles it. There's no reason I need to derive it at all, I suppose! I'll simply put it in character from here on out, I suppose!

avatar image zimzimdz May 02 '16 at 10:23 PM

Yeah I totally agree with your reasonning. But if things are setup this way Epic guys must have a good reason too (there is a comment since 4.6 that deprecates the direct access to CharacterMovement) Anyway, i am a bit useless here as I don't see any other solution than writing your movement logic in the character itself or handling it in a standard inherited ActorComponent attached to your character. Keep me in touch if you find some more answers.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You can override Character Movement Component in the constructor. Instead of use default empty constructor, replace:



 AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UMyMovementComponent>(ACharacter::CharacterMovementComponentName))

Although it is for an older engine version, the Rama wiki it's a usefull resource:


more ▼

answered Jul 31 '17 at 02:49 PM

avatar image

46 1 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question