Local Player Subsystem (ULocalPlayerSubsystem)
A local player subsystem refers to a singleton object that exists alongside a ULocalPlayer instance. Essentially if you have a local player, you are guaranteed to have a local player subsystem.
What You Should Know
- If you have a
ULocalPlayer, you have aULocalPlayerSubsystem. - Subclassing the
ULocalPlayerSubsystemwill create it for the local player in your game. - The Subsystem has a method called
PlayerControllerChangedthat will fire when the local player receives a controller ULocalPlayerSubsysteminstances only exist on the client. They're a good candidate for UI or other systems if you have only a single local player.
Why it's Useful
a ULocalPlayerSubsystem is a useful construct if you need a singleton that has a lifetime tied to a local player. I personally like to tie user interface logic to a local player subsystem because without a local player to speak of, there's no need to render widgets for gameplay display.
Additional Notes
- You can centralize a lot of event driven behavior at the local player subsystem level like when the subsystem gets a new valid player controller
UUserWidgettypes can access a local player subsystem easily usingUserWidget->GetOwningLocalPlayer()since they're typically associated with a local player when created- Using
CreateWidgetwith an owner that is a particular Player Controller will wire a widget up such that calling for the owning local player will return the correctULocalPlayer
- Using
