Announcement
Collapse
No announcement yet.
APawn input not working
Collapse
X
-
Daveoh repliedThe problem was that I had a UMG widget displayed. When I stopped adding it to the viewport on launch, everything started working again. Does anyone know how to use UMG and also use keyboard input?
-
Daveoh repliedYes. When I press keys nothing happens, but I have a GUI which I made with UMG which is working fine.
Leave a comment:
-
TheSpaceMan repliedAfter you pressed play, have you clicked in the "play" window to make sure it gets focus, otherwise it won't recieve any input.
Leave a comment:
-
Daveoh repliedYes, I have the following, which I assigned in the editor:
Code:+ActionMappings=(ActionName="Space",Key=SpaceBar,bShift=False,bCtrl=False,bAlt=False,bCmd=False) +ActionMappings=(ActionName="Quit",Key=Escape,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
Leave a comment:
-
Dune repliedMight be a stupid question, but have you setup your input in the editor or config file. DefaultInput.ini should contain some lines which resemble something like:
+ActionMappings=(ActionName="Space",Key=Space,bShift=False,bCtrl=False,bAlt=False)
+ActionMappings=(ActionName="Quit",Key=Q,bShift=False,bCtrl=False,bAlt=False)
or you could use the GetOwner->WasInputKeyJustPressed(EKeys::Space) check.
Leave a comment:
-
Daveoh started a topic APawn input not workingAPawn input not working
Hi, I'm having trouble receiving any input on my pawn. If someone could point out what might be wrong then it would be highly appreciated. Here is my source for my pawn, which has been specified as the DefaultPawnClass in my GameMode:
.h
Code:#pragma once #include "GameFramework/Pawn.h" #include "ConstructionPlayerController.h" #include "ConstructionPawn.generated.h" /** * */ UCLASS() class ROBOTS_API AConstructionPawn : public APawn { GENERATED_UCLASS_BODY() public: virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override; void OnBeginCameraRotation(); void OnEndCameraRotation(); void Quit(); /** Camera */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera) TSubobjectPtr<class UCameraComponent> MyCameraComponent; /** Camera boom positioning the camera */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera) TSubobjectPtr<class USpringArmComponent> CameraBoom; AConstructionPlayerController* PC; };
Code:#include "Robots.h" #include "ConstructionPawn.h" #include "ConstructionPlayerController.h" AConstructionPawn::AConstructionPawn(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { // Create a camera boom... CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom")); CameraBoom->AttachTo(RootComponent); CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does CameraBoom->TargetArmLength = 512.f; CameraBoom->RelativeRotation = FRotator(-45.f, 0.f, 0.f); CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with // Create a camera... MyCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("MyCamera")); MyCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName); MyCameraComponent->bUseControllerViewRotation = false; // Camera does not rotate relative to arm } void AConstructionPawn::SetupPlayerInputComponent(UInputComponent* InputComponent) { UE_LOG(LogTemp, Warning, TEXT("AConstructionPawn entered SetupPlayerInputComponent()")); check(InputComponent); InputComponent->BindAction("Space", IE_Pressed, this, &AConstructionPawn::OnBeginCameraRotation); InputComponent->BindAction("Space", IE_Released, this, &AConstructionPawn::OnEndCameraRotation); InputComponent->BindAction("Quit", IE_Pressed, this, &AConstructionPawn::Quit); if (GetOwner() && Cast<AConstructionPlayerController>(GetOwner())) { PC = Cast<AConstructionPlayerController>(GetOwner()); } EnableInput(PC); } void AConstructionPawn::OnBeginCameraRotation() { PC->SetMouseCursor(EMouseCursor::GrabHand); } void AConstructionPawn::OnEndCameraRotation() { PC->SetMouseCursorToDefault(); } void AConstructionPawn::Quit() { GetWorld()->Exec(GetWorld(), TEXT("exit")); }
Leave a comment: