UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ToolTargetManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8
9#include "ToolTargetManager.generated.h"
10
11// TODO: Do we need more control over factory order to prioritize which gets used if we can
12// make multiple qualifying targets? It should theoretically not matter, but in practice, one
13// target or another could be more efficient for certain tasks. This is probably only worth
14// thinking about once we encounter it.
15
16// NOTE FOR IMPLEMENTING CACHING: Someday we will probably write a tool target manager that
17// caches tool targets and gives prebuilt ones when possible to avoid any extra conversions.
18// When implementing this, note that currently, some targets store converted versions of their
19// source objects without a way to determine whether their stored conversion is out of date.
20// The cached target will then give an incorrect result if the source object has been
21// modified after caching.
22// One way to deal with this is to have subclasses of UToolTarget that give the degree of
23// cacheability- fully cacheable (i.e., detects changes and rebuilds if necessary), cacheable
24// only if changes are made through that tool target (i.e. target manager has to clear it if
25// object may have changed; may choose not to have this option), or not cacheable.
26
35UCLASS(Transient, MinimalAPI)
37{
39
40public:
44 bool IsActive() const { return bIsActive; }
45
49 INTERACTIVETOOLSFRAMEWORK_API virtual void AddTargetFactory(UToolTargetFactory* Factory);
50
54 INTERACTIVETOOLSFRAMEWORK_API virtual void RemoveTargetFactoriesByPredicate(TFunctionRef<bool(UToolTargetFactory*)> Predicate);
55
59 INTERACTIVETOOLSFRAMEWORK_API virtual UToolTargetFactory* FindFirstFactoryByPredicate(TFunctionRef<bool(UToolTargetFactory*)> Predicate);
60
64 template<typename CastToType>
66 {
67 UToolTargetFactory* Found = FindFirstFactoryByPredicate([](UToolTargetFactory* Factory) { return Cast<CastToType>(Factory) != nullptr; });
68 return (Found != nullptr) ? Cast<CastToType>(Found) : nullptr;
69 }
70
71
72
74 INTERACTIVETOOLSFRAMEWORK_API virtual bool CanBuildTarget(UObject* SourceObject, const FToolTargetTypeRequirements& TargetRequirements) const;
75
85
87 template<typename CastToType>
88 CastToType* BuildTarget(UObject* SourceObject, const FToolTargetTypeRequirements& TargetType)
89 {
90 UToolTarget* Result = BuildTarget(SourceObject, TargetType);
91 return (Result != nullptr) ? Cast<CastToType>(Result) : nullptr;
92 }
93
98 INTERACTIVETOOLSFRAMEWORK_API virtual int32 CountSelectedAndTargetable(const FToolBuilderState& SceneState,
100
105 INTERACTIVETOOLSFRAMEWORK_API virtual void EnumerateSelectedAndTargetableComponents(const FToolBuilderState& SceneState,
108
113 INTERACTIVETOOLSFRAMEWORK_API virtual int32 CountSelectedAndTargetableWithPredicate(const FToolBuilderState& SceneState,
116
117
122 INTERACTIVETOOLSFRAMEWORK_API virtual UToolTarget* BuildFirstSelectedTargetable(const FToolBuilderState& SceneState,
124
129 INTERACTIVETOOLSFRAMEWORK_API virtual TArray<TObjectPtr<UToolTarget>> BuildAllSelectedTargetable(const FToolBuilderState& SceneState,
131
134
137
143
144protected:
145
146 // This should be removed once tools are transitioned to using tool targets, and the
147 // functions in ComponentSourceInterfaces.h do not exist. For now, this is here to call
148 // Initialize().
150
152
154 bool bIsActive = false;
155
156 UPROPERTY()
158
159 // More state will go here if the manager deals with target caching.
160
161private:
162 TFunction<bool(const UObject*)> InputFilterFunction;
163};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
Definition ToolTarget.h:54
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition ActorComponent.h:152
Definition Object.h:95
Definition ToolTarget.h:92
Definition ToolTargetManager.h:37
UToolTargetManager()
Definition ToolTargetManager.h:151
CastToType * FindFirstFactoryByType()
Definition ToolTargetManager.h:65
friend INTERACTIVETOOLSFRAMEWORK_API void AddFactoryToDeprecatedToolTargetManager(UToolTargetFactory *Factory)
CastToType * BuildTarget(UObject *SourceObject, const FToolTargetTypeRequirements &TargetType)
Definition ToolTargetManager.h:88
bool IsActive() const
Definition ToolTargetManager.h:44
virtual void SetInputFilterFunction(TFunction< bool(const UObject *)> ShouldAllowBuildingFromInputObject)
Definition ToolTargetManager.h:139
Definition ToolTarget.h:40
Definition ToolContextInterfaces.h:50
Definition ObjectPtr.h:488