Make subobject editor fix more conservative, just fix implementation of SSubobjectEditor::GetSelectedItemsForContextMenu to provide the correct component for inherited SCS components

#jira UE-194087, UE-196020, UE-194833
#rb Phillip.Kavan, Ben.Hoffman

[CL 28670594 by dan oconnor in ue5-main branch]
This commit is contained in:
dan oconnor
2023-10-11 13:09:28 -04:00
parent 8e6093cead
commit 364291983a
2 changed files with 12 additions and 33 deletions

View File

@@ -1045,39 +1045,12 @@ USCS_Node* FSubobjectData::FindSCSNodeForInstance(const UActorComponent* Instanc
return nullptr;
}
bool GUseLegacySubobjectTemplateBehavior = false;
static FAutoConsoleVariableRef CVarUseLegacySubobjectTemplateBehavior(
TEXT("bp.UseLegacySubobjectTemplateBehavior"),
GUseLegacySubobjectTemplateBehavior,
TEXT("Use the legacy behavior for setting up subobject template objects.")
);
bool FSubobjectData::AttemptToSetSCSNode()
{
if (USCS_Node* PossibleSCS = Cast<USCS_Node>(WeakObjectPtr.Get()))
{
WeakObjectPtr = PossibleSCS->ComponentTemplate;
SCSNodePtr = PossibleSCS;
if (GUseLegacySubobjectTemplateBehavior)
{
WeakObjectPtr = PossibleSCS->ComponentTemplate;
}
else
{
const FSubobjectData* RootSubobjectData = GetRootSubobject().GetData();
const UObject* Object = RootSubobjectData->GetObject();
UBlueprintGeneratedClass* BPGC = Cast<UBlueprintGeneratedClass>(Object->GetClass());
if (BPGC)
{
WeakObjectPtr = PossibleSCS->GetActualComponentTemplate(BPGC);
}
else
{
// I don't believe this is possible, but we may have strange clients
// and the best thing we can do for them is provide the current behavior:
ensureMsgf(false, TEXT("Falling back to cached Component Template, consider running bp.UseLegacySubobjectTemplateBehavior true"));
WeakObjectPtr = PossibleSCS->ComponentTemplate;
}
}
return true;
}
// If this is an instanced component, then we can find it's SCS node
@@ -1089,10 +1062,7 @@ bool FSubobjectData::AttemptToSetSCSNode()
SCSNodePtr = FindSCSNodeForInstance(Template, Template->GetOwner()->GetClass());
if (SCSNodePtr.IsValid())
{
if (GUseLegacySubobjectTemplateBehavior)
{
WeakObjectPtr = SCSNodePtr->ComponentTemplate;
}
WeakObjectPtr = SCSNodePtr->ComponentTemplate;
return true;
}
}

View File

@@ -3253,7 +3253,16 @@ void SSubobjectEditor::GetSelectedItemsForContextMenu(TArray<FComponentEventCons
const FSubobjectEditorTreeNodePtrType& TreeNode = *NodeIter;
const FSubobjectData* Data = TreeNode->GetDataSource();
NewItem.VariableName = Data->GetVariableName();
NewItem.Component = const_cast<UActorComponent*>(TreeNode->GetComponentTemplate());
const UObject* ContextObject = GetObjectContext();
const AActor* ContextAsActor = Cast<AActor>(ContextObject);
if (!ContextObject->HasAnyFlags(RF_ClassDefaultObject) && ContextAsActor)
{
NewItem.Component = const_cast<UActorComponent*>(Data->FindComponentInstanceInActor(ContextAsActor));
}
else
{
NewItem.Component = const_cast<UObject*>(Data->GetObjectForBlueprint(GetBlueprint()));
}
OutSelectedItems.Add(NewItem);
}
}