UDN
Search public documentation:

GFxKismetInput
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > User Interfaces & HUDs > Scaleform GFx > How to capture keyboard input in Kismet

How to capture keyboard input in Kismet


Last tested May, 2011

Overview


This tutorial explains how to capture keyboard input via Kismet, thus allowing a GFx movie to use that captured input to do something, without needing to write any UnrealScript at all! A GFx movie in the level that you want the player to be able to interact with when he walks up to it, such as a computer console.

Setup


Create a simple red square in the middle of the stage of a new Flash file. Convert the square to a movie clip, and give it an instance name of 'myGraphic' in the properties panel. Save the Flash file in the proper location of your UDK install.

ActionScript


Put this code on a new layer called 'actions' on frame 1 of your Flash file:

ActionScript
  _global.gfxExtensions = true;
  _perspfov = 25; // Used in 3D transformations. Can be any value from 1 to 179.
  
  var keyboardInput:Object = new Object(); // creates a new object to hold keyboard input.
  Key.addListener(keyboardInput); // uses the object to listen for keyboard input.
  
  /* when a key is pressed, execute this function. */
  keyboardInput.onKeyDown = function()
  {
      /* store the keyboard input ASCII code inside 'keyPressed'. */
      var keyPressed:Number = Key.getCode();
  
      /* if LEFT ARROW was pressed... */
      if (keyPressed == 37)
      {
          /* rotate the movie clip by +5 degrees. */
          myGraphic._yrotation += 5;
      }
      /* if RIGHT ARROW was pressed... */
      else if (keyPressed == 39)
      {
          /* rotate the movie clip by -5 degrees. */
     myGraphic._yrotation -= 5;
      }
  }
  

ALERT! Note: Scaleform does not currently support getAscii(). Instead, be sure to use getCode().

Save and Publish the movie.

UDK Initial Setup


In UDK, create a simple test level. One room with a light and a player start should do. Then do the following:

  • Create a BSP cube inside the room somewhere. We'll display the GFx movie on one face of this cube.
  • Add a Trigger right in front of one of the faces of the cube.
  • Now, import the SWF file into the Content Browser.
  • Create a new TextureRenderTarget2D in the same package as the newly imported SWF. Name it 'myRT'.
  • Create a new Material in the same package. Name it 'myMat'.
  • Add a new TextureSample in the Material Editor window.
  • Attach the black (RGB) output of the Texture Sample to the Diffuse input of the Material, and the white (alpha channel) output to the Opacity input of the Material.
  • Select the Material and set the Blend Mode to BLEND_AlphaComposite in the Material drop down.
  • Leave the Material Editor open, and go back into the Content Browser and select 'myRT'.
  • Back in the Material Editor, select the Texture Sample, then insert 'myRT' into the Texture field with the green arrow.
  • Close the Material Editor window and save changes.
  • Save the package that contains the SWF file, render texture, and material.
  • Select a face of the BSP cube, preferably the one next to the Trigger, and with 'myMat' selected in the Content Browser, right click, then choose: Apply Material : myMat.
  • Build all and save the level.

Kismet Setup


Open Kismet and do the following:

  • Add a Level Loaded event.
  • Add an Open GFx Movie action.
  • Connect Loaded and Visible to In on Open GFx Movie.
  • Create a new Object Variable and attach it to the Movie Player output of Open GFx Movie.
  • Select Open GFx Movie, and insert the SWF from the Content Browser in the Movie field.
  • Insert 'myRT' from the Content Browser in the Render Texture field.
  • Set the Render Texture Mode to RTM_AlphaComposite.
  • Now, select the Trigger in the level, then right click in Kismet and select: New Event Using Trigger_x -> Touch.
  • In the new Trigger node's Sequence Event drop down, set the Max Trigger Count to 0.
  • Add a new Set GFx Captured Keys action.
  • Connect the Movie Player input to the Object Variable you created above in Step 4.
  • Connect the Touched output of the Trigger node to the Activate input of the Captured Keys node, then connect the UnTouched output to the DeActivated input.
  • Select the Captured Keys node, and add two Capture Keys using the green plus icon.
  • Set [0] to Left and set [1] to Right.

Save the level, then play in editor.

You should be able to walk up to the GFx movie, which shows a red square, then use the Left Arrow and Right Arrow keys of your keyboard to alter its rotation in 3D space. Walking away from the movie will release the Left and Right arrow keys.

You could just as easily put the material 'myMat' on a static mesh instead of a BSP.