Code to make Blueprint_Reparent safer.
This commit is contained in:
@@ -22,6 +22,11 @@
|
||||
#include "Misc/Paths.h"
|
||||
#include "Misc/PackageName.h"
|
||||
|
||||
// Reparent validation
|
||||
#include "Engine/LevelScriptActor.h"
|
||||
#include "Animation/AnimInstance.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
|
||||
// Animation Blueprint support
|
||||
#include "AnimStateNode.h"
|
||||
#include "AnimStateTransitionNode.h"
|
||||
@@ -397,6 +402,47 @@ bool WingUtils::CheckCanRename(UEdGraphNode* Node, const FString &Name)
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Reparent validation
|
||||
// ============================================================
|
||||
|
||||
bool WingUtils::CanReparentBlueprint(UClass* CurrentGenerated, UClass* Proposed)
|
||||
{
|
||||
if (!CurrentGenerated || !Proposed) return false;
|
||||
|
||||
UClass* CurrentParent = CurrentGenerated->GetSuperClass();
|
||||
if (!CurrentParent) return false;
|
||||
|
||||
// Don't allow parenting to itself or one of its children
|
||||
if (Proposed->IsChildOf(CurrentGenerated)) return false;
|
||||
|
||||
// Don't allow parenting to an interface
|
||||
if (Proposed->IsChildOf(UInterface::StaticClass())) return false;
|
||||
|
||||
// LevelScriptActor blueprints stay in the LevelScriptActor hierarchy
|
||||
if (CurrentParent->IsChildOf(ALevelScriptActor::StaticClass()))
|
||||
return Proposed->IsChildOf(ALevelScriptActor::StaticClass());
|
||||
|
||||
// Actor blueprints stay in the Actor hierarchy, but not LevelScriptActor
|
||||
if (CurrentParent->IsChildOf(AActor::StaticClass()))
|
||||
return Proposed->IsChildOf(AActor::StaticClass()) &&
|
||||
!Proposed->IsChildOf(ALevelScriptActor::StaticClass());
|
||||
|
||||
// Component blueprints stay in the ActorComponent hierarchy
|
||||
if (CurrentParent->IsChildOf(UActorComponent::StaticClass()))
|
||||
return Proposed->IsChildOf(UActorComponent::StaticClass());
|
||||
|
||||
// Anim blueprints stay in the AnimInstance hierarchy
|
||||
if (CurrentParent->IsChildOf(UAnimInstance::StaticClass()))
|
||||
return Proposed->IsChildOf(UAnimInstance::StaticClass());
|
||||
|
||||
// Widget blueprints stay in the UserWidget hierarchy
|
||||
if (CurrentParent->IsChildOf(UUserWidget::StaticClass()))
|
||||
return Proposed->IsChildOf(UUserWidget::StaticClass());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Blueprint helpers
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user