fix: harden gameplay state transitions

This commit is contained in:
Christophe Del Vecchio committed 2026-10-01 12:43:29 +02:00
1 parent 26a204b49c
commit 914e2d5c9b
8 files changed
+305 -59

No files matched your search

+4
View File
@@ -40,6 +40,10 @@ ArchivedBuilds/
.DS_Store .DS_Store
._* ._*
# --- Python tooling ---
__pycache__/
*.py[cod]
# --- Per-developer content (keep Developers/ local) --- # --- Per-developer content (keep Developers/ local) ---
Content/Developers/ Content/Developers/
Content/Collections/ Content/Collections/
+96
View File
@@ -0,0 +1,96 @@
"""Fast regression checks for gameplay control-flow blockers.
These tests intentionally inspect the small C++ functions at issue. The Unreal
editor build remains the integration gate for syntax, types, and engine APIs.
"""
from pathlib import Path
import unittest
ROOT = Path(__file__).resolve().parents[2]
def source(relative_path: str) -> str:
return (ROOT / relative_path).read_text(encoding="utf-8")
def function_body(relative_path: str, signature: str) -> str:
text = source(relative_path)
start = text.index(signature)
open_brace = text.index("{", start)
depth = 0
for index in range(open_brace, len(text)):
if text[index] == "{":
depth += 1
elif text[index] == "}":
depth -= 1
if depth == 0:
return text[open_brace + 1:index]
raise AssertionError(f"Unclosed function body for {signature}")
class GameplayBlockerTests(unittest.TestCase):
def test_set_character_speed_finishes_synchronously(self):
body = function_body(
"Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp",
"FStateTreeSetCharacterSpeedTask::EnterState",
)
self.assertIn("return EStateTreeRunStatus::Succeeded;", body)
self.assertNotIn("return EStateTreeRunStatus::Running;", body)
def test_dash_commits_state_only_after_montage_starts(self):
body = function_body(
"Source/pogo/Variant_Platforming/PlatformingCharacter.cpp",
"void APlatformingCharacter::DoDash()",
)
self.assertIn("if (!AnimInstance || !DashMontage)", body)
self.assertIn("MontageLength <= 0.0f", body)
play = body.index("Montage_Play")
success_guard = body.index("MontageLength <= 0.0f")
state_commit = body.index("bIsDashing = true;")
self.assertLess(play, success_guard)
self.assertLess(success_guard, state_commit)
def test_attacks_commit_state_only_after_montage_starts(self):
cases = [
("Source/pogo/Variant_Combat/CombatCharacter.cpp", "void ACombatCharacter::ComboAttack()", False),
("Source/pogo/Variant_Combat/CombatCharacter.cpp", "void ACombatCharacter::ChargedAttack()", False),
("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "void ACombatEnemy::DoAIComboAttack()", True),
("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "void ACombatEnemy::DoAIChargedAttack()", True),
]
for path, signature, must_finish_state_tree in cases:
with self.subTest(signature=signature):
body = function_body(path, signature)
self.assertIn("MontageLength <= 0.0f", body)
play = body.index("Montage_Play")
success_guard = body.index("MontageLength <= 0.0f")
state_commit = body.index("bIsAttacking = true;")
self.assertLess(play, success_guard)
self.assertLess(success_guard, state_commit)
if must_finish_state_tree:
self.assertGreaterEqual(body.count("OnAttackCompleted.ExecuteIfBound();"), 2)
def test_side_scrolling_landed_calls_base_first(self):
body = function_body(
"Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp",
"void ASideScrollingCharacter::Landed(const FHitResult& Hit)",
)
self.assertIn("Super::Landed(Hit);", body)
self.assertLess(body.index("Super::Landed(Hit);"), body.index("bHasDoubleJumped = false;"))
def test_attack_traces_deduplicate_actors(self):
cases = [
("Source/pogo/Variant_Combat/CombatCharacter.cpp", "ACombatCharacter::DoAttackTrace"),
("Source/pogo/Variant_Combat/AI/CombatEnemy.cpp", "ACombatEnemy::DoAttackTrace"),
]
for path, signature in cases:
with self.subTest(signature=signature):
body = function_body(path, signature)
self.assertIn("TSet<AActor*> DamagedActors;", body)
self.assertIn("DamagedActors.Contains(HitActor)", body)
self.assertIn("DamagedActors.Add(HitActor);", body)
self.assertLess(body.index("DamagedActors.Add(HitActor);"), body.index("Damageable->ApplyDamage"))
if __name__ == "__main__":
unittest.main()
+41 -24
View File
@@ -50,7 +50,21 @@ void ACombatEnemy::DoAIComboAttack()
return; return;
} }
// raise the attacking flag UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (!AnimInstance || !ComboAttackMontage)
{
OnAttackCompleted.ExecuteIfBound();
return;
}
const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
if (MontageLength <= 0.0f)
{
OnAttackCompleted.ExecuteIfBound();
return;
}
// raise the attacking flag only after the montage starts
bIsAttacking = true; bIsAttacking = true;
// choose how many times we're going to attack // choose how many times we're going to attack
@@ -59,19 +73,9 @@ void ACombatEnemy::DoAIComboAttack()
// reset the attack counter // reset the attack counter
CurrentComboAttack = 0; CurrentComboAttack = 0;
// play the attack montage
if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance())
{
const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
// subscribe to montage completed and interrupted events
if (MontageLength > 0.0f)
{
// set the end delegate for the montage // set the end delegate for the montage
AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage); AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage);
} }
}
}
void ACombatEnemy::DoAIChargedAttack() void ACombatEnemy::DoAIChargedAttack()
{ {
@@ -81,7 +85,21 @@ void ACombatEnemy::DoAIChargedAttack()
return; return;
} }
// raise the attacking flag UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (!AnimInstance || !ChargedAttackMontage)
{
OnAttackCompleted.ExecuteIfBound();
return;
}
const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
if (MontageLength <= 0.0f)
{
OnAttackCompleted.ExecuteIfBound();
return;
}
// raise the attacking flag only after the montage starts
bIsAttacking = true; bIsAttacking = true;
// choose how many loops are we going to charge for // choose how many loops are we going to charge for
@@ -90,19 +108,9 @@ void ACombatEnemy::DoAIChargedAttack()
// reset the charge loop counter // reset the charge loop counter
CurrentChargeLoop = 0; CurrentChargeLoop = 0;
// play the attack montage
if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance())
{
const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
// subscribe to montage completed and interrupted events
if (MontageLength > 0.0f)
{
// set the end delegate for the montage // set the end delegate for the montage
AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage); AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage);
} }
}
}
void ACombatEnemy::AttackMontageEnded(UAnimMontage* Montage, bool bInterrupted) void ACombatEnemy::AttackMontageEnded(UAnimMontage* Montage, bool bInterrupted)
{ {
@@ -127,6 +135,7 @@ void ACombatEnemy::DoAttackTrace(FName DamageSourceBone)
{ {
// sweep for objects in front of the character to be hit by the attack // sweep for objects in front of the character to be hit by the attack
TArray<FHitResult> OutHits; TArray<FHitResult> OutHits;
TSet<AActor*> DamagedActors;
// start at the provided socket location, sweep forward // start at the provided socket location, sweep forward
const FVector TraceStart = GetMesh()->GetSocketLocation(DamageSourceBone); const FVector TraceStart = GetMesh()->GetSocketLocation(DamageSourceBone);
@@ -149,14 +158,22 @@ void ACombatEnemy::DoAttackTrace(FName DamageSourceBone)
// iterate over each object hit // iterate over each object hit
for (const FHitResult& CurrentHit : OutHits) for (const FHitResult& CurrentHit : OutHits)
{ {
AActor* HitActor = CurrentHit.GetActor();
if (!HitActor || DamagedActors.Contains(HitActor))
{
continue;
}
/** does the actor have the player tag? */ /** does the actor have the player tag? */
if (CurrentHit.GetActor()->ActorHasTag(FName("Player"))) if (HitActor->ActorHasTag(FName("Player")))
{ {
// check if the actor is damageable // check if the actor is damageable
ICombatDamageable* Damageable = Cast<ICombatDamageable>(CurrentHit.GetActor()); ICombatDamageable* Damageable = Cast<ICombatDamageable>(HitActor);
if (Damageable) if (Damageable)
{ {
DamagedActors.Add(HitActor);
// knock upwards and away from the impact normal // knock upwards and away from the impact normal
const FVector Impulse = (CurrentHit.ImpactNormal * -MeleeKnockbackImpulse) + (FVector::UpVector * MeleeLaunchImpulse); const FVector Impulse = (CurrentHit.ImpactNormal * -MeleeKnockbackImpulse) + (FVector::UpVector * MeleeLaunchImpulse);
@@ -240,7 +240,7 @@ EStateTreeRunStatus FStateTreeSetCharacterSpeedTask::EnterState(FStateTreeExecut
// set the character's max ground speed // set the character's max ground speed
InstanceData.Character->GetCharacterMovement()->MaxWalkSpeed = InstanceData.Speed; InstanceData.Character->GetCharacterMovement()->MaxWalkSpeed = InstanceData.Speed;
return EStateTreeRunStatus::Running; return EStateTreeRunStatus::Succeeded;
} }
#if WITH_EDITOR #if WITH_EDITOR
+36 -24
View File
@@ -190,7 +190,19 @@ void ACombatCharacter::ResetHP()
void ACombatCharacter::ComboAttack() void ACombatCharacter::ComboAttack()
{ {
// raise the attacking flag UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (!AnimInstance || !ComboAttackMontage)
{
return;
}
const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
if (MontageLength <= 0.0f)
{
return;
}
// raise the attacking flag only after the montage starts
bIsAttacking = true; bIsAttacking = true;
// reset the combo count // reset the combo count
@@ -199,24 +211,25 @@ void ACombatCharacter::ComboAttack()
// notify enemies they are about to be attacked // notify enemies they are about to be attacked
NotifyEnemiesOfIncomingAttack(); NotifyEnemiesOfIncomingAttack();
// play the attack montage
if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance())
{
const float MontageLength = AnimInstance->Montage_Play(ComboAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
// subscribe to montage completed and interrupted events
if (MontageLength > 0.0f)
{
// set the end delegate for the montage // set the end delegate for the montage
AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage); AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ComboAttackMontage);
} }
}
}
void ACombatCharacter::ChargedAttack() void ACombatCharacter::ChargedAttack()
{ {
// raise the attacking flag UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (!AnimInstance || !ChargedAttackMontage)
{
return;
}
const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
if (MontageLength <= 0.0f)
{
return;
}
// raise the attacking flag only after the montage starts
bIsAttacking = true; bIsAttacking = true;
// reset the charge loop flag // reset the charge loop flag
@@ -228,19 +241,9 @@ void ACombatCharacter::ChargedAttack()
// notify enemies they are about to be attacked // notify enemies they are about to be attacked
NotifyEnemiesOfIncomingAttack(); NotifyEnemiesOfIncomingAttack();
// play the charged attack montage
if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance())
{
const float MontageLength = AnimInstance->Montage_Play(ChargedAttackMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
// subscribe to montage completed and interrupted events
if (MontageLength > 0.0f)
{
// set the end delegate for the montage // set the end delegate for the montage
AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage); AnimInstance->Montage_SetEndDelegate(OnAttackMontageEnded, ChargedAttackMontage);
} }
}
}
void ACombatCharacter::AttackMontageEnded(UAnimMontage* Montage, bool bInterrupted) void ACombatCharacter::AttackMontageEnded(UAnimMontage* Montage, bool bInterrupted)
{ {
@@ -268,6 +271,7 @@ void ACombatCharacter::DoAttackTrace(FName DamageSourceBone)
{ {
// sweep for objects in front of the character to be hit by the attack // sweep for objects in front of the character to be hit by the attack
TArray<FHitResult> OutHits; TArray<FHitResult> OutHits;
TSet<AActor*> DamagedActors;
// start at the provided socket location, sweep forward // start at the provided socket location, sweep forward
const FVector TraceStart = GetMesh()->GetSocketLocation(DamageSourceBone); const FVector TraceStart = GetMesh()->GetSocketLocation(DamageSourceBone);
@@ -291,11 +295,19 @@ void ACombatCharacter::DoAttackTrace(FName DamageSourceBone)
// iterate over each object hit // iterate over each object hit
for (const FHitResult& CurrentHit : OutHits) for (const FHitResult& CurrentHit : OutHits)
{ {
AActor* HitActor = CurrentHit.GetActor();
if (!HitActor || DamagedActors.Contains(HitActor))
{
continue;
}
// check if we've hit a damageable actor // check if we've hit a damageable actor
ICombatDamageable* Damageable = Cast<ICombatDamageable>(CurrentHit.GetActor()); ICombatDamageable* Damageable = Cast<ICombatDamageable>(HitActor);
if (Damageable) if (Damageable)
{ {
DamagedActors.Add(HitActor);
// knock upwards and away from the impact normal // knock upwards and away from the impact normal
const FVector Impulse = (CurrentHit.ImpactNormal * -MeleeKnockbackImpulse) + (FVector::UpVector * MeleeLaunchImpulse); const FVector Impulse = (CurrentHit.ImpactNormal * -MeleeKnockbackImpulse) + (FVector::UpVector * MeleeLaunchImpulse);
@@ -238,6 +238,19 @@ void APlatformingCharacter::DoDash()
if (bHasDashed) if (bHasDashed)
return; return;
// Validate the montage before committing any dash state.
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (!AnimInstance || !DashMontage)
{
return;
}
const float MontageLength = AnimInstance->Montage_Play(DashMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
if (MontageLength <= 0.0f)
{
return;
}
// raise the dash flags // raise the dash flags
bIsDashing = true; bIsDashing = true;
bHasDashed = true; bHasDashed = true;
@@ -251,18 +264,8 @@ void APlatformingCharacter::DoDash()
// enable the jump trails // enable the jump trails
SetJumpTrailState(true); SetJumpTrailState(true);
// play the dash montage
if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance())
{
const float MontageLength = AnimInstance->Montage_Play(DashMontage, 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true);
// has the montage played successfully?
if (MontageLength > 0.0f)
{
AnimInstance->Montage_SetEndDelegate(OnDashMontageEnded, DashMontage); AnimInstance->Montage_SetEndDelegate(OnDashMontageEnded, DashMontage);
} }
}
}
void APlatformingCharacter::DoJumpStart() void APlatformingCharacter::DoJumpStart()
{ {
@@ -117,6 +117,8 @@ void ASideScrollingCharacter::NotifyHit(class UPrimitiveComponent* MyComp, AActo
void ASideScrollingCharacter::Landed(const FHitResult& Hit) void ASideScrollingCharacter::Landed(const FHitResult& Hit)
{ {
Super::Landed(Hit);
// reset the double jump // reset the double jump
bHasDoubleJumped = false; bHasDoubleJumped = false;
} }
@@ -0,0 +1,112 @@
# Gameplay Blockers Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Remove the five identified gameplay deadlocks/regressions without changing the intended successful gameplay paths.
**Architecture:** Keep fixes local to the existing character and StateTree implementations. Add a fast source-level regression suite for exact control-flow invariants, then compile the complete Unreal editor target as the integration gate.
**Tech Stack:** Unreal Engine 5.8, C++20, Python 3 `unittest`, UnrealBuildTool on macOS.
**Spec:** User request in this conversation: fix the five gameplay blockers identified by the project audit.
## Global Constraints
- Fix only: synchronous StateTree completion, dash montage failure, attack montage failure, Side Scrolling base landing call, and per-trace hit deduplication.
- Preserve successful montage behavior and Blueprint hooks.
- No dependency changes, broad refactor, commit, push, or binary asset edit.
- Tests must be observed failing before production edits and passing afterward.
- Final verification requires the regression suite, a full `pogoEditor Mac Development` build, and a clean tracked diff check.
## Review Focus
- A missing dash montage must not consume dash state or change gravity/trails.
- Missing player attack montages must leave the player available for the next input.
- Missing enemy attack montages must finish the waiting StateTree task.
- One actor exposed through multiple hit results must receive one damage event per trace.
- Side Scrolling landing must retain `ACharacter` landing notifications before resetting local jump state.
---
### Task 1: Add the red regression suite
**Files:**
- Create: `Scripts/tests/test_gameplay_blockers.py`
**Interfaces:**
- Consumes: current C++ source text.
- Produces: five deterministic regression checks, one for each blocker.
- [ ] Write tests that extract exact C++ function bodies and assert the required control-flow invariants.
- [ ] Run `python3 -m unittest Scripts.tests.test_gameplay_blockers -v`.
- [ ] Confirm all five tests fail against the current implementation for the expected missing guards/calls.
### Task 2: Complete the synchronous StateTree speed task
**Files:**
- Modify: `Source/pogo/Variant_Combat/AI/CombatStateTreeUtility.cpp:235-244`
**Interfaces:**
- Consumes: StateTree task entry contract.
- Produces: `EnterState` returns `Succeeded` after applying `MaxWalkSpeed`.
- [ ] Change only the terminal status from `Running` to `Succeeded`.
- [ ] Run the focused StateTree regression test and confirm green.
### Task 3: Make montage startup transactional
**Files:**
- Modify: `Source/pogo/Variant_Platforming/PlatformingCharacter.cpp:235-265`
- Modify: `Source/pogo/Variant_Combat/CombatCharacter.cpp:191-243`
- Modify: `Source/pogo/Variant_Combat/AI/CombatEnemy.cpp:45-105`
**Interfaces:**
- Consumes: `UAnimInstance::Montage_Play`, where a value `<= 0` means startup failed.
- Produces: gameplay flags and side effects are committed only after successful montage startup; AI failure executes `OnAttackCompleted` so StateTree can advance.
- [ ] Guard null AnimInstance and montage before mutating dash/attack state.
- [ ] Guard `Montage_Play <= 0` before mutating state.
- [ ] Keep delegate installation on the successful path.
- [ ] Notify enemy StateTree completion on both failure paths.
- [ ] Run the focused dash and attack regression tests and confirm green.
### Task 4: Preserve base landing behavior
**Files:**
- Modify: `Source/pogo/Variant_SideScrolling/SideScrollingCharacter.cpp:118-122`
**Interfaces:**
- Consumes: `ACharacter::Landed` lifecycle.
- Produces: base landing notifications execute before local double-jump reset.
- [ ] Call `Super::Landed(Hit)` first.
- [ ] Run the focused landing regression test and confirm green.
### Task 5: Deduplicate melee hits per trace
**Files:**
- Modify: `Source/pogo/Variant_Combat/CombatCharacter.cpp:267-310`
- Modify: `Source/pogo/Variant_Combat/AI/CombatEnemy.cpp:126-170`
**Interfaces:**
- Consumes: `SweepMultiByObjectType` hit arrays, which may contain several components from one actor.
- Produces: a local `TSet<AActor*>` applies damage once per actor for each trace invocation.
- [ ] Resolve and null-check `HitActor` once per result.
- [ ] Skip actors already present in the per-call set.
- [ ] Add the actor before calling `ApplyDamage`.
- [ ] Run the focused deduplication regression test and confirm green.
### Task 6: Full verification and review
**Files:**
- Verify all modified source and test files.
**Interfaces:**
- Consumes: Tasks 1-5.
- Produces: green regression suite and compiled editor target.
- [ ] Run `python3 -m unittest Scripts.tests.test_gameplay_blockers -v`.
- [ ] Build `pogoEditor Mac Development` with UnrealBuildTool.
- [ ] Run `git diff --check` and inspect `git diff --stat` plus `git status`.
- [ ] Request a fresh whole-change code review; fix only Critical/Important findings with another red-green cycle.