JaydenMaalouf / JoystickPlugin

Native Input Joystick Plugin for Unreal Engine 4/5
MIT License
30 stars 6 forks source link

SDL device name doesn't seem to appear properly on Linux, and double input registering happens with DualSense controllers. #53

Closed KingKrouch closed 7 months ago

KingKrouch commented 10 months ago

Hi! I wanted to write about an issue that I'm currently facing with the plugin (at least with the sensor-implementation branch which supports UE5) where my DualSense controller appears under a generic joystick name titled "Joystick" (at least under Linux, I do not have a Windows install currently to test this on), and there's seemingly a double input related issue where the original controller device is not being hidden from Unreal. From what I've seen from other things using SDL2, they seemingly detect my controller type fine, which makes the issue a bit more strange.

Interestingly, even when I don't use the plugin, at least on Linux, my DualSense controller seems to behave similarly to an XInput controller, with a Platform and User Device ID of 0, so I don't know if there's anything inherently wrong with how Unreal handles input on Linux now, but I can at least confirm that I was able to recreate the issue using a Ubuntu Live USB to make sure that my Fedora KDE setup wasn't just weird:

image

I also wonder if there's any C++ or Blueprints related functionality for the plugin that allows you to grab the current controller type, such as in the case where you may want to run a check that changes controller prompt UI elements from say Xbox to PlayStation equivalents.

JaydenMaalouf commented 10 months ago

I believe DualSense controllers work out of the box with Linux - therefore, they may be being added to the Unreal Gamepad controller as well as this plugins Joystick controller

You can disable this plugin from picking up gamepads by enabling Ignore Game Controllers image Then just use the standard Unreal Gamepad as if it were an XInput type device

If that doesn't work, or you'd actually prefer this plugin to handle the DualSense input Simply leave the Ignore Game Controllers setting unticked and consume the input of the Joystick input image

Also, if you are wanting the device name in the input (to have specific inputs for this device), you can do that by enabling Use Device Name image

The reason for the generic "Joystick" as default, is so that developers can release their game with automatic support for multiple devices, not just those that they've been developing on

KingKrouch commented 10 months ago

Also, if you are wanting the device name in the input (to have specific inputs for this device), you can do that by enabling Use Device Name image

The reason for the generic "Joystick" as default, is so that developers can release their game with automatic support for multiple devices, not just those that they've been developing on

Thanks for the suggestion. Enabling the "Use Device Name" option did the trick, and it recognizes the controller as a PS5Controller now.

I do wonder, since you did mention that the joystick naming scheme is done by default, if there's something planned that could expose some sort of functionality to Blueprints and C++ that could let developers grab the currently used connected controller's properties (in the settings under connected devices) alongside possibly with the other properties.

KingKrouch commented 10 months ago

Regarding the controller properties thing, from what I see, in JoystickInformation.h, there's some BlueprintReadOnly UProperties that are under the category "Device Config", but I don't think they appear in the Blueprtints editor at the moment.

iridescenthsn commented 9 months ago

hi. I think I have a similar problem. I need to have Use Device Name turned on so whenever a button is pressed, I can get the device name and update my game UI accordingly(Xbox/Playstation/PC). The problem is whenever I turn Use Device Name on, binding doesnt work image as you can see it just says "Joystick_PS4" or "Joystick_Xbox" and they dont work in game either. However the buttons do get triggered in "any key" node

I cant turn Use Device Name off as there seems to be no other way to tell what controller is being used at the moment.

iridescenthsn commented 9 months ago

I was able to solve my problem like this:

in JoystickInputDevice.h I added JOYSTICKPLUGIN_API before the class name: class JOYSTICKPLUGIN_API FJoystickInputDevice final : public IInputDevice

then I made this function:

FString UGameplayHelpers::GetInputDeviceNameByKey(const FKey& Key)
{
    UJoystickSubsystem* JoystickSubsystem = GEngine->GetEngineSubsystem<UJoystickSubsystem>();
    if (!IsValid(JoystickSubsystem))
    {
        return "";
    }

    const FJoystickInputDevice* InputDevice = JoystickSubsystem->GetInputDevice();
    if (InputDevice == nullptr)
    {
        return "";
    }

    FJoystickInformation DeviceInfo;
    const FJoystickInstanceId& InstanceId = InputDevice->GetInstanceIdByKey(Key);
    const bool Result = JoystickSubsystem->GetJoystickInfo(InstanceId, DeviceInfo);
    if (Result == false)
    {
        return "";
    }

    return DeviceInfo.DeviceName;
}

this function takes a Key and gives you the device name it is from. because of this there was no need to turn on Use Device Name (at least for me)

JaydenMaalouf commented 7 months ago

I was able to solve my problem like this:

in JoystickInputDevice.h I added JOYSTICKPLUGIN_API before the class name:

class JOYSTICKPLUGIN_API FJoystickInputDevice final : public IInputDevice

then I made this function:


FString UGameplayHelpers::GetInputDeviceNameByKey(const FKey& Key)

{

  UJoystickSubsystem* JoystickSubsystem = GEngine->GetEngineSubsystem<UJoystickSubsystem>();

  if (!IsValid(JoystickSubsystem))

  {

      return "";

  }

  const FJoystickInputDevice* InputDevice = JoystickSubsystem->GetInputDevice();

  if (InputDevice == nullptr)

  {

      return "";

  }

  FJoystickInformation DeviceInfo;

  const FJoystickInstanceId& InstanceId = InputDevice->GetInstanceIdByKey(Key);

  const bool Result = JoystickSubsystem->GetJoystickInfo(InstanceId, DeviceInfo);

  if (Result == false)

  {

      return "";

  }

  return DeviceInfo.DeviceName;

}

this function takes a Key and gives you the device name it is from. because of this there was no need to turn on Use Device Name (at least for me)

I've been a bit out of action but wanting to pick this plugin back up and get the latest release out soon

If you want this change added, I would be happy if you want to raise a PR to add this in! Let me know, otherwise I can add it on your behalf

JaydenMaalouf commented 7 months ago

Hey all, I released a new version of the plugin (3.3.0) Which contains a fix for the incorrect key mapping! I will close this issue off until it's confirmed to be working