Custom Character Movement Component

Evening all. Fairly new to unreal programming.
I’m working on a game using Tom Loomans survival game as a reference. But I have a problem implementing a custom character movement component.

This is the error I get.

1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: Pilot, Configuration: Development_Editor x64 ------
2>  Performing 2 actions (4 in parallel)
2>  PilotBaseCharacter.cpp
2>X:\Dev\Unreal Projects\4.11\Pilot Code Project\Source\Pilot\Private\Player\PilotBaseCharacter.cpp(11): error C2065: 'UPilotCharacterMovementComponent': undeclared identifier
2>X:\Dev\Unreal Projects\4.11\Pilot Code Project\Source\Pilot\Private\Player\PilotBaseCharacter.cpp(11): error C2974: 'FObjectInitializer::SetDefaultSubobjectClass': invalid template argument for 'T', type expected
2>  s:\epic games\4.11\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(848): note: see declaration of 'FObjectInitializer::SetDefaultSubobjectClass'
2>  s:\epic games\4.11\engine\source\runtime\coreuobject\public\uobject\UObjectGlobals.h(837): note: see declaration of 'FObjectInitializer::SetDefaultSubobjectClass'
2>  -------- End Detailed Actions Stats -----------------------------------------------------------
2>ERROR : UBT error : Failed to produce item: X:\Dev\Unreal Projects\4.11\Pilot Code Project\Binaries\Win64\UE4Editor-Pilot.pdb
2>  Total build time: 3.86 seconds
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3073: The command ""S:\Epic Games\4.11\Engine\Build\BatchFiles\Build.bat" PilotEditor Win64 Development "X:\Dev\Unreal Projects\4.11\Pilot Code Project\Pilot.uproject" -waitmutex" exited with code -1.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And this is the line its complaining about.

APilotBaseCharacter::APilotBaseCharacter(const class FObjectInitializer& ObjectInitializer)
/* Override the movement class from the base class to our own to support multiple speeds (eg. sprinting) */
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UPilotCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))

But i literally have no idea how to resolve the issue.

Any help is greatly appreciated!

Thanks all.

EDITED: Fixed the copy and paste with code tags.

As far as I can tell, I have done it exactly the same as Tom Looman has done it in his Survival Game.
I just can’t see what I’m missing.

Thanks again all!

Unless AnswerHub formatting messed up your copy paste, you’re forgetting to pass the actual class of your custom component in the SetDefaultSubobjectClass call. Its passed as a template argument, try:

    Super(ObjectInitializer.SetDefaultSubobjectClass<UPilotCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))

This won’t make a difference, the value of that variable is statically defined in ACharacter, nor should you pass a different value because it is the name that ACharacter will use to retrieve the subobject clasd for.

:slight_smile: Thats exactly the same as what I pasted.
Thanks for the help!

Yeah I realised and updated my original post. Thanks!

Answerhub deletes the pointy < brackets, so he thought you were missing them and it deleted his too. I’ll report this to epic because it shouldn’t do that and it’s causing confusion.

Then he needs to post the actual code because there’s only one line and it’s not causing the issue

You need to post your code. A couple of lines isn’t sufficient.

Undeclared identifier suggests you haven’t included the header for your custom character movement component

I thought I spotted the issue until answerhub removed my <> too.:slight_smile:

Seems the compiler doesn’t recognize the type UPilotCharacterMovementComponent. Did you include its header file?

Where would I need to include it.

In the movementComp header. The includes are
#include “GameFramework/CharacterMovementComponent.h”
#include “PilotCharacterMovementComponent.generated.h”

Then in the movement comp .cpp the includes are.
#include “Pilot.h”
#include “PilotCharacterMovementComponent.h”
#include “PilotBaseCharacter.h”

BaseCharacter header
#include “GameFramework/Character.h”
#include “PilotBaseCharacter.generated.h”

BaseCharacter.cpp
#include “Pilot.h”
#include “PilotBaseCharacter.h”
#include “PilotGameMode.h”

Infact, my includes are all the same as his.

Thanks again all!

In your PilotBaseCharacter.cpp you would have to have

#include "PilotCharacterMovementComponent.h"

That isn’t included in Tom Loomans BaseCharacter class though. Only in the Character class, which inherits from BaseCharacter.

PilotBaseCharacter.h
http://

PilotBaseCharacter.cpp
http://

Have you tried my suggestion? The compiler needs to know what UPilotCharacterMovementComponent in your PilotBaseCharacter.cpp. If you don’t include its header file in the .cpp file itself nor in any header files it does include, the compiler won’t know the UPilotCharacterMovementComponent type.

I see Tom Looman’s source indeed doesn’t have this include, but perhaps his project uses different settings. For example, you can tell UE’s compiler to merge all source files before compiling. If this setting is enabled, even if your includes aren’t all correctly set up in the individual .cpp they may be correct when all source files are merged before compilation. If this is enabled in Tom Looman’s project but not in yours, that could explain why his compiles without the include and yours doesn’t.

Yeah, putting that include in should solve it. Either putting it in PilotBaseCharacter.h or .cpp will do it.

I have indeed :slight_smile:

This is the output.

http://pastebin.com/kjMUUTQ6

Looks like I have some other problem. Something I’m missing.

Any idea where and what sort of project settings he may have changed?

Thanks again!

The new output shows that your original issue is resolved. For the future, read up on #include since its required knowledge for C++!

Your new output shows two issues:

  • You haven’t implemented APilotBaseCharacter::GetLifetimeReplicatedProps. Any actor that is replicated must have this function, its function header is automatically generated but its body is not, because through its implementation you have control over how often a replicated variable is sent from server to client. Check out this other question and the posted answer: link text

  • It seems you’ve declared a SetSprinting function in your PilotCharacter.h header file but not implemented it yet in PilotCharacter.cpp.

I know about includes, it was just that it wasnt included in the survival game example, so I didn’t think it was needed. I’m still interested to see how its done differently in the Survival Game. The class is only included in the character class, not the base character class.

Ahh yeah, Indeed I had missed the SetSprinting out. Well spotted thank you.

As for the replication. I have been leaving out any replicated functions/variables due to only making a single player game.

So that is my next issue. I can’t see where I need to alter things for the GetLifetimeReplicatedProps.

Thanks again!

Ah okay. :slight_smile: Since you’re making a single player game, simply don’t declare any replicated variables and UE wont require a GetLifetimeReplicatedProps function.