Skip to content

6 Inputs and Controllers

ashtongilbert56 edited this page Nov 5, 2023 · 4 revisions

A. Inputs Setup

This section will cover how to setup inputs to create events inside blueprints. For now, we will setup the Aileron, Elevator, Rudder, and Throttle inputs, where others will be added later.

  • Open your Project Settings and go to the Inputs section.

Screenshot (21) Screenshot (22)

  • There are two types of inputs defined here, Action and Axis. Action inputs are inputs that are a single action, used for applications like toggling controls, changing camera views, etc. Where Axis inputs that could have a range of values, such as the value from a flight stick. For this example we will implement Axis Inputs.

  • Add an input by clicking the plus symbol next to Axis Mappings and name this as Aileron.

  • Now that we have an input we need to designate what keys/device input correspond to that input inside the sim. Click the plus symbol next to Aileron and designate the key by either finding the key in the drop down menu or by selecting the keyboard button next to the box and pressing the desired key. For this example, we will add a 'A' and 'D' keys as our inputs as changing the scale to create opposite directions.

Screenshot (23)

  • We will repeat this same procedure for the Elevator, Rudder, and Throttle as shown. The scale value can be changed to adjust the scale and direction of the input.

Screenshot (29)

  • We can now go to our vehicle blueprint, where we can now search and add our new event input nodes.

Screenshot (25) Screenshot (26)


B. Controller Setup NOT FINISHED

This section will cover how to setup our input controllers. This section should be taken as a general guide as each different controller will be different. A generic overview of the steps are below, followed by examples for a flight stick HOTAS, a PS4 controller, and an RC transmitter.

  1. Checking your device First, connect your device to your pc either through a USB port or bluetooth, then open the device manager. Your controller should show up as a 'HID-compliant game controller' under the 'Human Interface Devices' category. This can be hard to spot as it will more than likely not display the name of your device. If your device doesn't show up in the 'Human Interface Devices' category, or at all, you may need to download specific drivers for your device from the manufacturer.

  2. Obtain the device's hardware and model numbers. Once you have found your device in the device manager, right-click and open the properties. Navigate to the Details tab and select 'Hardware Ids' from the dropdown. We are looking for the Vendor and Product ID marked as VID and PID respectively, each usually a four character code.

  3. Add Raw Input Plugin Enable the Raw Input Plugin in Unreal Engine. This is done the same way as Cesium, by opening the 'Plugins' window in the 'Settings' and searching for 'Raw Input'. This plugin takes the raw data from your input device and converts it into information for Unreal Engine to use.

  4. Raw Input Setup Open your Project Settings and scroll down to the now visible Raw Input section under 'Plugins'. Here we will paste in our Hardware IDs to tell the plugin to lock on this device. Click the plus sign and add your IDs proceeded by a '0x'. Ex: for a VID of 044F, we would input '0x044F'. This will automatically populate Axis and Button elements based on what the plugin guesses how the devices are setup, usually this is always wrong.

  5. Axis Configuration This step is the tricky part. First let's define what we are looking at. Each Index under the Axis and Button Properties corresponds to an interpreted input. This is the input from the device. For example, Index[0] is the first input axis the plugin recognizes from the controller. We then tell Unreal Engine what this input should be "known' as. If we define the Index[0] axis property as the 'GenericUSBController Axis 1', Unreal Engine will create an input 'GenericUSBController Axis 1' from the value obtained from the Index[0] data. This would be the same as naming the Index[0] key on the keyboard as 'A' or any other key. The problem now comes that we don't know what Index[0] actually is. Index[0] for a keyboard could be any key, which we need to figure out. A way to do this is to setup a simple blueprint to test what input is doing what.

Let's focus on Axis Properties first. Each controller will have a number of different axes for each input interpolated by the plugin; We need to decipher what axis is what.


C. Example: Rotating with Inputs

  • After setting up our input event nodes in a previous section, we can create a blueprint to use these inputs to change the rotation of our vehicle. This blueprint is very similar to the moving forward example where here we utilize 'Get/Set Actor Rotation' rather than 'Get/Set Actor Location'.

Screenshot (28)

  • We can compile and run our sim. By pressing the respective input keys the vehicle should rotate, however, probably not in the way we'd expect an aircraft to rotate. This blueprint is only rotating the vehicle around the axes and not updating the aircraft states and respective axes. The speed and direction of the rotation can be altered in the blueprint or in the Inputs settings.

Tip:

  • You can organize your blueprints by adding comment boxes as seen in the above image. To do this, highlight the nodes you want and press 'c'.