Adding Fog of War to an Actor

Setup fog of war in C++

For this tutorial, I already created a new actor (you can follow this documentationarrow-up-right) for fog of war component and it is called MySampleActor.

I'll be adding the fog of war component at begin play so in MySampleActor.h file, let's first declare like this:

// On top of your header (above UCLASS) forward declare the class
class UAgoraFogOfWarComponent;

...

UPROPERTY(Transient)
TObjectPtr<UAgoraFogOfWarComponent> FogOfWarComponent;

UPROPERTY(EditAnywhere)
float FogRadius = 3000.f;

virtual void BeginPlay() override;

Then in MySampleActor.cpp file lets define BeginPlay and add set our component.

#include "AgoraFogOfWarComponent.h"
#include "AgoraFogOfWarStatics.h"

void AMySampleActor::BeginPlay()
{
    Super::BeginPlay();
    UFogOfWarStatics::SetMapSize(10000.f);
    FogOfWarComponent = UAgoraFogOfWarStatics::AddFogOfWarComponentToActor(this);
    UAgoraFogOfWarStatics::SetFogRadius(FogOfWarComponent, FogRadius);
    FogOfWarComponent->Activate();
}

That's all you need to setup fog of war for an actor in C++ πŸ™‚

Last updated