Input system: How to remove empty PlayerInput slots from the PlayerInputManager array?

Hello I am trying to find a way to remove players with disconnected controllers from my scene at run time.

I succeeded at removing PlayerInput objects, but when a PlayerInput object is removed that isn’t the last created PlayerInput, the PlayerInput with a higher index will still have the same index in the PlayerInputManager and so a gab is created.


Example:

I create players 0, 1, 2, 3 and 4.

Then I disconnect and delete player 2.

After that I will have 0, 1, 3 and 4.

What I want is that player 3 and 4 will lower down by one.

So I have 0, 1, 2 and 3.


Does anybody know a way to edit the PlayerInput array in the PlayerInputManager?

I have found a solution my self.


Instead of altering the array inside the PlayerInputManager, I just unbind everything (so the controller won’t reconnect to the same User) from the User who lost it’s controller and bind the controller from the next User to that User.

After that I unbind everything from the next User and because this code is running on each User object and the next User will always looses it’s controller, this process repeats it’s self until it reaches the User with the highest index.

If the code sees the User’s index + 1 == the total amount of User’s, it will delete that User object.


If you were stuck with this too, than you can follow these steps.

I hope it will help you too.

And if anybody has a question about this, please let me know.