PlayerState returns None on Client's Controller

Solution found!

https://api.unrealengine.com/INT/API/Runtime/Engine/GameFramework/AController/OnRep_PlayerState/index.html

:slight_smile:

This will make your dreams come true. It fixed a lot of issues for me. This is a function that gets called when PlayerState is replicated. You can make an event out of this and notify your code that PlayerState has been replicated in Blueprints.

Bad news: It’s not exposed in BP. So you need to expose it yourself using some C++.

Good news: It’s very easy to do so.

For C++ programmers this should be easy so this is for BP devs:

  1. Go to UE4 Editor and make a C++ class that’s based off of PlayerController.
  2. Make an event dispatcher that you will broadcast from CPP and listen to from BP.
  3. Expose the event dispatcher to Blueprints
  4. Extend OnRep_PlayerState() which is a prebuilt function that gets called when PlayerState gets replicated.
  5. Call Super::OnRep_PlayerState(); to make sure prebuilt logic still gets executed since we are only extending the method
  6. Broadcast the event dispatcher.
  7. Compile
  8. In BP, make your main PlayerController BP extend this class.
  9. Bind to this event. It should be called according to how you named your event dispatcher variable.

It should look something like this:

// MasterPlayerController.h
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "MasterPlayerController.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRepPlayerState);

/**
 * 
 */
UCLASS()
class KRIEG_API AMasterPlayerController : public APlayerController
{
	GENERATED_BODY()

public:
	
	void OnRep_PlayerState() override;

	UPROPERTY(BlueprintAssignable, BlueprintCallable)
	FRepPlayerState RepPlayerState;
};



// MasterPlayerController.cpp

#include "MasterPlayerController.h"

void AMasterPlayerController::OnRep_PlayerState()
{
	Super::OnRep_PlayerState();
	RepPlayerState.Broadcast();
}

@GTNardy

5 Likes