Skip to content

Instantly share code, notes, and snippets.

@Delaunay
Created April 22, 2023 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Delaunay/28c06034214ae68736173a05c80b78c5 to your computer and use it in GitHub Desktop.
Save Delaunay/28c06034214ae68736173a05c80b78c5 to your computer and use it in GitHub Desktop.
GKFogOfWarPawn.patch
diff --git a/Source/GKFogOfWar/Public/GKFogOfWarPawn.h b/Source/GKFogOfWar/Public/GKFogOfWarPawn.h
index b7d940c..33eda34 100644
--- a/Source/GKFogOfWar/Public/GKFogOfWarPawn.h
+++ b/Source/GKFogOfWar/Public/GKFogOfWarPawn.h
@@ -8,13 +8,16 @@
// Unreal Engine
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
+#include "Net/UnrealNetwork.h"
// Generated
#include "GKFogOfWarPawn.generated.h"
UCLASS()
-class GKFOGOFWAR_API AGKFogOfWarPawn : public APawn, public IGKFogOfWarAgentInterface
+class GKFOGOFWAR_API AGKFogOfWarPawn : public APawn,
+ public IGKFogOfWarAgentInterface,
+ public IGenericTeamAgentInterface
{
GENERATED_BODY()
@@ -37,6 +40,51 @@ public:
return FoWComponent;
}
+ // >>>>>> Begin
+ void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override {
+ Super::GetLifetimeReplicatedProps(OutLifetimeProps);
+ DOREPLIFETIME(AGKFogOfWarPawn, Team);
+ }
+
+ bool IsReplicationPausedForConnection(const FNetViewer& ConnectionOwnerNetViewer) override
+ {
+ TObjectPtr<AActor> ViewTarget = ConnectionOwnerNetViewer.ViewTarget;
+
+ if (FoWComponent && ViewTarget) {
+ return !FoWComponent->IsVisibleBy(ViewTarget);
+ }
+
+ return false;
+ }
+
+ //! Retrieve team identifier in form of FGenericTeamId
+ UFUNCTION(BlueprintPure, Category = "Team")
+ FGenericTeamId GetGenericTeamId() const override {
+ return Team;
+ }
+
+ //! This is set by the Player Controller on possession
+ UPROPERTY(Replicated, EditAnywhere, BlueprintReadOnly, Category = "Team")
+ FGenericTeamId Team;
+
+ void OnReplicationPausedChanged(bool bIsReplicationPaused) override {
+ bool bIsVisible = !bIsReplicationPaused;
+
+ if (bIsVisible)
+ {
+ SetActorHiddenInGame(false);
+ SetActorEnableCollision(true);
+ SetActorTickEnabled(true);
+ }
+ else
+ {
+ SetActorHiddenInGame(true);
+ SetActorEnableCollision(false);
+ SetActorTickEnabled(false);
+ }
+ }
+
+ // <<<<< End
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FogOfWar")
class UGKFogOfWarComponent* FoWComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment