Announcement

Collapse
No announcement yet.

Cannot check if a certain key is down

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Cannot check if a certain key is down

    Code:
    float result = InputComponent->GetAxisKeyValue(EKeys::A);
    if ( result){		
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("This is an on screen message!"));
    }
    I have that in my Tick function. The tick function actually gets called, but apparently there is something wrong with the above code. I tried other keys, but still nothing.

    #2
    An input component itself does nothing unless it is enabled and added to the player input 'stack'.
    This gets processed by the player input class, which itself is called from the player controller.

    Check out: https://docs.unrealengine.com/latest...put/index.html

    So the question is, which tick function?
    Actor? Pawn? PlayerController? Other?

    For example, detecting the key input from a Pawn, you could do:
    Code:
    if (APlayerController* PC = Cast<APlayerController>(Controller))
    {
        if (PC->InputKeyDown(EKeys::A))
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("This is an on screen message!"));
        }
    }
    Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

    Comment


      #3
      I have the UInputComponent I receive at the SetupPlayerInputComponent override for my class which inherits from ACharacter.
      That being so, the Tick function is from an Actor, since Character inherits from it.

      Comment


        #4
        Actor => Pawn => Character => YourCharacter?

        Code:
        void AYourCharacter::Tick()
        {
            ...
        As long as your actor/pawn/character has a controller that is also a player controller, using the PC->InputKeyDown() should work.
        If not, nada.
        Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

        Comment


          #5
          well thats the class hierarchy right there....

          Comment


            #6
            Without seeing the code in context, I'm unsure what is going on
            Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

            Comment


              #7
              Did the answer to your question on the answer HUB not resolve this?

              https://answers.unrealengine.com/que...is-updown.html

              Comment

              Working...
              X