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_AddTransition.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_AddTransition : public UObject, public IWingHandler
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
2026-03-14 00:02:00 -04:00
|
|
|
UPROPERTY(meta=(Description="Animation Blueprint package path"))
|
2026-03-08 22:17:14 -04:00
|
|
|
FString Blueprint;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Description="State machine graph name"))
|
|
|
|
|
FString Graph;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Description="Name of the source state"))
|
|
|
|
|
FString FromState;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Description="Name of the target state"))
|
|
|
|
|
FString ToState;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Optional, Description="Crossfade duration in seconds"))
|
|
|
|
|
float CrossfadeDuration = 0.0f;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Optional, Description="Transition priority order"))
|
|
|
|
|
int32 Priority = 0;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Optional, Description="Whether the transition is bidirectional"))
|
|
|
|
|
bool BBidirectional = false;
|
|
|
|
|
|
|
|
|
|
virtual FString GetDescription() const override
|
|
|
|
|
{
|
|
|
|
|
return TEXT("Add a transition between two states in an animation state machine graph.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 23:41:59 -04:00
|
|
|
virtual void Handle() override
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
2026-03-18 10:17:58 -04:00
|
|
|
WingFetcher F;
|
2026-03-14 00:02:00 -04:00
|
|
|
UAnimBlueprint* AnimBP = F.Asset(Blueprint).Cast<UAnimBlueprint>();
|
|
|
|
|
if (!AnimBP) return;
|
2026-03-08 22:17:14 -04:00
|
|
|
|
2026-03-18 10:17:58 -04:00
|
|
|
UAnimationStateMachineGraph* SMGraph = WingUtils::FindStateMachineGraph(AnimBP, Graph);
|
2026-03-10 07:17:42 -04:00
|
|
|
if (!SMGraph)
|
|
|
|
|
{
|
2026-03-18 10:17:58 -04:00
|
|
|
UWingServer::Printf(TEXT("ERROR: State machine graph '%s' not found in '%s'\n"), *Graph, *WingUtils::FormatName(AnimBP));
|
2026-03-10 07:17:42 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 10:17:58 -04:00
|
|
|
UAnimStateNode* FromStateNode = WingUtils::FindStateByName(SMGraph, FromState);
|
2026-03-08 22:17:14 -04:00
|
|
|
if (!FromStateNode) return;
|
|
|
|
|
|
2026-03-18 10:17:58 -04:00
|
|
|
UAnimStateNode* ToStateNode = WingUtils::FindStateByName(SMGraph, ToState);
|
2026-03-08 22:17:14 -04:00
|
|
|
if (!ToStateNode) return;
|
|
|
|
|
|
|
|
|
|
// Create transition node
|
|
|
|
|
UAnimStateTransitionNode* TransNode = NewObject<UAnimStateTransitionNode>(SMGraph);
|
|
|
|
|
TransNode->CreateNewGuid();
|
|
|
|
|
TransNode->PostPlacedNewNode();
|
|
|
|
|
TransNode->AllocateDefaultPins();
|
|
|
|
|
|
|
|
|
|
// Position between the two states
|
|
|
|
|
TransNode->NodePosX = (FromStateNode->NodePosX + ToStateNode->NodePosX) / 2;
|
|
|
|
|
TransNode->NodePosY = (FromStateNode->NodePosY + ToStateNode->NodePosY) / 2;
|
|
|
|
|
|
|
|
|
|
SMGraph->AddNode(TransNode, false, false);
|
|
|
|
|
TransNode->SetFlags(RF_Transactional);
|
|
|
|
|
|
|
|
|
|
// Connect: FromState output -> Transition input, Transition output -> ToState input
|
|
|
|
|
TransNode->CreateConnections(FromStateNode, ToStateNode);
|
|
|
|
|
|
|
|
|
|
// Set optional properties
|
2026-03-12 17:20:20 -04:00
|
|
|
TransNode->CrossfadeDuration = CrossfadeDuration;
|
|
|
|
|
TransNode->PriorityOrder = Priority;
|
|
|
|
|
TransNode->Bidirectional = BBidirectional;
|
2026-03-08 22:17:14 -04:00
|
|
|
|
2026-03-19 10:56:20 -04:00
|
|
|
// Compile
|
2026-03-08 22:17:14 -04:00
|
|
|
FKismetEditorUtilities::CompileBlueprint(AnimBP);
|
|
|
|
|
|
2026-03-18 10:17:58 -04:00
|
|
|
UWingServer::Printf(TEXT("Created transition %s -> %s: %s\n"),
|
|
|
|
|
*FromState, *ToState, *WingUtils::FormatName(TransNode));
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
};
|