Creating a touch button HUD.

Hi

I am trying to create a touch button for a mobile game HUD.
I am not sure if this is the best way to do or if I am doing it the correctly or now.

I am using c++ to do it.

First I created an actor having a box component and a static mesh component.

Then I use the delegate on the box component


UPROPERTY(BlueprintAssignable, Category="Input|Touch Input")
	FComponentOnInputTouchBeginSignature OnInputTouchBegin;

to detect touch.

To place this button on the camera location I use tick function and deproject from camera. Find the location and rotation of the camera and move the the actor to that location.

Is the best way to create touch HUD for mobile?

My another question is how can i know the location of touch on screen. If suppose I want to drag something on screen how do I do it?

----edit-----

I found something called hitbox in the HUD class. Can these be used to create click-able HUDs?


/**
	 * Add a hitbox to the hud
	 * @param Position			Coordinates of the top left of the hit box.
	 * @param Size				Size of the hit box.
	 * @param Name				Name of the hit box.
	 * @param bConsumesInput	Whether click processing should continue if this hit box is clicked.
	 * @param Priority			The priority of the box used for layering. Larger values are considered first.  Equal values are considered in the order they were added.
	 */
	UFUNCTION(BlueprintCallable, Category=HUD, meta=(InPriority="0"))
	void AddHitBox(FVector2D Position, FVector2D Size, FName Name, bool bConsumesInput, int32 Priority = 0);

Yes! These let you make click/touchable areas in the same way you draw boxes/text using a HUD Blueprint. In 4.1 they only supported mouse clicking, but in 4.2 they support touch interaction as well. Here is the change on GitHub:

https://github.com/EpicGames/UnrealEngine/commit/119473da77fbcc1e7deeaa9b960daa84e2eaec68

Ok… Thanks

Btw is it possible to create drag-able actors? Either in HUD or in world space. Like I can touch something in the HUD or a world actor and drag it. And it will drag where I touch on the screen.

There is a map in the Content Examples project called something like Mouse Interaction, which shows how to drag actors around with the mouse.

Ohk… I had not seen it yet. Is something like that currently possible to do with touch? Moving object by click them then dragging them with touch?

I can think of a method which involves creation of hitbox around a actor when you click it which detects where you move your finger on the touch. Although i am not sure if this method could work cause i have not used hitbox yet.