Skip to content

Commit

Permalink
UE5 version was incorrectly selecting the inner actors when the prefa…
Browse files Browse the repository at this point in the history
…b was selected. This caused usability issues while moving / duplicating prefabs
  • Loading branch information
coderespawn committed Jul 8, 2021
1 parent 87d7a9f commit e2eb4ea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
26 changes: 21 additions & 5 deletions Source/PrefabricatorEditor/Private/Utils/SelectionHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ void FPrefabricatorSelectionHook::Release()
USelection::SelectNoneEvent.Remove(CallbackHandle_SelectNone);
}

void FPrefabricatorSelectionHook::Tick(float DeltaTime) {
bSelectionGuard = true;
FPrefabricatorSelectionRequest Request;
while (SelectionRequests.Dequeue(Request)) {
if (Request.Actor.IsValid()) {
GEditor->SelectActor(Request.Actor.Get(), Request.bSelected, true);
}
}
bSelectionGuard = false;
}

bool FPrefabricatorSelectionHook::IsTickable() const {
return true;
}

TStatId FPrefabricatorSelectionHook::GetStatId() const {
return TStatId();
}

namespace {
bool IsInHierarchy(AActor* InActor, AActor* InPossibleParent) {
if (!InActor || !InPossibleParent) {
Expand Down Expand Up @@ -100,11 +119,8 @@ void FPrefabricatorSelectionHook::OnObjectSelected(UObject* Object)
}

if (CustomSelection) {
bSelectionGuard = true;
GEditor->SelectActor(CustomSelection, true, true);
GEditor->SelectActor(RequestedActor, false, true);
bSelectionGuard = false;

SelectionRequests.Enqueue({RequestedActor, false});
SelectionRequests.Enqueue({CustomSelection, true});
LastSelectedObject = CustomSelection;
}
else {
Expand Down
14 changes: 13 additions & 1 deletion Source/PrefabricatorEditor/Public/Utils/SelectionHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"

class PREFABRICATOREDITOR_API FPrefabricatorSelectionHook {
struct FPrefabricatorSelectionRequest {
TWeakObjectPtr<AActor> Actor;
bool bSelected;
};

class PREFABRICATOREDITOR_API FPrefabricatorSelectionHook : public FTickableEditorObject {
public:
void Initialize();
void Release();

//~ Begin FTickableEditorObject Interface
virtual void Tick(float DeltaTime) override;
virtual bool IsTickable() const override;
virtual TStatId GetStatId() const override;
//~ End FTickableEditorObject Interface

private:
void OnObjectSelected(UObject* Object);
void OnSelectNone();
Expand All @@ -18,5 +29,6 @@ class PREFABRICATOREDITOR_API FPrefabricatorSelectionHook {
FDelegateHandle CallbackHandle_SelectNone;
TWeakObjectPtr<AActor> LastSelectedObject;
bool bSelectionGuard = false;
TQueue<FPrefabricatorSelectionRequest> SelectionRequests;
};

0 comments on commit e2eb4ea

Please sign in to comment.