[HELP]Script Character Movement Errors

Guy i need Help, I’m used to do thing with bp, but I decided to try to learn c ++ so I started with the basics in ue4 that was to make a character walk, so i search on google and find this tutorial
A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums, I made it to the moving part, where it started to go wrong, i stater have problems with c2027, c2227 and another one with character.h even with out using, i will copy and paste the log and scripts
LOG:
Info Compiling game modules for hot reload
Info Performing 3 actions (2 in parallel)
Info MyChar.cpp
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\MyChar.cpp(51) : error C2027: use of undefined type ‘UCharacterMovementComponent’
Error C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\Engine\Classes\GameFramework/Character.h(24) : note: see declaration of ‘UCharacterMovementComponent’
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\MyChar.cpp(51) : error C2227: left of ‘->IsMovingOnGround’ must point to class/struct/union/generic type
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\MyChar.cpp(51) : error C2227: left of ‘->IsFalling’ must point to class/struct/union/generic type
Info ERROR: UBT ERROR: Failed to produce item: C:\Users\guilh\Desktop\Unreal Projects\CTest\Binaries\Win64\UE4Editor-CTest-916.dll
Info Total build time: 3,05 seconds (Local executor: 0,00 seconds)

MyChar.CPP
1 // Fill out your copyright notice in the Description page of Project Settings.
2
3 #include “MyChar.h”
4
5
6 // Sets default values
7 AMyChar::AMyChar()
8 {
9 // Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
10 PrimaryActorTick.bCanEverTick = true;
11
12 }
13
14 // Called when the game starts or when spawned
15 void AMyChar::BeginPlay()
16 {
17 Super::BeginPlay();
18
19
20 if (GEngine)
21 {
22 GEngine->AddOnScreenDebugMessage(-2, 5.f, FColor::Yellow, TEXT(“My Character”));
23 }
24 }
25
26 // Called every frame
27 void AMyChar::Tick(float DeltaTime)
28 {
29 Super::Tick(DeltaTime);
30
31 }
32
33 // Called to bind functionality to input
34 void AMyChar::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
35 {
36 Super::SetupPlayerInputComponent(PlayerInputComponent);
37
38 //set up gameplay key bindings
39 InputComponent->BindAxis(“WS”, this, &AMyChar::WS);
40 InputComponent->BindAxis(“AD”, this, &AMyChar::AD);
41
42}
43
44 void AMyChar::WS(float Value)
45 {
46 if ((Controller != NULL) && (Value != 0.0f))
47 {
48 // find out which way is forward
49 FRotator Rotation = Controller->GetControlRotation();
50 // Limit pitch when walking or falling
51 if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling())
52 {
53 Rotation.Pitch = 0.0f;
54 }
55 // add movement in that direction
56 const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
57 AddMovementInput(Direction, Value);
58 }
59 }
60
70 void AMyChar::AD(float Value)
71 {
72 if ((Controller != NULL) && (Value != 0.0f))
73 {
74 // find out which way is right
75 const FRotator Rotation = Controller->GetControlRotation();
76 const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
77 // add movement in that direction
78 AddMovementInput(Direction, Value);
79 }
80 }

If need the rest of the scripts tell me

Add to the .cpp file:



#include "GameFramework/CharacterMovementComponent.h"


You are trying to access the Character Movement Component of type, UCharacterMovementComponent but it’s not included, which is why it complains about the undefined type.

God bless you, thanks for the help.
So it’s not my fault
Because in the tutorial did not say to add this command
Is this because it may be out of date?

Yeah, it’s a recent change. The tutorial is probably from 4.14 or 4.15.

another error
Info Compiling game modules for hot reload
Info Performing 3 actions (2 in parallel)
Info GMode.cpp
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\GMode.cpp(10) : error C2653: ‘ConstructorHelpers’: is not a class or namespace name
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\GMode.cpp(10) : error C2612: trailing ‘type’ illegal in base/member initializer list
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\GMode.cpp(27) : fatal error C1004: unexpected end-of-file found
Info ERROR: UBT ERROR: Failed to produce item: C:\Users\guilh\Desktop\Unreal Projects\CTest\Binaries\Win64\UE4Editor-CTest-486.dll
Info Total build time: 2,91 seconds (Local executor: 0,00 seconds)

1// Fill out your copyright notice in the Description page of Project Settings.
2
3 #include “GMode.h”
4 #include “MyChar.h”
5
6 AGMode::AGMode(const FObjectInitializer& FObjectInitializer)
7 : Super(FObjectInitializer)
8
9 //set default pawnclass to our blueprinted character
10 static ConstructorHelpers::FClassFinder<APawn>PlayerPawnObject(TEXT(“Pawn’/Game/Blueprints/Mychar.BP_Mychar’”));
11 if (PlayerPawnObject.Class != NULL)
12 {
13 DefaultPawnClass = PlayerPawnObject.Class;
14 }
15
16 void AGMode::BeginPlay()
17 {
18 Super::BeginPlay();
19
20 StartPlay();
21
22 if (GEngine)
23 {
24 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT(“Game Started”));
25 }
26 }



#include "UObject/ConstructorHelpers.h"


You can always search what is missing here: https://docs.unrealengine.com/latest/INT/index.html

Then at the bottom of the page is what header to include.

OMG why is it so annoying to program
I’m stopped for 1 or 2 days, because I can not fix the code
I entered the site that you indicated to me, it worked a part, but now I have this error
Error C:\Users\guilh\Desktop\Unreal Projects\CTest\Source\CTest\MyChar.cpp(25) : error C2660: ‘USceneComponent::AttachToComponent’: function does not take 0 arguments


// Fill out your copyright notice in the Description page of Project Settings.

#include "MyChar.h"
#include "Runtime/Engine/Classes/Camera/CameraComponent.h"
#include "Runtime/Engine/Classes/Components/CapsuleComponent.h"
#include "Runtime/Engine/Classes/Components/SceneComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Engine.h"


// Sets default values
AMyChar::AMyChar()
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

//Create Camera Component
20 AMyChar::AMyChar(const FObjectInitializer& ObjectInitializer)
21	: Super(ObjectInitializer)
22 {
23	//Create a Camera
24	ThirdPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT(''ThirdPersonCamera''));
25	ThirdPersonCameraComponent->AttachToComponent(this->GetCapsuleComponent());
26 }

// Called when the game starts or when spawned
void AMyChar::BeginPlay()
{
	Super::BeginPlay();
	

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-2, 5.f, FColor::Yellow, TEXT("My Character"));
	}
}

// Called every frame
void AMyChar::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyChar::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	//setup gameplay key bindings
	InputComponent->BindAxis("WS", this, &AMyChar::WS);
	InputComponent->BindAxis("AD", this, &AMyChar::AD);

	//setup gameplay mouse axis
	InputComponent->BindAxis("Look Horiz", this, &AMyChar::AddControllerYawInput);
	InputComponent->BindAxis("Look Ver", this, &AMyChar::AddControllerPitchInput);

	//setup gameplay Jump key
	InputComponent->BindAction("Jump", IE_Pressed, this, &AMyChar::OnStartJump);
	InputComponent->BindAction("Jump", IE_Released, this, &AMyChar::OnStopJump);
}

void AMyChar::WS(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		// find out which way is forward
		FRotator Rotation = Controller->GetControlRotation();
		// Limit pitch when walking or falling
		if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling())
		{
			Rotation.Pitch = 0.0f;
		}
		// add movement in that direction
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
		AddMovementInput(Direction, Value);
	}
}

void AMyChar::AD(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		// find out which way is right
		const FRotator Rotation = Controller->GetControlRotation();
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
		// add movement in that direction
		AddMovementInput(Direction, Value);
	}
}

void AMyChar::OnStartJump()
{
	bPressedJump = true;
}
void AMyChar::OnStopJump()
{
	bPressedJump = false;
}






ThirdPersonCameraComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, NAME_None);



https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/USceneComponent/AttachToComponent/index.html