[HELP]Character Dont Move

Guys 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 tps character, so i search on google tps tutorial but i cant find, then find this tutorial A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums , its outdate, but i managed to do with help of Vawx, now i finish the tutorial and my character doesn’t move, i cant look around, he just play idle animation
My problem is with (Adding a mesh to your Character) code, where i need change my

DefaultPawnClass = AFPSCharacter::StaticClass();

to

// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT(


"Pawn'/Game/Blueprints/BP_FPSCharacter.BP_FPSCharacter_C'"

));
if (PlayerPawnObject.Class != NULL)
{
DefaultPawnClass = PlayerPawnObject.Class;
}

where is highlight i think is the problem
If you can help me, I would appreciate it.

Gamemode.cpp



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

#include "GMode.h"
#include "MyChar.h"
#include "UObject/ConstructorHelpers.h"

AGMode::AGMode(const FObjectInitializer& FObjectInitializer)
	: Super(FObjectInitializer)
{
	//set default pawnclass to our blueprinted character
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("Pawn'/Game/char/BP_Mychar.BP_Mychar_C'"));
	if (PlayerPawnObject.Class != NULL)
	{
		DefaultPawnClass = PlayerPawnObject.Class;
	}
}

void AGMode::BeginPlay()
{
	Super::BeginPlay();

	StartPlay();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Game Started"));
	}
};


GameMode.h



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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "GMode.generated.h"

/**
 * 
 */
UCLASS()
class CTEST_API AGMode : public AGameModeBase
{
	GENERATED_BODY()

	AGMode(const FObjectInitializer& FobjectiInitializer);

	virtual void BeginPlay() override;
};


MyChar.cpp



// 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/Camera/PlayerCameraManager.h"
#include "Runtime/Engine/Classes/Components/CapsuleComponent.h"
#include "Runtime/Engine/Classes/Components/SceneComponent.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "Runtime/Engine/Classes/GameFramework/Character.h"
#include "GameFramework/CharacterMovementComponent.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
AMyChar::AMyChar(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	//Create a Camera
	ThirdPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("ThirdPersonCamera"));
	ThirdPersonCameraComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, NAME_None);

	//Allow Pawn Control Rotation
	ThirdPersonCameraComponent->bUsePawnControlRotation = true;
}

// 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;
}


MyChar.h



#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Runtime/Engine/Classes/Camera/CameraComponent.h"
#include "Runtime/Engine/Classes/Components/SceneComponent.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "MyChar.generated.h"

UCLASS()
class CTEST_API AMyChar : public ACharacter
{
	GENERATED_BODY()


public:
	// Sets defau  values for this character's properties
	AMyChar();


protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	//Move foward/backward
	UFUNCTION()
	virtual void WS(float val);
	//Move strafe
	UFUNCTION()
	virtual void AD(float val);

	//Set Jump flag when key is pressed
	UFUNCTION()
	void OnStartJump();
	//Clear Jump flag when key is released
	UFUNCTION()
	void OnStopJump();

	//Third Person Camera
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
	UCameraComponent* ThirdPersonCameraComponent;

	//Contructor for AMyChar
	AMyChar(const FObjectInitializer& ObjectInitializer);

};




static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("/Game/Blueprints/BP_FPSCharacter"));
if (PlayerPawnObject.Succeeded( ))
{
    DefaultPawnClass = PlayerPawnObject.Class;
}


You’ll run into an issue if you use the entire asset path that is copied from the editor.

now my project is crashing :frowning:

With what error and what line?

i dont remember, i delete after trying open 3 times

There is always an answer that doesn’t require you to delete everything. If you post the error, there is a good chance somebody can help you figure it out.

Either way, hopefully you got everything working.

I just lost the character was not a big loss, Since I do not know coding, I could not do anything else.

Made the intire code again in this and now will crash again, there is my code before



AGMode::AGMode(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
	//set default pawn class to blueprint
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("'Pawn/Game/MyCharacter/MyCharacter.MyCharacter_C'"));
	if (PlayerPawnObject.Class != NULL)
	{
		DefaultPawnClass = PlayerPawnObject.Class;
	}
}


but my charact stil dont move so change to this



AGMode::AGMode(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
	//set default pawn class to blueprint
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("/Game/MyCharacter/MyCharacter.MyCharacter_C


"));
	if (PlayerPawnObject.Class != NULL)
	{
		DefaultPawnClass = PlayerPawnObject.Class;
	}
}


I highlighted my error and what I think was the reason for crashing
here is the result it crash again
log
LoginId:1d76938f4934fba7ff6b0188aeae0621
EpicAccountId:4b263d0465bb4a168f417587983cf7a4

You do not have any debugging symbols required to display the callstack for this crash.

Try:




#include "MyPawnClass.h" //Put the actual header for your Pawn class instead of "MyPawnClass.h"

AGMode::AGMode(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
	//set default pawn class to blueprint
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("/Game/MyCharacter/MyCharacter"));
	if (PlayerPawnObject.Class != NULL)
	{
		DefaultPawnClass = PlayerPawnObject.Class;
	}
}


Also, what version of the engine are you using? I ask because the FObjectInitializer hasnt been used in a long time, by default. If you happen to have GENERATED_UCLASS_BODY( ) in your AGameMode class, then its probably OK. I do not remember if GENERATED_BODY( ) is OK, though.

I am using 4.16.1, but the tutorial was for 4.15
i make again, now dont crashed but my character still dont move, my pawn have the same name of my c++ class have some problem?/

Gamemode.cpp



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

#include "GMode.h"
#include "MyCharacter.h"
#include "UObject/ConstructorHelpers.h"

AGMode::AGMode(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
	//Set Default class to Blueprint
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("/Game/MyCharacter/MyCharacter.MyCharacter_C"));
		if (PlayerPawnObject.Succeeded())
		{
			DefaultPawnClass = PlayerPawnObject.Class;
	}

}

void AGMode::StartPlay()
{
    Super::StartPlay();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 0.5f, FColor::Yellow, TEXT("Game Started"));
	}
}


Have you setup the input in the editor as well as in your character class?

https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial#WASD_Movement


"/Game/MyCharacter/MyCharacter.MyCharacter_C"

This is still incorrect. Change to:


"/Game/MyCharacter/MyCharacter"

I put together a sample project:

ExamplePlayer.uproject

Open the DevMap in the Content/Levels folder and you can play.

Yes i have, because i can move, jump, look around with this code:



AFPSGameMode::AFPSGameMode(const class FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	DefaultPawnClass = AFPSCharacter::StaticClass();
}


but with this



AGMode::AGMode(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
	//Set Default class to Blueprint
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("/Game/MyCharacter/MyCharacter.MyCharacter_C"));
		if (PlayerPawnObject.Succeeded())
		{
			DefaultPawnClass = PlayerPawnObject.Class;
	}

}


i tried with this and dont work too



"/Game/MyCharacter/MyCharacter"


how can i make this Uproject?/

Did you make the “MyCharacter” Blueprint class from your “MyCharacter” C++ class and put it in the “MyCharacter” folder in your Content folder?

No i didnt make from my c++, they are on diferent folders, c++ on default folder and bp in other

What I mean is, does your character Blueprint inherit from your character c++ class and is it in the “MyCharacter” folder?

Thanks for the help, i made like you said, i create based from my c++ now its working, i just cant look up and down but its working