APlayerState::SetUniqueId
#include "GameFramework/PlayerState.h"
Access: public
Description
Associates an online unique ID with this PlayerState and calls OnSetUniqueId to allow subclasses and the engine to react to the change.
Caveats & Gotchas
- • Calling this triggers OnSetUniqueId both on server and, once replicated, on all clients. If you need to set the ID without triggering that callback, write the underlying UniqueId member directly — but this bypasses all reactive logic.
- • A move-semantic overload (SetUniqueId(FUniqueNetIdRepl&&)) is also available for avoiding copies when constructing a new ID inline; prefer it when performance matters.
Signature
ENGINE_API void SetUniqueId(const FUniqueNetIdRepl& NewUniqueId) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| NewUniqueId | const FUniqueNetIdRepl& | The unique network ID to associate with this player. | — |
Return Type
void Example
Assign an online ID from the subsystem login result C++
void AMyGameMode::OnLoginComplete(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId)
{
if (bWasSuccessful)
{
AMyPlayerState* PS = GetPlayerState();
if (PS)
{
PS->SetUniqueId(FUniqueNetIdRepl(UserId.AsShared()));
}
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?