I have a working Action Map and I can go into the UI and manually change the default Action Map and Default Scheme and everything works fine. However when I try to modify the controller choice from c# I can’t seem to get it to work right. Even if I change the default values and verify it in the editor it still won’t run right.
I’ve tried a few different methods I found online and am including my code below. I’m also including some commented out items for reference. This code appears to update the correct action map, but I can’t get the scheme to update correctly. Can anyone assist in showing me how this is supposed to work?
For context I’ve been learning Unity and am trying to finalize my controller setup for Keybard & Controller before I try to implement local 2 player co-op. I ran into issues with using twin-stick with settings for both keyboard and controller so I split the maps into separate Controller (CON) and Keyboard and Mouse (KAM) settings.
private PlayerInput myPlayerInput;
private UserInputController refUserInputController;
void Start()
{
// Setup the Controllers
refUserInputController = new UserInputController();
myPlayerInput = gameObject.GetComponent<PlayerInput>();
SetupControllerOne();
}
public void SetupControllerOne()
{
string myConChoice = PlayerPrefs.GetString("playerOneCon");
if (myConChoice == "CON")
{
Debug.Log("Found Controller: " + myConChoice);
refUserInputController.AttackShipCON.Enable();
// myPlayerInput.actions.FindActionMap("AttackShipCON").Enable();
myPlayerInput.SwitchCurrentActionMap("AttackShipCON");
// myPlayerInput.SwitchCurrentControlScheme("Controller");
myPlayerInput.defaultActionMap = "AttackShipCON";
myPlayerInput.defaultControlScheme = "Controller";
// refUserInputController.bindingMask = new InputBinding { groups = "Controller" };
}
else if (myConChoice == "KAM")
{
}
}