# Custom Controllers

Custom Controllers are virtual controllers that you can customize, adding as many axes and buttons as you need. A Custom Controller allows you to set your own sources for axis and button input. This could be any type of controller or virtual controller. Anything that can return a float or a boolean value can be used as an element source. Custom Controllers can be used for on-screeen touch controllers and more. (See the example in the Rewired/Examples folder.)

IMPORTANT NOTE: Custom Controllers are NOT meant to be used to create new HID joystick definitions for controllers that Rewired doesn't automatically recognize and map for you. They are virtual controllers that know nothing but what axis and button data is fed into them by your script. They are entirely separate from the Joystick system, are not auto-assigned, don't generate connect or disconnect events, etc. If you are planning to use a Custom Controller to add support for controller that Rewired can detect but doesn't recognize and automatically map for you, don't -- it's the wrong tool for the job. Instead you want to create a new controller definition for that or else define a Joystick Map for Unknown Controller instead. Custom Controllers can however be used to support devices that do not show up as joysticks such as special controllers that require the use of an SDK (most VR controllers).

Creating/Editing Custom Controllers

You create and edit Custom Controllers in the Rewired Editor. See Rewired Editor - Custom Controllers for more information.

Assigning Custom Controllers to Players

You assign starting Custom Controllers in the Rewired Editor. See Rewired Editor - Players for more information.

Custom Controllers, unlike Joysticks, are instantiated for each player. When you add a Custom Controller, the controller will be created on game start and assigned to the Player. If you add the same controller to multiple Players, the Custom Controller will be instantiated for each, therefore setting a Tag on each can be helpful to differentiate the controllers.

You can also assign and un-assign Custom Controllers via scripting at runtime. This can be useful if you want to detect the presence of a certain type of non-standard controller (some VR controller for example) and auto-assign that to a Player. Assignment of Custom Controllers is similar to assigning Joysticks to Players.

Instantiating Custom Controllers via scripting

Normally, Rewired will instantiate the controllers assigned to each Player upon initialization. If you need to instantiate new Custom Controller objects at runtime, they can be instantiated from the pre-defined definitions in the Rewired Input Manager at via scripting using the CreateCustomController methods in ReInput.controllers.

Updating Element Values

Element (axes and buttons) values must be updated on the Custom Controller each frame. There are 2 different ways you can do this:

1) Register for the ReInput.InputSourceUpdateEvent, then when that event fires, push the new values into the elements directly through CustomController.SetAxisValue and CustomController.SetButtonValue.

2) Set callbacks in the CustomController with CustomController.SetAxisUpdateCallback and SetButtonUpdateCallback. These callback functions will be called during the input update step and you can push the latest values into the element at this time.

Examples of both methods can be seen in the Touch Controller example in the Rewired/Examples folder.

Note: Both the InputSourceUpdateEvent and the callbacks may be called more than once per frame. They will be called each time input is updated, which is dependent on the Update Loop setting in the Input Manager. If you're updating input in multiple loops, for example Update and FixedUpdate, the event and the callbacks will be called once for each update loop.

Layouts How To's