I am creating a Editor plugin to assist with creating blueprints. Specifically the plugin is to assist in the viewport. Upon a keystroke I want the currently selected component to be duplicated and then have the duplicate rotated and moved in a defined way.
So far I have the keystroke working in the blueprint editor and it determines the currently selected nodes using GetSelectedHandles():
TArray<FSubobjectDataHandle> SelectedNodes = SubobjectEditor->GetSelectedHandles();
I obtain the SubObjSubsystem and duplicate the entries.
if (USubobjectDataSubsystem* SubObjSubsystem = USubobjectDataSubsystem::Get())
{
TArray<FSubobjectDataHandle> DuplicatedHandles;
SubObjSubsystem->DuplicateSubobjects(SubobjectEditor->GetObjectContextHandle(), SelectedNodes, SubobjectEditor->GetBlueprint(), DuplicatedHandles);
FSubobjectEditorTreeNodePtrType NewNodes = DuplicatedHandles.Num() > 0 ? SubobjectEditor->FindSlateNodeForHandle(DuplicatedHandles[0]) : nullptr;
if (NewNodes != nullptr)
{
SubobjectEditor->GetDragDropTree()->SetSelection(NewNodes);
}
Where I just can’t figure out is how do I modify the components represented by the duplicated entries? I have tried many different methods but the closest I can get is to use a const_cast. I figure this can’t be the way I should do it and it doesn’t fully work.
TArray<FSubobjectDataHandle> NewSelectedNodes = SubobjectEditor->GetSelectedHandles();
for (FSubobjectDataHandle AHdl : NewSelectedNodes)
{
const UStaticMeshComponent* TestNode = AHdl.GetData()->GetObject<UStaticMeshComponent>();
if (TestNode)
{
(const_cast <UStaticMeshComponent*> (TestNode))->SetRelativeLocation(FVector(0, 0, 0)); //const_cast workaround....
}
}
So if I used the const_cast it will update the duplicated object in its details panel but it doesn’t update it in the viewport. In fact once I do this I cannot move the duplicated object in the viewport. It’s like it disconnects from the viewport. However, if I save the blueprint and reopen the duplicated object is rotated and moved. Maybe I need a refresh but I can’t determine what to call.
Thoughts?
Jason