Hi,
What I am trying to do is to just move a box up and down. To do so, I just added some action bindings to that character. However, the keys do not respond. Actually, after I debugged that project, I saw that it also does not get in the method called ‘SetupPlayerInputComponent’. What is the problem?
What I do is basically create a blueprint of the class ‘playercloud’ and put it into the scene. When I hit play and push the buttons ‘Up’ and ‘Down’, nothing happens.
Note: I have setup the key actions for ‘up’ and ‘down’ keys, of course
Cloud.h
#pragma once
#include "GameFramework/Character.h"
#include "Cloud.generated.h"
/**
*
*/
UCLASS()
class THECLOUDGAME_API ACloud : public ACharacter
{
GENERATED_UCLASS_BODY()
const float VOLUME_SIZE_MIN = 0.2f;
const float VOLUME_SIZE_MAX = 2.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlyingObjects)
float ChargeLevel;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlyingObjects)
float CurrentVolume;
};
Cloud.cpp
#include "TheCloudGame.h"
#include "Cloud.h"
ACloud::ACloud(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
ChargeLevel = 0.0f;
CurrentVolume = ACloud::VOLUME_SIZE_MIN;
}
PlayerCloud.h
#pragma once
#include "Cloud.h"
#include "PlayerCloud.generated.h"
/**
*
*/
UCLASS()
class THECLOUDGAME_API APlayerCloud : public ACloud
{
GENERATED_UCLASS_BODY()
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
void MoveUp(void);
void MoveDown(void);
};
PlayerCloud.cpp
#include "TheCloudGame.h"
#include "PlayerCloud.h"
APlayerCloud::APlayerCloud(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void APlayerCloud::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
check(InputComponent);
InputComponent->BindAction("MoveUp", IE_Pressed, this, &APlayerCloud::MoveUp);
InputComponent->BindAction("MoveDown", IE_Pressed, this, &APlayerCloud::MoveDown);
}
void APlayerCloud::MoveUp()
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("MoveUp!"));
}
void APlayerCloud::MoveDown()
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("MoveDown!"));
}