AGameStateBase::GetPlayerStateFromUniqueNetId
#include "GameFramework/GameStateBase.h"
Access: public
Specifiers: const
Description
Searches `PlayerArray` for the `APlayerState` matching the given unique net ID. Returns null if no match is found.
Caveats & Gotchas
- • This function is linear in the number of connected players (`O(n)` over `PlayerArray`). Avoid calling it every tick; cache the result when the player set is stable.
- • `FUniqueNetIdWrapper` can wrap an invalid ID — passing an uninitialized wrapper will always return null without crashing, but ensure the ID is valid before relying on the result.
Signature
ENGINE_API APlayerState* GetPlayerStateFromUniqueNetId(const FUniqueNetIdWrapper& InPlayerId) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InPlayerId | const FUniqueNetIdWrapper& | The platform-agnostic unique net ID to search for. | — |
Return Type
APlayerState* Example
Look up a player state from an online session result C++
FUniqueNetIdWrapper PlayerId = FUniqueNetIdWrapper(SessionResult.Session.OwningUserId);
if (APlayerState* PS = GameState->GetPlayerStateFromUniqueNetId(PlayerId))
{
UE_LOG(LogTemp, Log, TEXT("Found: %s"), *PS->GetPlayerName());
} See Also
Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?