Suggesting - Exposing device assignment to player controllers and input rerouting

wonka007
Mon, 28 Apr 2025 10:53:47 +0000
Feedback & Requests

I have a suggestion for future upgrades to enhanced input.

It would be nice if there were an easy way to query and then reassign input devices to player controllers.

I imagine something built over IPlatformInputDeviceMapper. The user could reroute input events from the device to controllers, which would use regular enhanced input. This way, one event could be sent to multiple controllers, allowing for easy one keyboard multiplayer or even splitting gamepad (overcooked style). There could be more complex setups that would filter keys/buttons for an individual controller.

I have created a simple pseudo-code that demonstrates how rerouting could work. The device would be split into slots which each could be assigned to one controller. This way controller can share the device with another controller, or one controller can have multiple devices assigned to it. I imagine that would be helpful for setups like plane simulators. The index of the slot can be used to differentiate between the players using that device.

struct InputDevice{
    FInputDeviceId deviceId;

    bool IsGamepad(){...}

    //etc.
    //...
};

struct InputSlot{
    PlayerController* connectedController;
};

struct DeviceSlotContainer{

    bool deviceConnected = false;
    TMap<uint32_t, InputSlot> m_slots;
};

class inputDeviceRemapper{

protected:
    TMap<FInputDeviceId, DeviceSlotContainer> m_devices;

public:

    //Reroute input into slots
    void OnInputKey(FInputDeviceId InputDevice, InputEvent event){
        if(DeviceSlotContainer* container = m_devices.FInd(InputDevice)){
            for(const TPair<FInputDeviceId, InputSlot>& item : caontainer.m_slots){

                if(item.Value.connectedController){
                    //Send input to be processed by EnhancedInput
                    item.Value.connectedController.ProcessInput(event, item.key);
                }
            }
        }
    }

    void OnDeviceConnected(InputDevice device){
        DeviceSlotContainer* container = m_devices.Find(device.deviceId);
        if(container){
            container.deviceConnected = true;

            for(const TPair<FInputDeviceId, InputSlot>& item : caontainer.m_slots){

                if(item.connectedController)
            }
        }
    }


    void OnDeviceDisconnected(InputDevice device){
        /* Similar to OnDeviceConnected, but player controller
         * stays connected for easy recovery after unplugging the input device
         */
    }


    bool RegisterController(FInputDeviceId deviceId, int32_t slotIndex, PlayerController* controller){
        if(DeviceSlotContainer* container = m_devices.Find(deviceId)){
            if(InputSlot* slot = container.Find(slotIndex)){
                if(slot.connectedController != controller){
                    //Slot already used by a different controller
                    return false;
                }
                else{
                    //Slot already registered by this controller
                    return true;
                }
            }
            else{
                container.Add({slotIndex, InputSlot(controller)});
                return true;
            }
        }
    }


    bool UnregisterController(FInputDeviceId deviceId, int32_t slotIndex, PlayerController* controller){
        //Similar to RegisterController
    }


    //Remove all slots that are using this controller
    bool UnregisterController(PlayerController* controller){
        //Search for slots with this controller and set the connectedController to nullptr
    }


    //Other functions for querying input devices and slots.
}

What do you think? How much outrageously stupid idea is this?
I think it would make creating local multiplayer much easier, and I do not know any way to achieve a similar result without replacing GameViewportClient, which is not wanted in my opinion, because for example, CommonUI needs to use its own client.

1 post - 1 participant