Hello.
I wanted to ask about how people set up their Controller Structures for games that allow both Gamepads and keyboard/mouse. (User chooses which one they want to use)
A lot of tutorials seem to use if statements to check which controller type is being used and then the function runs specific to the chosen controller type. But I feel like that is a wasted ‘if statement’ check every update. Wouldn’t it be better to set it at the start of the game and then not have to check the controller type every update?
I would suppose for most tutorials this works for a simple implementation, but for real life implementation I would prefer not to have these if statements in there.
Interested to see if anyone has any insight around this or can point me to any related resources.
I’m not really after any specific code but just discussion/info around the theory/structure of implementation.
Hi @S4V3D,
There are many ways to do that. First of all I want to understand more about what you are aiming to achieve. If you want to customise the game depending on the active controllers k+m / gamepad the control schemes are probably what you are looking for. With the .currentControlScheme you can read which set of controllers is used for instance. With the .ControlsChangedEvent() you can determine when the control scheme switched and the Player picked up a different device /set of devices.
In general setting the controlls at the start of the game is only a good idea if switching controlls should not be allowed in your game, if that is the case I see no problem in doing what you mentioned. In that case you may want to use .neverAutoSwitchControlSchemes.
Thanks for your reply.
I think would I generally want is to allow a player to switch controls mid game (e.g. their gamepad batteries died) so they might use their Kb/M instead.
But I don’t like the idea that every update frame there is an if statement checking which controller type is being used.
I think it would be more efficient to set the controller type at the start. And allow a player to switch it during the game if they wanted/needed too.