As title says, I coded a basic input but when i start a test play… just, my input is not received. Is important to metion that i am trying to use all functionalities from C++ - Unreal API, and I am using blueprints as less possible. Some body can help me?
My “Warrior” character defs:
AWarrior::AWarrior () {
// 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;
AutoPossessPlayer = EAutoReceiveInput::Player0;
FTransform transform;
mBaseMesh = CreateDefaultSubobject<UStaticMeshComponent> ( "BaseMesh" );
root_component = CreateDefaultSubobject<USceneComponent> ( "Root" );
camera = CreateDefaultSubobject<UCameraComponent> ( "Camera" );
const auto meshAsset = ConstructorHelpers::FObjectFinder<UStaticMesh> ( TEXT ( "StaticMesh'/Engine/BasicShapes/Cylinder.Cylinder'" ) );
if ( meshAsset.Object != nullptr ) {
mBaseMesh->SetStaticMesh ( meshAsset.Object );
mBaseMesh->AddLocalOffset ( FVector::ZeroVector );
mBaseMesh->AttachToComponent ( root_component, FAttachmentTransformRules ( EAttachmentRule::KeepWorld, false ), TEXT ( "BaseMesh" ) );
}
if ( camera != nullptr ) {
transform.SetLocation ( FVector ( -270.0f, 0.0f, 0.0f ) );
camera->AddLocalTransform ( transform );
camera->AttachToComponent ( root_component, FAttachmentTransformRules ( EAttachmentRule::KeepRelative, false ), TEXT ( "Camera" ) );
}
transform.SetLocation ( FVector::ZeroVector );
transform.SetScale3D ( FVector ( 2.0f ) );
GetCapsuleComponent ()->AddLocalTransform ( transform );
GetCapsuleComponent ()->AttachToComponent ( root_component, FAttachmentTransformRules ( EAttachmentRule::KeepRelative, false ), TEXT ( "CapsuleColider" ) );
RootComponent = root_component;
}
// Called when the game starts or when spawned
void AWarrior::BeginPlay () {
Super::BeginPlay ();
}
// Called every frame
void AWarrior::Tick ( float DeltaTime ) {
Super::Tick ( DeltaTime );
}
// Called to bind functionality to input
void AWarrior::SetupPlayerInputComponent ( UInputComponent* PlayerInputComponent ) {
Super::SetupPlayerInputComponent ( PlayerInputComponent );
check ( PlayerInputComponent );
PlayerInputComponent->BindAxis ( "Forward", this, &AWarrior::Forward );
PlayerInputComponent->BindAxis ( "Left", this, &AWarrior::Left );
PlayerInputComponent->BindAxis ( "Right", this, &AWarrior::Right );
PlayerInputComponent->BindAxis ( "Back", this, &AWarrior::Back );
}
void AWarrior::Forward ( float amount ) {
AddMovementInput ( GetActorLocation(), amount );
}
void AWarrior::Left ( float amount ) {
AddMovementInput ( -GetActorRightVector (), amount );
}
void AWarrior::Right ( float amount ) {
AddMovementInput ( GetActorRightVector (), amount );
}
void AWarrior::Back ( float amount ) {
AddMovementInput ( -GetActorForwardVector (), amount );
}
The Warrior Header
UCLASS()
class TEST_API AWarrior : public ACharacter {
GENERATED_BODY()
public:
// Sets default values for this character's properties
AWarrior ();
UPROPERTY () UStaticMeshComponent* mBaseMesh;
UPROPERTY () USceneComponent* root_component;
UPROPERTY () UCameraComponent* camera;
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;
void Forward ( float amount );
void Left ( float amount );
void Right ( float amount );
void Back ( float amount );
};
“TestGameMode” class defs
void ATestGameModeBase::BeginPlay () {
DefaultPawnClass = AWarrior::StaticClass ();
mPlayer = GetWorld ()->SpawnActor<AWarrior> ( FVector ( 50.0f, 50.0f, 200.0f ), FRotator ( 0, 0, 0 ), FActorSpawnParameters () );
mPlayer->EnableInput ( GetWorld ()->GetFirstPlayerController () );
}
Header for “TestGameMode”
UCLASS()
class TEST_API ATestGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
UPROPERTY() AWarrior* mPlayer;
};
Key bindings:
Nothing weird advices or warnings in unreal’s editor log
And correct call for TestGameMode with correct Warrior character spawn
Thanks for your time!