I have a problem with my local multiplayer brawler game. In my game scene I have a Player Input Manager which I am using to spawn in my different players. However, what I want to know is how can I rememer which controller spawned in which Player prefab? So that when restarting the match (from a different scene than the main game scene), they spawn the correct player designated to the right controller.
In addition to that I have a problem that sometimes it gets the same deviceID from the two different Xbox One controllers I am using. This is causeing some problems when trying to join new players.
Thanks in advance!
2 Likes
What I was doing when I tried local coop, is that I was spawning a “Player” in the lobby (with PLayerInputManager) but I was never destroying them. Keep them through your scenes, and when you go to your “game” scene, instantiate your characters or whatever and link them to your Player. Was working great for me !
1 Like
Would recommend the same approach that @Jichaels uses.
In case you do want to remember a controller, the device ID (as in InputDevice.deviceId) should be unique and stable across one session of the input system. However, if the controller is unplugged and plugged back in, it will have a new device ID. There’s no guaranteed way in which a newly plugged in device can be determined to be the same device that we saw before.
What the input system does internally is just compare InputDeviceDescriptions. If a device is unplugged and then a device with an identical InputDeviceDescription appears, the system decides it’s the same device (which may be wrong).
Two separate gamepads ending up with the same InputDevice.deviceId would be a bug. Would find that one highly surprising, though. Are you sure it was indeed two different InputDevice instances that existed at the same time and had the same InputDevice.deviceId?
1 Like
Yes, in the input debuger the input showed up as expected to the correct controller. One controller had the id of 12, the other 17. But when debugging in the editor, it showed 12 for both controllers. However, this only happened occasionally, usually only on the first press of a button after the other controller had been used. Kind of like it were remembering the last controller input on the first new input from the new controller.