Files
integration/Plugins/UEWingman/Deprecated/StateMachine_RemoveState.h

82 lines
2.4 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
2026-03-18 10:17:58 -04:00
#include "WingServer.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingUtils.h"
2026-03-08 22:17:14 -04:00
#include "Kismet2/KismetEditorUtilities.h"
#include "Animation/AnimBlueprint.h"
#include "AnimStateNode.h"
#include "AnimStateTransitionNode.h"
#include "AnimationStateMachineGraph.h"
2026-03-12 00:44:17 -04:00
#include "StateMachine_RemoveState.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
2026-03-15 19:32:09 -04:00
UCLASS()
2026-03-18 10:17:58 -04:00
class UWing_StateMachine_RemoveState : public UObject, public IWingHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
2026-03-10 07:17:42 -04:00
UPROPERTY(meta=(Description="Path to the state machine graph, e.g. /Game/MyAnimBP,graph:StateMachine"))
2026-03-15 17:20:31 -04:00
FString Graph;
2026-03-08 22:17:14 -04:00
UPROPERTY(meta=(Description="Name of the state to remove"))
FString StateName;
virtual FString GetDescription() const override
{
return TEXT("Remove a state and its connected transitions from an animation state machine graph.");
}
virtual void Handle() override
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
// Fetch the state machine graph via WingFetcher
WingFetcher F;
2026-03-15 17:20:31 -04:00
F.Walk(Graph);
2026-03-10 07:17:42 -04:00
if (!F.Ok()) return;
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
UAnimationStateMachineGraph* SMGraph = F.Cast<UAnimationStateMachineGraph>();
if (!SMGraph) return;
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
// Find the owning AnimBlueprint for compile/save
UBlueprint* BP = Cast<UBlueprint>(SMGraph->GetOuter()->GetOuter());
if (!BP)
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
UWingServer::Print(TEXT("ERROR: Could not find owning blueprint.\n"));
2026-03-10 07:17:42 -04:00
return;
2026-03-08 22:17:14 -04:00
}
2026-03-10 07:17:42 -04:00
// Find the state node
2026-03-18 10:17:58 -04:00
UAnimStateNode* StateNode = WingUtils::FindStateByName(SMGraph, StateName);
2026-03-10 07:17:42 -04:00
if (!StateNode) return;
// Collect and remove transitions connected to this state
int32 RemovedTransitions = 0;
for (UEdGraphNode* Node : TArray<UEdGraphNode*>(SMGraph->Nodes))
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
UAnimStateTransitionNode* TransNode = Cast<UAnimStateTransitionNode>(Node);
if (!TransNode) continue;
if (TransNode->GetPreviousState() != StateNode && TransNode->GetNextState() != StateNode) continue;
TransNode->BreakAllNodeLinks();
SMGraph->RemoveNode(TransNode);
RemovedTransitions++;
2026-03-08 22:17:14 -04:00
}
// Remove the state
StateNode->BreakAllNodeLinks();
SMGraph->RemoveNode(StateNode);
// Compile
2026-03-10 07:17:42 -04:00
FKismetEditorUtilities::CompileBlueprint(BP);
2026-03-08 22:17:14 -04:00
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Removed state %s and %d transition(s).\n"),
*WingUtils::FormatName(StateNode), RemovedTransitions);
2026-03-08 22:17:14 -04:00
}
};