Hi!
I’m developing a multiplayer game for the first time. So, I have NO IDEA about how to do it.
I have a blueprint widget, which appears at the beginning of the game, where the player needs to set his/her name. When the player pressed the Enter key it runs:
By the way, I don’t know why it always appears an error in the Set Player Name
node. I have to delete it a create it every time.
I have created a custom PlayerState class header:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerState.h"
#include "OpenDoorPlayerState.generated.h"
/**
*
*/
UCLASS()
class MULTIPLAYERTEST_API AOpenDoorPlayerState : public APlayerState
{
GENERATED_BODY()
public:
virtual void OnRep_PlayerName() override;
UFUNCTION(BlueprintCallable)
virtual void SetPlayerName(const FString& S) override;
};
And the code:
#include "OpenDoorPlayerState.h"
void AOpenDoorPlayerState::OnRep_PlayerName()
{
Super::OnRep_PlayerName();
// Update The name in the widget on his head
}
void AOpenDoorPlayerState::SetPlayerName(const FString& S)
{
Super::SetPlayerName(S);
ENetMode NetMode = GetNetMode();
UE_LOG(LogTemp, Warning, TEXT("[ AOpenDoorPlayerState::SetPlayerName ] "));
}
Also, I have created a blueprint class that inherits from the above, BP_OpenDoorPlayerState
.
But, when I run the above blueprint code, on the client, it doesn’t call the OnRep_PlayerName
because the GetNetMode();
returns NM_Client
.
How can I make run OnRep_PlayerName
function?
I think the problem is that I don’t know how to run the blueprint code on the server.