Hello everyone, thank you in advance for your time.
I’m prototyping a small game where 4 players can control different modules/turrets. As each module has different controls, I’ve created an ActionMap for each using the new InputSystem.
The players use the PlayerInput component (with the “SendMessage” behavior), with a default map (“Convoy” in this context) and a script to handle default actions like moving themselves or enter in a module. Something classic so far.
Here’s a little preview of my InputAction asset if it could help to understand :
My question is about the modules. They have their own script with the methods for their respective Actions (in distinct ActionMap) but I discovered that these methods will only be called if the gameObject itself has a PlayerInput component.
In my head, I believed only my players should/would have the component attached.
So I’m quite confused about handling my ActionMaps because there is nothing like global active map, even less per players, right ?
So am I twisting myself in knots over something simple or do you have other recommendations for handling theses players and these module’s ActionMaps ?
Thank you very much for your knowledge and have a good day !
Thanks a lot for you answer !
Yeah, you’re right, the SwitchCurrentActionMap will tell to the PlayerInput component to swith to another ActionMap and to send messages for other actions. But as I understand right now, all actions should be inside the Player script, because the PlayerInput will only send messages to the gameObject it’s on.
My question was more about organizing code now that I think about it, because if wanted my modules to execute some code and answer that message, it’s likely I have to add another PlayerInput component on them but doing that might just be overcomplicated for nothing.
I’m quite reticent to dig through C# events but, as you suggested, this might be the “simpler” way to make actions, regardless what object execute it as long as I take care to put everything together.
Well, I think the problem with having another PlayerInput component on another gameObject is that it can mess things up with the PlayerInput & PlayerInputManager. So, if you try to print something like playerCount, you will find that it will count all gameObjects with PlayerInput even if they are not players in your case.
Also, I found this forum which talked about a similar issue to yours. People there suggested using Unity or C# events. Hopefully this helps, and good luck : )
Thanks a thousand times for your help and for all of these resources !
I think I will use them and give a try to C# events, they seems more robust once set up.
Thanks again and have a great day !