Text field with blueprints

Hello,

Is there a way to create a text field using a blueprint?
To be more clear: when I press a key it gets printed on the screen or stored in a variable.
The only idea I have is to get evey key and number and make nodes for each one - but it’s a lot of work for 26 keys and 10 numbers (if I ignore the symbols)…

Thank you.

As far as i know you need to use a little bit of code to get that (you might want to read this).

Since i’ve posted there i’ve updated the code to exclude keys like Enter, Backspace and Escape, here’s the updated version if you’re interested:

TestViewportClient.h



#pragma once

#include "Engine/GameViewportClient.h"
#include "TestViewportClient.generated.h"

/**
 * 
 */
UCLASS()
class UTestViewportClient : public UGameViewportClient
{
	GENERATED_UCLASS_BODY()

	
	virtual bool InputChar(FViewport* Viewport, int32 ControllerId, TCHAR Character) OVERRIDE;
};

TestViewportClient.cpp



#include "YOURGAMENAMEHERE.h"
#include "TestViewportClient.h"
#include "TextBasedPlayerController.h"


UTestViewportClient::UTestViewportClient(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

}


bool UTestViewportClient::InputChar(FViewport* InViewport, int32 ControllerId, TCHAR Character)
{
	// should probably just add a ctor to FString that takes a TCHAR
	FString CharacterString;
	CharacterString += Character;

	bool bResult = false; 

	ULocalPlayer* const TargetPlayer = GEngine->GetLocalPlayerFromControllerId(this, ControllerId);

	if (TargetPlayer && TargetPlayer->PlayerController && TargetPlayer->PlayerController->IsA(ATextBasedPlayerController::StaticClass()) &&
		Character >= 0x20 && Character < 0x100)
	{
		bResult = Cast<ATextBasedPlayerController>(TargetPlayer->PlayerController)->InputChar(ControllerId, CharacterString);
	}

	if (!bResult && Character >= 0x20 && Character < 0x100)
		Super::InputChar(Viewport, ControllerId, Character);

	return bResult;
}

TextBasedPlayerController.h



#pragma once

#include "GameFramework/PlayerController.h"
#include "TextBasedPlayerController.generated.h"

/**
 * 
 */
UCLASS()
class ATextBasedPlayerController : public APlayerController
{
	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintImplementableEvent, BlueprintCosmetic)
	virtual bool InputChar(int32 ControllerId, const FString& Unicode);
	
};

By default PlayerController has InputKey, but that would have required a bit more work to make it work properly, i hope this helps.

Thank you for your answer - but I don’t want to use C.
I think I’ll do it the hard way using blueprints.

You can do that, or you could ask Rama if it would be possible to include the above code in a plugin (or if he knows a better way of doing it)

Thanks for the code, Thommie. But how can I use the functionality of the ViewportClient-Class in my custom HUD now? I would be interested in the C++ approach…