Files
integration/Plugins/UEWingman/Source/UEWingman/Handlers/ActorComponent_Reparent.h
2026-04-04 01:45:25 -04:00

53 lines
1.7 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingUtils.h"
#include "WingServer.h"
#include "WingActorComponent.h"
#include "Engine/Blueprint.h"
#include "Engine/SimpleConstructionScript.h"
#include "Engine/SCS_Node.h"
#include "ActorComponent_Reparent.generated.h"
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
UCLASS()
class UWing_ActorComponent_Reparent : public UWingHandler
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, meta=(Description="Path to the component (e.g. '/Game/MyBP,component:MyComp')"))
FString Component;
UPROPERTY(EditAnywhere, meta=(Description="New parent component name."))
FString Parent;
virtual void Register() override
{
UWingServer::AddHandler(this,
TEXT("Change the parent of a component in a Blueprint's SimpleConstructionScript."));
}
virtual void Handle() override
{
WingFetcher F(WingOut::Stdout);
UWingComponentReference* CompRef = F.Walk(Component).Cast<UWingComponentReference>();
if (!CompRef) return;
// Find the new parent among all components (if specified)
UBlueprint *BP = CompRef->BP;
TArray<UWingComponentReference*> AllComponents = UWingComponentReference::GetAll(BP);
UWingComponentReference* NewParent = WingUtils::FindOneWithExternalID(Parent, AllComponents, TEXT("Component"), WingOut::Stdout);
if (!NewParent) return;
if (!CompRef->ReparentComponent(NewParent, WingOut::Stdout)) return;
WingOut::Stdout.Printf(TEXT("Reparented component."));
}
};