- Home /
Problem with PlayerInput.user.index
Hi,
in my game I have local multiplayer with the new input system. When a player joins by pressing a button, I instantiate a prefab with a PlayerInput Component.
In my custom PlayerManager, I have a custom class PlayerData which contains a reference to a PlayerInput and additional settings regarding this player (selected character, stats etc.).
When a player joins, I am using OnPlayerJoined to create a new PlayerData object, which references the PlayerInput of the joined player, and add this PlayerData to a list (PlayerDataList), so I have all active players in this list.
Now I use PlayerInput.user.index to identify different players, meaning that I pass the user.index value around to other scripts that need to change settings for this player. If some script needs to access the PlayerData object I loop through the PlayerDataList and compare the user.index to find the correct player.
Now this seems to work fine. The problem I have appears when players leave the game.
On my custom PlayerManager I use OnPlayerLeft(PlayerInput player) to identify the player (using player.user.index), and I remove him from my PlayerDataList.
The Input System in Unity automatically reorders the users, so if the player with user.index 0 leaves, the user with user.index 1 is now at user.index 0, 2->1, etc.
What I want to do now is to pass the updated user.indexes to the scripts that need the values to identify the player. In OnPlayerLeft I go through my PlayerDataList, and for each PlayerInput I pass the user.index to the other scripts.
The problem is that the moment OnPlayerLeft executes the user.indexes are still the old ones, even though the Input Debugger already shows the new indexes. I can check that by logging PlayerInput.all.
I am really scratching my head why when in OnPlayerLeft I ask for the user.index of the PlayerInput (in the PlayerData object of my PlayerDataList) I get the old ones. Shouldn't they have been updated?
Thinking about it, I could probably circumvent that by, instead of passing the user.index around, directly passing the PlayerInput around (or the PlayerData object). But my thought was that passing an Integer around is way quicker.
Answer by Ramirofd · Aug 28, 2021 at 09:38 AM
I'm working on a project that previously worked, but after some changes to the UI it no longer receives player input. Of course I wasn't using source control for some reason, so now I need to find out why.
I know this:
The button I'm pressing has been set in the input.ini and no other class uses that button (B) or input event (TestButtonB)
The implementation consumes the input, executes when paused, and overrides any parent bindings
The player controller BP implementing the input event correctly possesses the correct pawn (I print the pawn it possesses in OnPossess
, and the pawn adds a crosshair widget to the possessing controller)
The input event implementation is not being executed (it's a print statement)
I'm out of ideas guys :(
Your answer
Follow this Question
Related Questions
ai to input value 0 Answers
How to consume input when automatically switching control schemes through a Player Input Component 0 Answers
Touch input 1 Answer
Preventing Input Changes 1 Answer