Remapping controls in-game

Particularly if your game is played with a keyboard or controller, you may want to provide your players with the option to remap the controls. It is possible to override Adventure Creator's input checks by using delegates - this also makes it possible to link AC with other input management assets.

In this tutorial, we'll override the InteractionA input, which is the input button used to interact with Hotspots, using a simple script. Be aware that 'delegates' are a slightly more advanced scripting topic, but the principles involved in here can be applied to create a completely customisable input system.

If you open up the Settings Manager, you can see a list of all inputs our game can use about halfway down:

Since we'll be overriding input, ensure that Assume inputs are defined? is left unchecked. This will mean Unity does not throw errors if any of these inputs are not defined.

Normally, we'd now need to create an input named InteractionA within our Input Manager. But instead: we're going to write a script that lets us change which keyboard key triggers this input.

Create a new C# script named InputOverride. Open it up, and add the AC namespace to it's header:

Now declare a public string variable named interactionKey, that will represent the letter key mapped to InteractionA. Here, we've given it a default value of 'a':

AC's PlayerInput script has a number of functions that serve the same purpose as Unity's Input.GetButtonDown (etc) functions - they are named similarly, but without the dot after 'Input', e.g. InputGetButtonDown. We'll write our own function that will override InputGetButtonDown. It takes a string parameter for the button's name, and returns a bool that determines whether or not the button was pressed:

Now let's modify the function so that, if buttonName is equal to InteractionA, we'll instead return the value of Input.GetKey (interactionKey);.

Finally, we just need to assign our CustomGetButtonDown function as the delegate that override's PlayerInput's InputGetButtonDown function. We can do this by assigning it in our Start() function:

All available input delegates can be found listed in the scripting guide. The main page of the guide also describes how any of AC's "engine" scripts can be referenced in his way.

Our complete script is then as follows:

using UnityEngine;
using System.Collections;
using AC;

public class InputOverride : MonoBehaviour
{

	public string interactionKey = "a";


	void Start ()
	{
		KickStarter.playerInput.InputGetButtonDownDelegate = CustomGetButtonDown;
	}


	private bool CustomGetButtonDown (string buttonName)
	{
		if (buttonName == "InteractionA")
		{
			return Input.GetKey (interactionKey);
		}

		return Input.GetButtonDown (buttonName);
	}

}

Attach this script to an empty GameObject in an AC scene, and run the game. You'll find that you can interact with Hotspots by pressing whatever key is listed as the interactionKey in the script's Inspector!

Update:
A further example, that involves linking AC to the Rewired asset, can be found here.

"Adventure Creator" and this website are copyright Chris Burton, ICEBOX Studios

Go to top