Unable to assign devices to PlayerInput whit Instantiate()
Hi, I'm trying to create a local coop menu in which when a device button is pressed a player prefab is instantiated and the device is assigned to his PlayerInput component. BUT...it doesn't work since it looks like the PlayerInput component has no assigned devices.
private void Awake()
{
playerControls = new PlayerControls();
playerControls.MenuPlayersRegistration.Register.performed += ctx =>
InstantiatePlayer(ctx.control.device);
}
void InstantiatePlayer(InputDevice newDevice)
{
PlayerInput playerInput = PlayerInput.Instantiate(playerPrefab, PlayersNumber, "Gamepad",
PlayersNumber, newDevice);
Debug.Log("Player " + playerInput.playerIndex);
foreach (InputDevice i in playerInput.devices)
{
Debug.Log(i.deviceId + "/n");
}
PlayersNumber++;
}
When I debug playerInput after the Instantiation it shows the devices list empty and also an hasMissingRequiredDevices field.
Answer by Glabro · Apr 07, 2020 at 11:51 PM
I just erased my input actions asset and remade it exactly the same as the original and now the instance problem is resolved. Also the input manager which I attempted to replace with my own script now works. Maybe there were a version conflict since a created it the first time with the preview 5 and then update to the preview 6.
Your answer
Follow this Question
Related Questions
GetBindingDisplayString() returns an empty string for certain bindings? 1 Answer
Moving an object a fixed amount on its local axis 1 Answer
Problems with touch input. 0 Answers
Input.GetKeyDown not reading? Am I being oblivious? 1 Answer
(Newbie's First Project) Object doesn't stop moving until long after I let go of the button 1 Answer