Multiplayer Library
- Base:
- UBlueprintFunctionLibrary
- Type:
- UNMultiplayerLibrary / FNMultiplayerUtils
- Header File:
- NexusMultiplayer/Public/NMultiplayerLibrary.h
A handful of methods meant to support the building logic that works in multiplayer scenarios.
UFunctions​
Admin Functions​
Has Remote Players​
/**
* Does the current world have remotely connected clients to it?
* @remark Clients won't have remote connections, only the server will.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @return true/false if remote clients are found.
*/
static bool HasRemotePlayers(UObject* WorldContextObject);
Has Local Players Only​
/**
* Does the current world have locally connected clients only?
* @remark Couch Co-op.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @return true/false if only local clients are found.
*/
static bool HasLocalPlayersOnly(UObject* WorldContextObject);
Has GameState Authority​
/**
* Does the current callstack have GameState authority?
* @remark One of many ways to check if the logic is being operated on the host/server.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @return true/false if authority is found.
*/
static bool HasGameStateAuthority(UObject* WorldContextObject);
Has World Authority​
/**
* Does the current callstack have World authority?
* @remark Developer preference, use this to determine if logic is operating on the host.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @return true/false if authority is found.
*/
static bool HasWorldAuthority(UObject* WorldContextObject);
Is Server​
/**
* An explicit check that the network mode of the world is not NM_Client, thus either a listen server (w/ client) or a dedicated server.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @return true/false if the world is not operating in NM_Client mode.
*/
static bool IsServer(UObject* WorldContextObject);
Kick Player​
/**
* Kicks a player from a session.
* @remark This should be only called on the server or world owner.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @param PlayerState The target player to kick.
* @return Was the player able to be kicked? true/false.
*/
static bool KickPlayer(UObject* WorldContextObject, APlayerState* PlayerState);
warning
Will fail if not done by server/host.
Player Functions​
Get PlayerIdentifier🚧0.3.0🚧​
/**
* Get a player's unique identifier from the APlayerController.
* @param PlayerController The target APlayerController to use when querying for the player identification number.
* @return The player's identifier.
*/
static int32 GetPlayerIdentifier(const APlayerController* PlayerController)
Get First PlayerIdentifier🚧0.3.0🚧​
/**
* Get the first player's unique identifier.
* @param WorldContextObject An object to get the UWorld from.
* @return The player's identifier.
*/
static int32 GetFirstPlayerIdentifier(UObject* WorldContextObject);
Get Pawn From PlayerIdentifier🚧0.3.0🚧​
/**
* Get the APawn for the given player's unique identifier.
* @param WorldContextObject An object to get the UWorld from.
* @param PlayerIdentifier The target identifier to query for.
* @return If found, APawn, or nullptr.
*/
static APawn* GetPawnFromPlayerIdentifier(UObject* WorldContextObject, const int32 PlayerIdentifier);
Get PlayerController From PlayerIdentifier🚧0.3.0🚧​
/**
* Get the AActor for the given player's unique identifier.
* @param WorldContextObject An object to get the UWorld from.
* @param PlayerIdentifier The target identifier to query for.
* @return If found, AActor, or nullptr.
*/
static AActor* GetPlayerControllerFromPlayerIdentifier(UObject* WorldContextObject, const int32 PlayerIdentifier);
Utility Functions​
Is Multiplayer Test​
/**
* Is the current session created from the MultiplayerTest editor command?
* @return true/false if it is.
*/
static bool IsMultiplayerTest();
Ping​
/**
* Get the current ping to the host/server.
* @param WorldContextObject Object that provides the context of which world to operate in.
* @return The numerical ping (ms) to the session host.
*/
static float Ping(const UObject* WorldContextObject);