UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InteractiveToolsContext.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreMinimal.h"
9#include "InteractiveTool.h"
11#include "Templates/Function.h"
12#include "UObject/Object.h"
14#include "UObject/ObjectPtr.h"
17
18#include "InteractiveToolsContext.generated.h"
19
20class FText;
24class UInputRouter;
27
28
37UCLASS(Transient, MinimalAPI)
39{
41
42public:
44
45 // FContextInitInfo is used by Initialize() to pass information to the various creator functions below.
46 // See ::UInteractiveToolsContext() and ::Initialize() for how these fields are used/initialized.
47 // In particular, InputRouter will not be set until after the UInputRouter has been created
49 {
50 UInteractiveToolsContext* ToolsContext = nullptr;
51 IToolsContextQueriesAPI* QueriesAPI = nullptr;
52 IToolsContextTransactionsAPI* TransactionsAPI = nullptr;
53 UInputRouter* InputRouter = nullptr;
54 };
55
56 //
57 // Replace the internal functions that are called to create/destroy the sub-objects owned by the ITC.
58 // By doing this, clients of the ITF can provide their own subclass implementations, or do other
59 // custom setup/teardown as necessary. See comments above CreateInputRouterFunc below
60 //
61 INTERACTIVETOOLSFRAMEWORK_API virtual void SetCreateInputRouterFunc(TUniqueFunction<UInputRouter* (const FContextInitInfo&)> Func);
62 INTERACTIVETOOLSFRAMEWORK_API virtual void SetCreateToolManagerFunc(TUniqueFunction<UInteractiveToolManager* (const FContextInitInfo&)> Func);
63 INTERACTIVETOOLSFRAMEWORK_API virtual void SetCreateToolTargetManagerFunc(TUniqueFunction<UToolTargetManager* (const FContextInitInfo&)> Func);
64 INTERACTIVETOOLSFRAMEWORK_API virtual void SetCreateGizmoManagerFunc(TUniqueFunction<UInteractiveGizmoManager* (const FContextInitInfo&)> Func);
65 INTERACTIVETOOLSFRAMEWORK_API virtual void SetCreateContextStoreFunc(TUniqueFunction<UContextObjectStore* (const FContextInitInfo&)> Func);
66
67 INTERACTIVETOOLSFRAMEWORK_API virtual void SetShutdownInputRouterFunc(TUniqueFunction<void(UInputRouter*)> Func);
68 INTERACTIVETOOLSFRAMEWORK_API virtual void SetShutdownToolManagerFunc(TUniqueFunction<void(UInteractiveToolManager*)> Func);
69 INTERACTIVETOOLSFRAMEWORK_API virtual void SetShutdownToolTargetManagerFunc(TUniqueFunction<void(UToolTargetManager*)> Func);
70 INTERACTIVETOOLSFRAMEWORK_API virtual void SetShutdownGizmoManagerFunc(TUniqueFunction<void(UInteractiveGizmoManager*)> Func);
71 INTERACTIVETOOLSFRAMEWORK_API virtual void SetShutdownContextStoreFunc(TUniqueFunction<void(UContextObjectStore*)> Func);
72
79
82
83 INTERACTIVETOOLSFRAMEWORK_API virtual void DeactivateActiveTool(EToolSide WhichSide, EToolShutdownType ShutdownType);
84 INTERACTIVETOOLSFRAMEWORK_API virtual void DeactivateAllActiveTools(EToolShutdownType ShutdownType);
85
86 INTERACTIVETOOLSFRAMEWORK_API bool CanStartTool(EToolSide WhichSide, const FString& ToolTypeIdentifier) const;
87 INTERACTIVETOOLSFRAMEWORK_API bool HasActiveTool(EToolSide WhichSide) const;
88 INTERACTIVETOOLSFRAMEWORK_API FString GetActiveToolName(EToolSide WhichSide) const;
89 INTERACTIVETOOLSFRAMEWORK_API bool ActiveToolHasAccept(EToolSide WhichSide) const;
90 INTERACTIVETOOLSFRAMEWORK_API bool CanAcceptActiveTool(EToolSide WhichSide) const;
91 INTERACTIVETOOLSFRAMEWORK_API bool CanCancelActiveTool(EToolSide WhichSide) const;
92 INTERACTIVETOOLSFRAMEWORK_API bool CanCompleteActiveTool(EToolSide WhichSide) const;
93 INTERACTIVETOOLSFRAMEWORK_API bool StartTool(EToolSide WhichSide, const FString& ToolTypeIdentifier);
94 INTERACTIVETOOLSFRAMEWORK_API void EndTool(EToolSide WhichSide, EToolShutdownType ShutdownType);
95 INTERACTIVETOOLSFRAMEWORK_API bool IsToolActive(EToolSide WhichSide, const FString ToolIdentifier) const;
96
97public:
98 // forwards message to OnToolNotificationMessage delegate
99 INTERACTIVETOOLSFRAMEWORK_API virtual void PostToolNotificationMessage(const FText& Message);
100 INTERACTIVETOOLSFRAMEWORK_API virtual void PostToolWarningMessage(const FText& Message);
101
105
106public:
108 UPROPERTY()
110
112 UPROPERTY()
114
116 UPROPERTY()
118
120 UPROPERTY()
122
127 UPROPERTY()
128 TObjectPtr<UContextObjectStore> ContextObjectStore;
129
131
132 // Initialize() calls these functions to create the main child objects needed to operate
133 // the Tools Framework - InputRouter, ToolManager, GizmoManager, TargetManager, ContextStore.
134 // Default implementations are set up in the UInteractiveToolsContext() constructor, however
135 // users of the framework are free to replace these with subclasses, or do more complex
136 // initialization, by replacing these functions with their own versions before calling Initialize().
137 // (the same could be accomplished by subclassing and overriding Initialize(), however using these
138 // lambda functions will be a safer alternative in many cases)
139 TUniqueFunction<UInputRouter* (const FContextInitInfo&)> CreateInputRouterFunc;
141 TUniqueFunction<UToolTargetManager* (const FContextInitInfo&)> CreateToolTargetManagerFunc;
143 TUniqueFunction<UContextObjectStore* (const FContextInitInfo&)> CreateContextStoreFunc;
144
145 // Analogous to the CreateX() functions above, these function are called by Shutdown()
146 // to terminate and clean up after the various elements.
147 TUniqueFunction<void(UInputRouter*)> ShutdownInputRouterFunc;
148 TUniqueFunction<void(UInteractiveToolManager*)> ShutdownToolManagerFunc;
149 TUniqueFunction<void(UToolTargetManager*)> ShutdownToolTargetManagerFunc;
150 TUniqueFunction<void(UInteractiveGizmoManager*)> ShutdownGizmoManagerFunc;
151 TUniqueFunction<void(UContextObjectStore*)> ShutdownContextStoreFunc;
152
153
154 // todo: deprecate and remove this, can now be accomplished via CreateToolManagerFunc()
155 UPROPERTY()
157};
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EToolSide
Definition InteractiveToolManager.h:20
EToolShutdownType
Definition InteractiveTool.h:45
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
Definition Text.h:385
Definition ToolContextInterfaces.h:254
Definition ToolContextInterfaces.h:360
Definition SoftObjectPtr.h:763
Definition FunctionFwd.h:19
Definition ContextObjectStore.h:25
Definition InputRouter.h:39
Definition InteractiveGizmoManager.h:40
Definition InteractiveToolManager.h:79
Definition InteractiveToolsContext.h:39
FToolsContextToolNotification OnToolWarningMessage
Definition InteractiveToolsContext.h:104
FToolsContextToolNotification OnToolNotificationMessage
Definition InteractiveToolsContext.h:103
DECLARE_MULTICAST_DELEGATE_OneParam(FToolsContextToolNotification, const FText &)
Definition Object.h:95
Definition ToolTargetManager.h:37
Definition ObjectPtr.h:488
Definition InteractiveToolsContext.h:49