Update 2 - C++
Update 2: The code.
It was pretty quick to implement, since I just needed to follow what I’ve made in Blueprints.
Events Handler Component:
.h
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class SHOOTERGAME_API USF_EventsHandlerComponent : public UActorComponent
{
GENERATED_BODY()
public:
....
virtual void SendMessageTo(EMessageType Message, APlayerState* Player);
};
.cpp - in my case, the Client call is a function inside the Player Controller defined as UFUNCTION(client, reliable).
void USF_EventsHandlerComponent::SendMessageTo(EMessageType Message, APlayerState* Player)
{
if (!Player)
{
return;
}
AShooterPlayerController* PC = Cast<AShooterPlayerController>(Player->GetOwner());
if (PC)
{
if (Message == EMessageType::MT_WarningMessage)
{
PC->ClientCall();
}
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, "Invalid PlayerController for Event", false);
}
}
**Interface **- used to avoid dependencies and casting
.h
UENUM(BlueprintType)
enum class EMessageType: uint8
{
MT_WarningMessage UMETA(DisplayName = "Warning Message")
};
...
class SHOOTERGAME_API ISF_EventsHandler
{
GENERATED_IINTERFACE_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interface")
void WarningMessageTo(APlayerState* Player, EMessageType Message);
};
GameMode
.h
UCLASS()
class SHOOTERGAME_API ASF_GameModeTeamDeathmatch : public AShooterGame_TeamDeathMatch, public ISF_EventsHandler
{
GENERATED_BODY()
....
UPROPERTY()
USF_EventsHandlerComponent* EventsHandler;
UFUNCTION(BlueprintCallable, Category = "Energy Interface")
virtual void WarningMessageTo_Implementation(APlayerState* Player, EMessageType Message);
};
.cpp
ASF_GameModeTeamDeathmatch::ASF_GameModeTeamDeathmatch(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
....
EventsHandler = CreateDefaultSubobject<USF_EventsHandlerComponent>("EventsHandler");
}
void ASF_GameModeTeamDeathmatch::WarningMessageTo_Implementation(APlayerState* Player, EMessageType Message)
{
EventsHandler->SendMessageTo(Message, Player);
}
Inside the PlayerController class, the ClientCall function will run as a Client RPC.
There’s just one thing left I could not identically reproduce and I had to workaround by defining the ClientCall function to call another method that can be finally overriden in blueprints, cause I could not make a Client RPC function overrideable in Blueprints so far.
For this, I’ve already posted in answerhub and hope someone could clarify this to me.
Well, tested and working inside c++.