I have some buttons in a shared multiplayer menu that supports of to 4 players selecting skills from a shared skill roster on the same screen at the same time.
I want to allow players using a pointer (typically keys & mouse) to choose skills by clicking, not just by using submit/enter.
This represents a problem. Let’s say we have two separate players, each using a different mouse/pointer to play. The devices are correctly mapped to each player (i.e. each PlayerInput) and the PlayerInputManager handles that through default join behaviour.
At the time of an OnClick event, I need to then be able to get the PlayerInput that is attached to Mouse.current (or some other way).
Can it be done?
Figured out a sort of hacky solution that works for now.
The PlayerUIInput controller (of which there can be up to 4 at any one time) receives the OnClick event first, before the clicked button fires it’s own OnPointerClick event. The button doesn’t know which player is clicking it since most of that information is stored inside the SkillMenu script, which is fed information and driven by the PlayerUIInput controller.
The workaround is as soon as I get an OnClick event, I set a variable inside the SkillMenu:
SkillMenu.LastClickedPlayer = this;
Now from inside the button script OnPointerClick event I need only feed the button to the SkillMenu, since it already knows which player last clicked. This likely introduces a race condition (may be possible for two different players to click at nearly the exact same time, which could mean the LastClickedPlayer updates before the OnPointerClick event fires) but I can live with that edge case.