Solution found!
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:
- Go to UE4 Editor and make a C++ class that’s based off of PlayerController.
- Make an event dispatcher that you will broadcast from CPP and listen to from BP.
- Expose the event dispatcher to Blueprints
- Extend
OnRep_PlayerState()
which is a prebuilt function that gets called when PlayerState gets replicated. - Call
Super::OnRep_PlayerState();
to make sure prebuilt logic still gets executed since we are only extending the method - Broadcast the event dispatcher.
- Compile
- In BP, make your main PlayerController BP extend this class.
- 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();
}