I decided to rethink how I am using the PlayerInput module and whacked it on a singleton which my controller then references.
Now I think about it, it’s probably the better design
Hey team - hoping someone can help out…
I have a ‘player’ with a PlayerInput component for it’s controls, works as expected. However if I need to disable that object and re-enable it, I get an error “Argument Exception: Invalid user”. This can be confirmed by monitoring the input system debugger window, when enabling the gameobject, no user is added.
Is there a way to do this operation correctly or is it just a representation of the current state of the input system?
I’m gonna revive this thread since I’m having the same issue you had.
You decided to use a singleton - how and why though?
(1) I need input for my UI actually. e.g. in a specific menu, when the player press back (escape), it should go to previous menu. That menu will be disabled then, and so the input
(2) If I use a single object and assign the PlayerInput to it - how will I be able to use it in my menu?
Hey there,
I’m also using menu ui navigation this way.
I’m simply registering the events by code and enabling the actions as required.
There are examples on the github page but let me know if you get stuck and I’ll post up my code as examples.
I know how to register it by code, I just find it a bit silly creating 5 different script for 5 different objects, where each one is simply doing .SetActive(false) .SetActive(true) to 2 different properties…
I just finished creating a script where you can choose the action map and the action, and add an event, and it will register those and call the event. However, I have 2 issues. Keep in mind that when a user presses a key, the current game object is disabled, and another game object is activated. Both have the custom script I’m talking about.
The issues are:
After trying to fight it some more, I ended up with simply checking the triggered property in Update().
I believe it is less efficient, since now I have an extra component in the game loop even though there is a specific callback for it; but at least this one works.
I have my implementation done via a state machine. So when the player state changes to something which requires a particular control mapping, the state machine calls it’s own OnDisable method (which will unsubscribe from the input events) - then the new state subscribes to the required input events.
So even if it is going from game mode to a menu UI, this implementation doesn’t really care because it is only actioning those specific input events in that state anyway. I feel this is quite effective, for my needs anyway.