Touch input event in c++ like blueprint

Hi,
I created a c++ class from actor. I want to make touch event like TouchInput node in Blueprint that wherever of screen touched it’s triggered … How I can do this?
Thanks

Hello Vahid,

The best way to see an example of this would be to create a C++ project based off a template that involves a character (such as Third Person Character) and look at the .cpp for the character in that project. There is a touch event setup in Third Person Character that causes the character to jump when the screen is pressed.

Hope this helps!

I know that but that inputs are from. APawn and I trying to do something similar but not working…

What types of issues are you running into? You’ll have to be more detailed for me to understand what is wrong so that I may be able to provide some advice.

problem is function for setup player input didn’t calland InputComponent hasn’t any value…

how i can Initialize

URPOPERTY()
class UInputComponent* InputComponent;

this variable defined in Actor class and accessible in my custom class.

and I have a function like ue4 templates for binding inputs but i don’t know where i need to call this ? I think i need to call at begin play right?

void SetupPlayerInputComponent(class UInputComponent* InputComponent);

SetupPlayerInputComponent is automatically called for you. All you need to do is set up the inputs inside of it to call the correct functions. I made a quick example with a C++ class based off of APawn and it seems to work fine. Here is the code: http:///QG1NwJhQ

Thanks for your example, I didn’t have problem about defining functions or binding to touch inputs, as I said before my class is inherited from actor not pawn, so SetupInputComponent didn’t call on that and also InputComponent hasn’t any value…

Ah, I didn’t see that you were using an actor. You can find more information here about setting up input for an actor here: Check Keyboard Events in code - Programming & Scripting - Epic Developer Community Forums
This particularly for keyboard keys but it should be able to help you.

Thanks for your help Mathew.
I solve the problem and i copy codes here for other people. but maybe somebody can do it in better way specially register actor on PlayerController to receive inputs from player controller.

in MyActor.h

    virtual void BeginPlay() override;
    
    void FunctionToCall();

in MyActor.cpp

    #include"MyPlayerController.h"
    
    void AMyActor::BeginPlay()
    {
          Super::BeginPlay()
    
         AMyPlayerController* PC = Cast<AMyPlayerController>(GetWorld()->GetFirstLocalPlayer());
         if(PC)
         {
             PC->RegisterMyActor(this);
         }
    }

    void AMyActor::FunctionToCall()
{
\\Something happened here
}

in MyPlayerController.h

        #include"MyActor.h"
    
        AMyActor* RegMyActor
    
        virtual void SetupInputComponent() override;
        void Touched(ETouchIndex::Type, FingerIndex, FVector Location);
        void RegisterMyActor(AMyActor* actor);
    
    in MyPlayerController.cpp
    
    void AMyPlayerController::SetupInputComponent()
    {
          Super::SetupInputComponent();
    
          check(InputComponent);
          InputComponent->BindTouch(IE_Pressed, this, &AMyplayerController::Touched);
    }
    
    void AMyPlayerController::Touched(ETouchIndex::Type, FingerIndex, FVector Location)
    {
         if(RegMyActor)
         RegMyActor->FunctionToCall();
    
    }
    void AMyPlayerController::RegisterMyActor(AMyActor* actor)
    {
         RegMyActor = actor;
    }

322103-cap3.png