PS4-PS5 horizontal analogs read as Vector2 instead of floats

Not sure if this is a bug, but if feels like so.

When reading horizontal analogs (surely happens with verticals too), I don´t get a float but a vector 2. This only happens with the Play Station controllers.

This makes reading Play Station devices much more dirty in the code.

      //STEERING INPUT
       //--------------------------------------------------------------------------------------
       var device = InputSystem.GetDevice<Joystick>();  // o usa Gamepad si prefieres

       if (device != null)
       {
           // Si el dispositivo es un mando de PlayStation (DualSense)
           if (device.name.Contains("DualSense"))
           {
               // Lee el Vector2 completo del stick izquierdo
               Input_Steer = action_steer.action.ReadValue<Vector2>().x;
           }

           else Input_Steer = action_steer.action.ReadValue<float>();
       }

       else if (device == null || !device.name.Contains("DualSense")) Input_Steer = action_steer.action.ReadValue<float>();

       //--------------------------------------------------------------------------------------
       

       Input_Accel = ProcessAxis(action_accel.action.ReadValue<float>(), accelConfig);  // Procesamos el acelerador
       Input_Brake     = ProcessAxis(action_brake.action.ReadValue<float>(), brakeConfig);  // Procesamos el freno
       Input_Clutch    = ProcessAxis(action_clutch.action.ReadValue<float>(), clutchConfig);  // Procesamos el clutch
       Input_Handbrake = ProcessAxis(action_handbrake.action.ReadValue<float>(), handbrakeConfig);  // Procesamos el freno de mano

Why not just internally convert those vector 2 to floats?

Yeah, PlayStation controllers (DualSense, DualShock) report stick values as Vector2 since both X and Y axes are read together, while other controllers (like Xbox) might give direct float values when reading a single axis.

Your check for device.name.Contains(“DualSense”) makes sense, but it’s kinda redundant and messy. Instead of manually checking and converting, you can just ensure you always extract .x from the Vector2 regardless of the controller.

var steerInput = action_steer.action.ReadValue<Vector2>().x;
Input_Steer = steerInput; // Always using Vector2.x to avoid issues

This way, you standardize how the input is handled without unnecessary conditionals. If some controllers actually return a float, Unity should implicitly cast it to a Vector2 where Y = 0, so the .x still works fine.

Thanks a lot for the clarification. I’ll try what you say since that would be MUCH cleaner, but if xbx returns a float not sure if the Vector2.x won´t trown an exception. But worth trying. Will update once I confirm it works. TX!

1 Like

OK wow, not sure what is going on but uppon removing the pathing code, and ismply reading it as float, both ps4 and ps5 controllers are working. ! lol. And the console is not flooded with excepton saying a vector2 can´t be read as float. I wonder if I changed something in the input asset that makes unity works it’s magic behind scenes. Now the steering is set as an axis. Whatever! cleaner code! :smiley: