Major Change - Rework how Cog gets integrated

Cog integration has been reworked to make it easier,  to keep Cog available between level loadings, and to properly tick ImGui while the game is paused.
Cog 's WindowManager is now a GameInstanceSubsystem.
The WindowManager ticks ImGui and the windows during the OnWorldPostActorTick delegate.
(If this is not working for your project, don't hesitate to open an issue.)

Check the readme to see how to integrate Cog.

The Plot debug functions (displayed by the Engine/Plot window) have been reworked as they were not properly working in Multi PIE in Single Process.

API changes:
- use FCogDebug::Plot instead of FCogDebugPlot::PlotValue
- use FCogDebug::InstantEvent  instead of FCogDebugPlot::PlotEventInstant
- use FCogDebug::StartEvent instead of FCogDebugPlot::PlotEventStart
- use FCogDebug::StopEvent instead of FCogDebugPlot::PlotEventStop
This commit is contained in:
Arnaud Jamin
2025-02-11 13:29:12 -05:00
parent 357bd9974e
commit 6d9494b685
40 changed files with 1618 additions and 1480 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
#include "Components/SkeletalMeshComponent.h"
#if ENABLE_COG
#include "CogDebugPlot.h"
#include "CogDebug.h"
#endif
//--------------------------------------------------------------------------------------------------------------------------
@@ -22,7 +22,7 @@ void UCogSampleAnimNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenc
Super::Notify(MeshComp, Animation, EventReference);
#if ENABLE_COG
FCogDebugPlot::PlotEventInstant(MeshComp->GetOwner(), "Anim Notify", GetFName())
FCogDebug::InstantEvent(MeshComp->GetOwner(), "Anim Notify", GetFName())
.AddParam("Name", GetNameSafe(this))
.AddParam("Animation", GetNameSafe(Animation))
.AddParam("Debug Info", GetDebugInfo());
@@ -8,7 +8,7 @@
#include "Components/SkeletalMeshComponent.h"
#if ENABLE_COG
#include "CogDebugPlot.h"
#include "CogDebug.h"
#endif
//--------------------------------------------------------------------------------------------------------------------------
@@ -22,7 +22,7 @@ UCogSampleAnimNotifyState::UCogSampleAnimNotifyState(const FObjectInitializer& O
void UCogSampleAnimNotifyState::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, const FAnimNotifyEventReference& EventReference)
{
#if ENABLE_COG
FCogDebugPlot::PlotEventStart(MeshComp->GetOwner(), "Anim Notify", GetFName())
FCogDebug::StartEvent(MeshComp->GetOwner(), "Anim Notify", GetFName())
.AddParam("Name", GetNameSafe(this))
.AddParam("Animation", GetNameSafe(Animation))
.AddParam("Debug Info", GetDebugInfo());
@@ -35,7 +35,7 @@ void UCogSampleAnimNotifyState::NotifyBegin(USkeletalMeshComponent* MeshComp, UA
void UCogSampleAnimNotifyState::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference)
{
#if ENABLE_COG
FCogDebugPlot::PlotEventStop(MeshComp->GetOwner(), "Anim Notify", GetFName());
FCogDebug::StopEvent(MeshComp->GetOwner(), "Anim Notify", GetFName());
#endif
Super::NotifyEnd(MeshComp, Animation, EventReference);
+5 -5
View File
@@ -27,7 +27,7 @@
#if ENABLE_COG
#include "CogAbilityReplicator.h"
#include "CogDebugMetric.h"
#include "CogDebugPlot.h"
#include "CogDebug.h"
#endif //ENABLE_COG
//--------------------------------------------------------------------------------------------------------------------------
@@ -402,7 +402,7 @@ void ACogSampleCharacter::OnAbilityInputStarted(const UInputAction* InputAction,
COG_LOG_OBJECT(LogCogInput, ELogVerbosity::Verbose, this, TEXT("%d"), Index);
#if ENABLE_COG
FCogDebugPlot::PlotEventStart(this, "Input", InputAction->GetFName());
FCogDebug::StartEvent(this, "Input", InputAction->GetFName());
#endif
if (ActiveAbilityHandles.IsValidIndex(Index) == false)
@@ -450,7 +450,7 @@ void ACogSampleCharacter::OnAbilityInputCompleted(const UInputAction* InputActio
COG_LOG_OBJECT(LogCogInput, ELogVerbosity::Verbose, this, TEXT("%d"), Index);
#if ENABLE_COG
FCogDebugPlot::PlotEventStop(this, "Input", InputAction->GetFName());
FCogDebug::StopEvent(this, "Input", InputAction->GetFName());
#endif
if (ActiveAbilityHandles.IsValidIndex(Index) == false)
@@ -631,7 +631,7 @@ void ACogSampleCharacter::OnRevived(AActor* InInstigator, AActor* InCauser, cons
void ACogSampleCharacter::OnGameplayEffectAdded(UAbilitySystemComponent* AbilitySystemComponent, const FGameplayEffectSpec& GameplayEffectSpec, FActiveGameplayEffectHandle Handle)
{
#if ENABLE_COG
FCogDebugPlot::PlotEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f)
FCogDebug::StartEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f)
.AddParam("Name", AbilitySystemComponent->CleanupName(GetNameSafe(GameplayEffectSpec.Def)))
.AddParam("Effect Instigator", GetNameSafe(GameplayEffectSpec.GetEffectContext().GetInstigator()))
.AddParam("Effect Level", GameplayEffectSpec.GetLevel())
@@ -643,7 +643,7 @@ void ACogSampleCharacter::OnGameplayEffectAdded(UAbilitySystemComponent* Ability
void ACogSampleCharacter::OnGameplayEffectRemoved(const FActiveGameplayEffect& RemovedGameplayEffect)
{
#if ENABLE_COG
FCogDebugPlot::PlotEventStop(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName());
FCogDebug::StopEvent(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName());
#endif //ENABLE_COG
}
@@ -11,7 +11,7 @@
#if ENABLE_COG
#include "CogDebugDraw.h"
#include "CogDebugPlot.h"
#include "CogDebug.h"
#endif //ENABLE_COG
//--------------------------------------------------------------------------------------------------------------------------
@@ -226,10 +226,10 @@ void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum E
if (FCogDebug::IsDebugActiveForObject(GetPawnOwner()))
{
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input X", GetPendingInputVector().X);
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Y", GetPendingInputVector().Y);
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Local X", FVector::DotProduct(GetPawnOwner()->GetActorRightVector(), GetPendingInputVector()));
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Local Y", FVector::DotProduct(GetPawnOwner()->GetActorForwardVector(), GetPendingInputVector()));
FCogDebug::Plot(Character, "Move Input X", GetPendingInputVector().X);
FCogDebug::Plot(Character, "Move Input Y", GetPendingInputVector().Y);
FCogDebug::Plot(Character, "Move Input Local X", FVector::DotProduct(GetPawnOwner()->GetActorRightVector(), GetPendingInputVector()));
FCogDebug::Plot(Character, "Move Input Local Y", FVector::DotProduct(GetPawnOwner()->GetActorForwardVector(), GetPendingInputVector()));
}
#endif //ENABLE_COG
@@ -250,29 +250,29 @@ void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum E
const FVector VelocityDelta = (Velocity - DebugLastVelocity) / DeltaTime;
const FVector LocalVelocityDelta = Rotation.UnrotateVector(VelocityDelta);
FCogDebugPlot::PlotValue(Character, "Location X", DebugBottomLocation.X);
FCogDebugPlot::PlotValue(Character, "Location Y", DebugBottomLocation.Y);
FCogDebugPlot::PlotValue(Character, "Location Z", DebugBottomLocation.Z);
FCogDebugPlot::PlotValue(Character, "Rotation Yaw", Character->GetActorRotation().Yaw);
FCogDebugPlot::PlotValue(Character, "Acceleration X", GetCurrentAcceleration().X);
FCogDebugPlot::PlotValue(Character, "Acceleration Y", GetCurrentAcceleration().Y);
FCogDebugPlot::PlotValue(Character, "Acceleration Z", GetCurrentAcceleration().Z);
FCogDebugPlot::PlotValue(Character, "Acceleration Local X", LocalAcceleration.X);
FCogDebugPlot::PlotValue(Character, "Acceleration Local Y", LocalAcceleration.Y);
FCogDebugPlot::PlotValue(Character, "Acceleration Local Z", LocalAcceleration.Z);
FCogDebugPlot::PlotValue(Character, "Velocity X", Velocity.X);
FCogDebugPlot::PlotValue(Character, "Velocity Y", Velocity.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Z", Velocity.Z);
FCogDebugPlot::PlotValue(Character, "Velocity Local X", LocalVelocity.X);
FCogDebugPlot::PlotValue(Character, "Velocity Local Y", LocalVelocity.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Local Z", LocalVelocity.Z);
FCogDebugPlot::PlotValue(Character, "Velocity Delta X", VelocityDelta.X);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Y", VelocityDelta.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Z", VelocityDelta.Z);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Local X", LocalVelocityDelta.X);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Local Y", LocalVelocityDelta.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Local Z", LocalVelocityDelta.Z);
FCogDebugPlot::PlotValue(Character, "Speed", Velocity.Length());
FCogDebug::Plot(Character, "Location X", DebugBottomLocation.X);
FCogDebug::Plot(Character, "Location Y", DebugBottomLocation.Y);
FCogDebug::Plot(Character, "Location Z", DebugBottomLocation.Z);
FCogDebug::Plot(Character, "Rotation Yaw", Character->GetActorRotation().Yaw);
FCogDebug::Plot(Character, "Acceleration X", GetCurrentAcceleration().X);
FCogDebug::Plot(Character, "Acceleration Y", GetCurrentAcceleration().Y);
FCogDebug::Plot(Character, "Acceleration Z", GetCurrentAcceleration().Z);
FCogDebug::Plot(Character, "Acceleration Local X", LocalAcceleration.X);
FCogDebug::Plot(Character, "Acceleration Local Y", LocalAcceleration.Y);
FCogDebug::Plot(Character, "Acceleration Local Z", LocalAcceleration.Z);
FCogDebug::Plot(Character, "Velocity X", Velocity.X);
FCogDebug::Plot(Character, "Velocity Y", Velocity.Y);
FCogDebug::Plot(Character, "Velocity Z", Velocity.Z);
FCogDebug::Plot(Character, "Velocity Local X", LocalVelocity.X);
FCogDebug::Plot(Character, "Velocity Local Y", LocalVelocity.Y);
FCogDebug::Plot(Character, "Velocity Local Z", LocalVelocity.Z);
FCogDebug::Plot(Character, "Velocity Delta X", VelocityDelta.X);
FCogDebug::Plot(Character, "Velocity Delta Y", VelocityDelta.Y);
FCogDebug::Plot(Character, "Velocity Delta Z", VelocityDelta.Z);
FCogDebug::Plot(Character, "Velocity Delta Local X", LocalVelocityDelta.X);
FCogDebug::Plot(Character, "Velocity Delta Local Y", LocalVelocityDelta.Y);
FCogDebug::Plot(Character, "Velocity Delta Local Z", LocalVelocityDelta.Z);
FCogDebug::Plot(Character, "Speed", Velocity.Length());
const FVector Delta = DebugBottomLocation - DebugLastBottomLocation;
const FColor Color = DebugIsPositionCorrected ? FColor::Blue : FColor::Yellow;
@@ -0,0 +1,24 @@
#include "CogSampleGameInstance.h"
#include "CogCommon.h"
#if ENABLE_COG
#include "CogAll.h"
#include "CogSampleWindow_Team.h"
#include "CogWindowManager.h"
#endif
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleGameInstance::Init()
{
Super::Init();
#if ENABLE_COG
if (UCogWindowManager* CogSubSystem = GetSubsystem<UCogWindowManager>())
{
Cog::AddAllWindows(*CogSubSystem);
CogSubSystem->AddWindow<FCogSampleWindow_Team>("Gameplay.Team");
}
#endif
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include "CoreMinimal.h"
#include "CogSampleGameInstance.generated.h"
class UCogWindowManager;
class UCogSampleAbilitySystemComponent;
UCLASS()
class UCogSampleGameInstance : public UGameInstance
{
GENERATED_BODY()
virtual void Init() override;
};
+9 -35
View File
@@ -8,7 +8,6 @@
#if ENABLE_COG
#include "CogAll.h"
#include "CogDebugPlot.h"
#include "CogSampleWindow_Team.h"
#include "CogWindowManager.h"
#endif //ENABLE_COG
@@ -40,31 +39,12 @@ void ACogSampleGameState::BeginPlay()
Super::BeginPlay();
AbilitySystemComponent->InitAbilityActorInfo(this, this);
#if ENABLE_COG
CogWindowManager = NewObject<UCogWindowManager>(this);
CogWindowManagerRef = CogWindowManager;
// Add all the built-in windows
Cog::AddAllWindows(*CogWindowManager);
// Add a custom window
CogWindowManager->AddWindow<FCogSampleWindow_Team>("Gameplay.Team");
#endif //ENABLE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
#if ENABLE_COG
if (CogWindowManager != nullptr)
{
CogWindowManager->Shutdown();
}
#endif //ENABLE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -88,10 +68,10 @@ void ACogSampleGameState::Tick(float DeltaSeconds)
if (GetLocalRole() != ROLE_Authority)
{
FCogDebugPlot::PlotValue(this, "Frame Rate Client Raw", GAverageFPS);
FCogDebugPlot::PlotValue(this, "Frame Rate Client Smooth", _ClientFramerateSmooth);
FCogDebugPlot::PlotValue(this, "Frame Rate Server Raw", _ServerFramerateRaw);
FCogDebugPlot::PlotValue(this, "Frame Rate Server Smooth", _ServerFramerateSmooth);
FCogDebug::Plot(this, "Frame Rate Client Raw", GAverageFPS);
FCogDebug::Plot(this, "Frame Rate Client Smooth", _ClientFramerateSmooth);
FCogDebug::Plot(this, "Frame Rate Server Raw", _ServerFramerateRaw);
FCogDebug::Plot(this, "Frame Rate Server Smooth", _ServerFramerateSmooth);
if (const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController())
{
@@ -99,16 +79,16 @@ void ACogSampleGameState::Tick(float DeltaSeconds)
{
if (const APlayerState* PlayerState = PlayerController->GetPlayerState<APlayerState>())
{
FCogDebugPlot::PlotValue(this, "Ping", PlayerState->GetPingInMilliseconds());
FCogDebug::Plot(this, "Ping", PlayerState->GetPingInMilliseconds());
}
if (const UNetConnection* Connection = PlayerController->GetNetConnection())
{
FCogDebugPlot::PlotValue(this,
FCogDebug::Plot(this,
"Packet Loss In",
Connection->GetInLossPercentage().GetAvgLossPercentage() * 100.0f);
FCogDebugPlot::PlotValue(this,
FCogDebug::Plot(this,
"Packet Loss Out",
Connection->GetOutLossPercentage().GetAvgLossPercentage() * 100.0f);
}
@@ -117,14 +97,8 @@ void ACogSampleGameState::Tick(float DeltaSeconds)
}
else
{
FCogDebugPlot::PlotValue(this, "Frame Rate Raw", GAverageFPS);
FCogDebugPlot::PlotValue(this, "Frame Rate Smooth", _ClientFramerateSmooth);
}
if (CogWindowManager != nullptr)
{
CogWindowManager->Tick(DeltaSeconds);
FCogDebug::Plot(this, "Frame Rate Raw", GAverageFPS);
FCogDebug::Plot(this, "Frame Rate Smooth", _ClientFramerateSmooth);
}
#endif //ENABLE_COG
-2
View File
@@ -42,8 +42,6 @@ protected:
#if ENABLE_COG
void InitializeCog();
TObjectPtr<UCogWindowManager> CogWindowManager = nullptr;
float _ClientFramerateSmooth = 0.0f;
@@ -9,7 +9,7 @@
#include "CogSampleSpawnPredictionComponent.h"
#if ENABLE_COG
#include "CogDebugPlot.h"
#include "CogDebug.h"
#endif
//--------------------------------------------------------------------------------------------------------------------------
@@ -26,7 +26,7 @@ void UCogSampleGameplayAbility::PreActivate(const FGameplayAbilitySpecHandle Han
COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT(""));
FCogDebugPlot::PlotEventStart(this, "Ability", GetFName())
FCogDebug::StartEvent(this, "Ability", GetFName())
.AddParam("Name", GetNameSafe(this))
.AddParam("Owner", GetNameSafe(ActorInfo->OwnerActor.Get()))
.AddParam("Avatar", GetNameSafe(ActorInfo->AvatarActor.Get()))
@@ -58,7 +58,7 @@ void UCogSampleGameplayAbility::EndAbility(const FGameplayAbilitySpecHandle Hand
COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT(""));
FCogDebugPlot::PlotEventStop(this, "Ability", GetFName());
FCogDebug::StopEvent(this, "Ability", GetFName());
#endif
}