keywords: [UE4]Controller and Input Related

How to get Touch Position on screen
  1. New C++ class inherit from GameViewportClient

  2. Project Settings -> Engine -> General Settings -> Default Classes -> set Game Viewport Client Class as your customized class.

  3. Override function InputTouch

     virtual bool InputTouch(FViewport* Viewport, int32 ControllerId, 
     uint32 Handle, ETouchType::Type Type, const FVector2D& TouchLocation, 
     float Force, FDateTime DeviceTimestamp, uint32 TouchpadIndex) override;

    Argument TouchLocation is the Touch Position.

Mobile Input - Swipe and Pinch

A plugin for Unreal Engine 4 that exposes touches and swipes on mobile devices as events in blueprints

Ultimate Touch Components

Controller Rotation

By default, Controller Rotation is equal to PlayerStart Actor Rotation. So if you change the Rotation of PlayerStart Actor, Controller Rotation would be affected.

How to set the rotation of Controller:

void AController::SetControlRotation(const FRotator& NewRotation)
How to create and get Spectator

1st way

Create Spectator:

    DefaultPawnClass = ASpectatorPawn::StaticClass();

Get Spectator:

ASpectatorPawn* APlayerController::GetSpectatorPawn() const;

2nd way

How to prevent cursor from moving out of window when using dual monitors

Project Settings -> Engine -> Input -> Viewport Properties -> change Default Viewport Mouse Lock Mode to Lock Always.
Then when mouse clicked in viewport, cursor would be locked in viewport.


AddYawInput doesn’t work in Tick of PlayerController

It’s strange, maybe a issue of engine?

Execute AddControllerYawInput() in ACharacter::Tick() (inherited by AMyCharacter)