How do I get Enhanced Input Local Player Subsystem without accessing Player Controller in C++?

Hello,
I’ve been searching for some time and seen quite a lot of topics about how to get UEnhancedInputLocalPlayerSubsystem, but they all seem to involve PlayerController in some way (or at least getting the current UWorld).
Now, I might be totally misunderstanding something, but this is what I’ve got and what I’m planning to do.
I am making a main menu where the player will be able to change key mappings. I’ve done this in BP first, but now I want to do it in C++.
In BP it was more or less straightforward: simply get Enhanced Input Local Player Subsystem and then do the remapping there - there was no need to reference any World or LocalPlayer.
In c++ however, in order to get UEnhancedInputLocalPlayerSubsystem, all the solutions that I’ve seen require a reference to the ULocalPlayer, which in turn requires referencing a UWorld.

Now, in C++ file (UMyGameUserSettings.h/cpp - derived from UGameUserSettings) I don’t have any reference to the LocalPlayer or any World - these are just user settings, which are supposed to work globally in any world, I really don’t get it. Even if I wanted to, how am I supposed to get UWorld or LocalPlayer in UserSettings?

Hello!
Firstly, I want to stress that your title mentions the “Player Controller”, but as you correctly point out in your post’s body, it’s actually from the “Local Player” that you can get the UEnhancedInputLocalPlayerSubsystem.

As its name indicates, it’s a child class of ULocalPlayerSubsystem.

Next: The LocalPlayer is not tied to a specific PlayerController, it’s just that for most use cases people are fine with accessing it this way, I guess..

And it’s not tied to the world either!

For instance, quickly looking at UE’s source code, the Game Instance also contains a reference to the local players, and since the game instance is a singleton (that persists between level transitions), you could absolutely access it from your settings class, or from anywhere else.

Example code:

ULocalPlayer* NewLocalPlayer = GetGameInstance().GetLocalPlayerByIndex(LocalUserNum);