Download

Typing Input

Hi all,

I’m working on a multiplayer game where typing is a core part of the gameplay.

So I read into the action binding system and came away with the feeling that to match the current pattern, I’d need to create a FInputActionKeyMapping for each character that could be typed - i.e. typed_A with ‘a’ and shift enabled for it, etc for all the characters which could be typed. This seemed kinda horrible and dirty, though as I dug further I came back around to thinking it may be the best way.

The other alternative I looked into was subclassing PlayerInput, adding a new event type which contained the typed character, and overriding relevant functions (at least ProcessInputStack and InputKey). Though neither of those are virtual, so it’d mean recompiling the engine from source, which seemed overkill for this.

So, to get to my question, what is the right (no, really, I’m a programmer, so I clearly don’t really mean right, let’s say answer that the highest percentage of programmers will begrudgingly acquiese to) way of doing it?

Is it the first, second, or some other idea my lack of familiarity with UE4 didn’t lead me to?

Cheers,

Alan

Another question I have, though I should probably just test it, but hey, better to know if it’s by design rather than by conincidence - are action names case sensitive? i.e. is “typed_a” != “typed_A”?

For anyone curious, at this stage I’m going with the a whole mess of action mappings (though I am wondering if the system was to designed to be performant with 100ish action mappings).

Way I’m trying to implement it (who knows if it’ll work) is to have a subclass of PlayerController, override SetupInputComponents, and in there make calls to AddActionMapping. These mappings may change depending upon the game type and keyboard layout etc (as far as I understand any given key combo (shift, ctrl, etc plus key) for a FInputActionKeyMapping can only have one action). Otherwise, I could get away with it just changing based on player settings, though even that I’m unclear on how best to do as the PlayerController is created on the server then replicated to the client. One option appears to be to have the GameMode’s PostLogin call through to the client asking it to grab it’s settings and either set them on replicated variables (I’m assuming the client is owner of its player controller and can do that) or push it through to the server via an RPC.

I guess to me the most unclear part of all this is there is this nice modularity of key presses and actions, which seems fairly straightforward in the local case, but once it gets to networked, it becomes a little opaque at what level a lot of this happens. The keypress is clearly received on the client end, is it converted to an action there and the action is sent through to the server? Or is the raw key press sent through and the server converts it to an action? I can’t imagine everything is sent through raw, as that means the server needs to care about the client hardware config.

Anyway, this is getting a little rambly. I’ll keep digging and update this thread with what I end up doing as I go. I’ve left off most questions that have arisen now as it’s becoming a very large number very rapidly.

Cheers,

Alan.

Okay, after much coding, digging, reading, coffee, and other bits of back and forth, I’ve found UGameViewportClient | Unreal Engine Documentation

My current plan, which is the one I dislike least so far (maybe), is to make a custom viewport client which can pass key events directly to my PlayerController.

This seems the least objectionable idea so far, possibly with extra mode stuff to decide if this should happen, but I’ll probably leave that up to the controller, and it can just say if it has consumed the key or not. Though, I need to do some networking planning and work here as the event needs to let the server be authorative on typing, a la the whole movementComponent thing for moving.

Hopefully these ramblings are useful for someone in the future.

Dude if you want to get text as input why not use umg or if you want to make actions as you type then just check what you typed each tick in the umg or just pass the text to your player character or whatever each tick and process it there? There is also a on text changed call back for textbox widget

Even if you don’t want to display a text box just make the umg widget’s visiblity hidden and type, the text would go from text box to actor or whatever you like but it’ll look as if you are typing directly, sounds simple?

Or maybe you are planning something different

Hi Commander,

Unfamiliarity with UE4 is the main reason this took so much digging. The Viewport option did work, and I have it passing through to my custom player controller, which in turn passes through to the possessed pawn.

Thanks for the UMG suggestion. I’ll read up on it a bit, depending on how I end up putting UI with menus etc around this all, it may make way more sense to have a hidden widget that takes focus when you’re in game and passes it across to menu entries.

All the gameplay is typing based, so my only concern with using existing widgets is if I still have the granularity of getting individual key presses, there’s no need for me to store the history or a buffer, but I can just clear anything stored. I may need the timing of key presses as part of this, I’m not sure, so checking an input each tick may or may not be precise enough (I’d be surprised if it’s not, but will find out).

Cheers,

Alan.

I’m not sure I understand your idea of the game, but if you wanted your game logic to react to text being typed in a case sensitive manner than there is no better alternative than a hidden umg textbox widget capturing the input.

Also there are certain input modes so you can have your keypress directed to player and typing text at the same time, so you can have player running around with arrow keys while you type with alphanumeric ones.

Good luck with your project

Thanks for the extra detail, Commander. I appreciate the advice.

Cheers,

Alan.

Hey Commander,

I believe I’m having the same issue that Skyphyr had. I want to allow the user to create floating text boxes (so to speak) in the environment at the cursor pointer. Right now I have my blueprint set up to raytrace and place an actor, but I have no idea how to use custom input text. Could you elaborate on what you meant in your comment?