playMaker

Author Topic: Unity's (new) Input System  (Read 29282 times)

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #15 on: August 23, 2019, 05:52:36 PM »
What version of Unity are you working on Thore?

Hi!

I have stopped working on this a while ago. Both Unity and the preview package were always the then lastest. The last prototype was about storing button variables in scriptable objects, which you can “slot” into PlayMaker actions, which was 2019.1, or late 2018. However I could not get it to work robustly (it did work in principle, but not good enough). I didn’t check with 2019.2

Both the input actions and PlayMaker work with events. The input actions need to be called and canceled properly, and that gets in the hair with the states in PlayMaker, somehow.

Also, the system was (is?) in the preview stage and that means, it might not be feature complete and contained some bugs back then. They provide a script that can use Unity events, which can, in theory, talk to PlayMaker. This is an alternative to my approach using PlayMaker actions. But that didn’t work at all. Since I never used the event system from script to call PlayMaker events, I had no idea if I’m doing it correctly and then concluded that their provided player input script was maybe not ready on their end.

Might be worth a check if it works now.
« Last Edit: August 24, 2019, 11:08:34 PM by Thore »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: Unity's (new) Input System
« Reply #16 on: August 23, 2019, 07:47:39 PM »
I'm still quite the newbie with playmaker.

The current issue of unity I'm using 2018.2.8 f1.

Using this free asset https://assetstore.unity.com/packages/tools/input-management/controller-tester-43621

I was able to get my logitech joystick controller Axis.

Essentially we are dealing with string information.

so all I needed was temp inputs, one for Horiz / Vert

You can always change the value of a string :)

Eg. In my mouse control state the string values are set to either fire 1 / fire 2

By adding new inputs and the help of the actions https://hutonggames.com/playmakerforum/index.php?topic=12996.msg60642#msg60642

I was able for the user to choose either logitech or Xbox controller and have the ability to remap the buttons.

Not sure if this info is of any use, but hope it helps.




Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #17 on: August 24, 2019, 06:43:51 AM »
Hi!

This might be useful for the while I’m stuck with the old ways. Thanks :)

The asset apparently sits on the standard Unity input system, where it’s indeed a hassle to configure gamepads and controllers.

That’s why Unity is moving to a brand new system, which is a lot better in a lot of ways. Here you configure input actions (tied to your game’s verbs, i.e. running, jumping, firing, cancel popup ...) and then you say what they mean in terms return variables and input sources (keyboard, mouse etc). In addition, it has more going, like input detection (“player 2 press button to join”) and managers to handle multiple devices, and any number of bindings.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #18 on: September 15, 2019, 07:07:51 PM »
Hi, Excellent, that will help me greatly! I can't promess when I am going to start on this, so please bump every week or so, just to keep me aware of that... I need it. Bye, Jean

More like once a month or so, but here's the bump :)

I'll give up on it for now. I managed to find a better way to reference actions than strings, but other than that, there's always a thing or two in the way to make it work. They changed something that the old version I made a while back don't respond anymore.

Right now, it's the old problem that virtually all example scripts use hardcoded references, but the action must be flexible.

I found that using the InputActionReference might be the best way for PlayMaker actions:
Quote from: Unity API
The reference will remain intact even if the action or the map that contains the action is renamed.

References can be set up graphically in the editor by dropping individual actions from the project browser onto a reference field

But I didn't get very far with this. I can fetch asset, action map and asset from the reference, but when I plug it in (no errors), it still won't do the thing.

Code: [Select]
public InputActionReference inputAction;
    InputAction action;
    InputActionAsset asset;
    InputActionMap map;

        public override void OnEnter()
        {
            if (inputAction != null)
            {
                // get the references
                asset = inputAction.asset;
                action = inputAction.action;
                map = action.actionMap;
            }

            action.performed += ctx => DoIt();

        }

   void DoIt()
        {
            Debug.Log("Did it");
        }

        void OnEnable()
        {
            map.Enable();
        }

        void OnDisable()
        {
            map.Disable();
        }

...

They don't return null, also log apparently correctly (e.g. Debug.Log(map.name)), But in hardcoded way, with hardcoded references, it works. E.g.

Code: [Select]
controls = new Controls();
...
controls.Gameplay.Foo.performed += ctx => DoIt();

Another neat function I found in one of the visualizer scripts:

Code: [Select]
   

        public InputActionReference actionReference;
        public FsmString actionName;
        InputAction action;


private void ResolveAction()
        {
            //// NEAT SNIPPED FROM UNITY
            // If we have a reference to an action, try that first.
            if (actionReference != null)
                action = actionReference.action;

            // If we didn't get an action from that but we have an action name,
            // just search through the currently enabled actions for one that
            // matches by name.
            if (action == null && !string.IsNullOrEmpty(actionName.Value))
            {
                var slashIndex = this.actionName.Value.IndexOf('/');
                var mapName = slashIndex != -1 ? this.actionName.Value.Substring(0, slashIndex) : null;
                var actionName = slashIndex != -1 ? this.actionName.Value.Substring(slashIndex + 1) : this.actionName;

                var enabledActions = InputSystem.ListEnabledActions();
                foreach (var action in enabledActions)
                {
                    if (string.Compare(actionName.Value, action.name, StringComparison.InvariantCultureIgnoreCase) != 0)
                        continue;

                    if (mapName != null && action.actionMap != null && string.Compare(mapName, action.actionMap.name,
                        StringComparison.InvariantCultureIgnoreCase) != 0)
                        continue;

                    this.action = action;
                    break;
                }
            }

            if (action == null) Finish();
        }


That's what I got.
« Last Edit: September 15, 2019, 07:10:13 PM by Thore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Unity's (new) Input System
« Reply #19 on: September 17, 2019, 02:10:19 AM »
Hi,

 Yeah... and it's out of beta, so I think it will make sense to support this officially actually, I'll talk to Alex on this.

 Bye,

 Jean

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #20 on: November 25, 2019, 08:39:30 PM »
Howdy, any updates on this?
https://blogs.unity3d.com/2019/10/14/introducing-the-new-input-system/

Edit: An easy implementation works in a custom action I just made, replicating the current buttonDown, get axis etc. However, it’s not yet using the mapper. This was easy enough this time around, maybe it’s stable enough now to get it to work.
« Last Edit: November 25, 2019, 09:31:52 PM by Thore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Unity's (new) Input System
« Reply #21 on: November 26, 2019, 01:28:19 AM »
Hi,

 yeah, I had a look, and the way they've done it is going to be tricky to implement in PlayMaker. Some careful planning need to go into this so that it works out well, so I would not hold my breath. Right now, I strongly recommend relying on Rewire asset, which is battle tested and has built in playmaker support.

Bye,

 Jean

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #22 on: November 26, 2019, 02:29:30 PM »
Alright!

Here's a simple action that directly reads out a currently connected gamepad. I made it for prototyping purposes. I am not sure if it's necessary to do a more throughout setup where it reads inputs in update, and clears them in fixedUpdate to make sure they're accounted for. Works for me, for now. ;)

Cheers.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #23 on: November 27, 2019, 01:53:27 PM »
Another heads-up. With the linked-to update, the provided PlayerInput and SendEvent system also works now, which means that global events (for instance) can be called with the proper input system and input maps.

Try this in a new scene and right out of the box to see how it works. You can change and adapt it easily afterwards :)

The first few steps are like explained here with pictures, under Getting input indirectly through an Input Action
https://blogs.unity3d.com/2019/10/14/introducing-the-new-input-system/


1: Install the Input System package.
2: Restart Unity!
3: Select the game object, and “Add Component” > Player Input.
4: Click on “Create Actions” in the Player Input component you just added.
5: Click on “Behaviours” in the same and select “Invoke Unity Events”.
6: Expand the Events > Player > e.g. Fire (Callback Context)
7: Drag-Drop the target FSM component into the field below Runtime.
8: Change “No Function” to PlaymakerFSM > SendEvent (string)
9: Write the exact target global event name into the field right below.

Now hit play and see that the global event gets triggered when the associated button/key is pressed.

 
« Last Edit: November 27, 2019, 02:39:52 PM by Thore »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: Unity's (new) Input System
« Reply #24 on: November 29, 2019, 08:53:50 AM »
Alright!

Here's a simple action that directly reads out a currently connected gamepad. I made it for prototyping purposes. I am not sure if it's necessary to do a more throughout setup where it reads inputs in update, and clears them in fixedUpdate to make sure they're accounted for. Works for me, for now. ;)

Cheers.

Did you solve the problem when building to web GL?
I noticed in my own work that the buttons are changed when build is web GL.

I solved this by using two separate FSM's web GL control and Unity editor control.

You can check this yourself with the controller tester its free on the asset store.


Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #25 on: November 30, 2019, 01:46:29 PM »
No idea. The script uses their API, so when there is a problem with Web GL, it would be on Unity’s side. I haven’t tested this though. A lot of things did not quite work during preview, as this thread shows, but it’s in a good shape for a month or two.

Alright!

Here's a simple action that directly reads out a currently connected gamepad. I made it for prototyping purposes. I am not sure if it's necessary to do a more throughout setup where it reads inputs in update, and clears them in fixedUpdate to make sure they're accounted for. Works for me, for now. ;)

Cheers.

Did you solve the problem when building to web GL?
I noticed in my own work that the buttons are changed when build is web GL.

I solved this by using two separate FSM's web GL control and Unity editor control.

You can check this yourself with the controller tester its free on the asset store.



Odd_But_Awesome

  • Playmaker Newbie
  • *
  • Posts: 22
    • Odd but Awesome
Re: Unity's (new) Input System
« Reply #26 on: July 28, 2020, 10:34:05 AM »
Hi @Thore

I tried doing as you listed steps 1-9 Getting Input Directly but it doesn't seem to call the event. Not sure if you can tell from the attached - what am I doing wrong? Or even if my actions will work.

Thanks
JG
« Last Edit: July 28, 2020, 10:40:03 AM by Odd_But_Awesome »
Check out my games & VR Cardboard titles at https://oddbutawesome.weebly.com/apps-new.html

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Unity's (new) Input System
« Reply #27 on: July 28, 2020, 02:54:01 PM »
My old version does no longer work, and I discontinued working on this. But Digitom picked it up, here: https://hutonggames.com/playmakerforum/index.php?topic=21797.msg95729#msg95729

« Last Edit: July 28, 2020, 02:57:27 PM by Thore »

Omninorm

  • Playmaker Newbie
  • *
  • Posts: 33
Re: Unity's (new) Input System
« Reply #28 on: July 30, 2020, 05:03:17 AM »
Ok so Rewire still the suggested method? :)