CrossPlatformInputManager Is Not Good

Seeing as we are making a spaceship type game I have attached a sophisticated flight controller joystick to my computer.
First of all there in no easy way to map joystick buttons CrossPlatformInputManager as it doesn’t have a learning mode, secondly there is no method to get an array of pressed buttons or anyway of passing in a generic string such as “joystick button 0” for example.
Ideally what is needed is for the player to be able to configure there own button and axes.

    bool f = CrossPlatformInputManager.GetButton("Trigger");
    if (f)
    {
        print("Firing!!!");
    }
    if(f != Firing)
    {
        Firing = f;
    }

Secondly i tried interrogating the unity engine at a low level. This doesn’t work either as no Joysticks are returned, although the joystick might be masquerading as a gamepad.

    UnityEngine.InputSystem.Joystick js = null;
    foreach (UnityEngine.InputSystem.Joystick jst in UnityEngine.InputSystem.Joystick.all)
    {
        js = jst;
        break;
    }

    if(js==null)
    {
        return;
    }
1 Like

I also made this function to log key presses to the console.
I am passing back in the array of strings I have got from introspection, this function throws loads of exceptions, if they key is missing it should return not pressed or false not chuck out an exception.

The Input.GetKey system should be able to handle it’s own enumeration without chucking exceptions NFFP.

void ButtonsPressedToConsole()
{
    string[] kn = Enum.GetNames(typeof(KeyCode));
    int z = kn.Length;
    int i = 0;
    for(i=0;i<z;i++)
    {
        try
        {
            if (Input.GetKeyDown(kn[i]))
            {
                print(kn[i] + " is pressed");
            }
        }catch{
            print(kn[i] + "is an unrecognised key");
        }
    }
}

GRUMPY :frowning:

Okay I sussed out how to create a unity keyboard / input logger. So I should be able to create a 2D scene with a input trainer in it to configure how keys are mapped to various functions.

void ButtonsPressedToConsole()
{
    // string[] kn = Enum.GetNames(typeof(KeyCode));
    string key_name="";
    //KeyCode[] values = Enum.GetValues(typeof(KeyCode));

    foreach(KeyCode k in Enum.GetValues(typeof(KeyCode)))
    {
        try
        {
            key_name = Enum.GetName(typeof(KeyCode), k);
            if (Input.GetKeyDown(k))
            {
                print(key_name + " is pressed");
            }
            else
            {
                //print(key_name + "NOT is pressed");
            }
        }catch{
           print(key_name + " is an unrecognised key");
        }
    }
}

:slight_smile: HAPPY

I completely agree.

A lot of Unity’s Standard Assets are “lacking” in general. I am not that experienced in order to write my own input system, but the sheer amount of bad experiences and reviews from people when it comes to CPIM makes me a little uncomfortable using it. If I’m not mistaken there is no documentation available at all on Unity’s website and most users just wrap the Unity API calls in their own class.

However, at the scope of this lecture (and the next ones), I believe it is good enough for everyone to dive in and learn, as Ben explained that the Manager gives this cross-platform and key reassignment capabilities. We could debate on whether it is good to have higher quality but more complicated material that can set a good example for the people using it, but not be beginner-friendly, or use CPIM as is so everyone can understand. At the end of the day, people who truly want to go to the next level, will do what you did and improve what it is given to them. But it needs time to do that. For now, this manager does the job quite well.

I didn’t want to get bogged down in creating an input system for unity at this stage, but I was very surprised that the input manager did not include an inbuilt keyboard trainer. This functionality is so commonly required by games I would have expected there to be a dedicated built in user interface in unity to accomplish this. At least I have given everyone an easy way to interrogate which buttons are being pressed in the unity environment.

Privacy & Terms