Thursday, October 11, 2012

Cookbook: Custom input bindings

In case you're not simply extending some UTGame and creating another clone of a shooter (which UDK is rather streamlined for) sooner or later you'll need to extend controls setup/rebind input keys, etc.

I recommend to create a custom input config, where you can keep only things you really need and avoid problems with upgrading to newer versions of UDK (conflicts while merging your changes to those from Epic). Apart from that you'll avoid problem with overriding bindings (last appearance of binding disables all bindings to the same key found anywhere before in the hierarchy of config files!). As with all other config files in UDK, create Default version of your input config (UDK version is going to be created automatically when launching editor):

   1:  [BallPuzzler.BallPuzzlerInput]
   2:  ; types //this is just a comment
   4:  //alias for binding command (reused for PC/XBOX in the same config)
   5:             //name to identify        //command to exectute
   6:  Bindings=(Name="GBA_ShowMenu",Command="CloseEditorViewport | onrelease ShowMenu")
   8:  ; pc
   9:             //key pressed, command to execute
  10:  Bindings=(Name="X",Command="ToggleZoom")
  11:  ...
  13:  //use previously defined alias
  14:  Bindings=(Name="Escape",Command="GBA_ShowMenu")
  16:  ; xbox
  17:               //key pressed, command to execute
  18:  Bindings=(Name="XboxTypeS_Y",Command="ToggleZoom")
  20:  ...
  22:  //use previously defined alias
  23:  Bindings=(Name="XboxTypeS_Start",Command="GBA_ShowMenu")

To use custom input config you need to do two additional steps:

  • create an extension to PlayerInput class with config file specified:

   1:  class BallPuzzlerInput extends PlayerInput within BallPuzzlerController
   2:   config(BallPuzzlerInput);

  • setup it in your controller class (defaultProperties):

   1:  //======================================================================= 
   2:  defaultProperties
   3:  {
   4:     InputClass=class'BallPuzzlerInput';
   6:     ...
   7:  }

Later you can react (in you controller class) on custom commands being executed:

   1:  //========================================================================
   2:  exec function ToggleZoom() //is triggered according to config key binding
   3:  {
   4:     //some code you want to run when X/XboxTypeS_Y is pressed
   5:     ...
   6:  }

No comments:

Post a Comment