UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GCObjectScopeGuard.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "UObject/GCObject.h"
6
11template <typename ObjectType>
13{
14 static_assert(TPointerIsConvertibleFromTo<ObjectType, const UObjectBase>::Value, "TGCObjectScopeGuard: ObjectType must be pointers to a type derived from UObject");
15
16public:
17 explicit TGCObjectScopeGuard(ObjectType* InObject)
18 : Object(InObject)
19 {
20 }
21
23 {
24 }
25
29
30 //~ FGCObject interface
31 virtual void AddReferencedObjects(FReferenceCollector& Collector) override
32 {
33 Collector.AddReferencedObject(Object);
34 }
35
36 virtual FString GetReferencerName() const override
37 {
38 return TEXT("TGCObjectScopeGuard");
39 }
40
41 UE_FORCEINLINE_HINT ObjectType* Get() const
42 {
43 return Object;
44 }
45
46private:
48};
49
51
55template <typename ObjectType>
57{
58 static_assert(TPointerIsConvertibleFromTo<ObjectType, const UObjectBase>::Value, "TGCObjectsScopeGuard: ObjectType must be pointers to a type derived from UObject");
59
60public:
62 : Objects(InObjects)
63 {
64 }
65
67 {
68 }
69
73
74 //~ FGCObject interface
75 virtual void AddReferencedObjects(FReferenceCollector& Collector) override
76 {
77 Collector.AddReferencedObjects(Objects);
78 }
79
80 virtual FString GetReferencerName() const override
81 {
82 return TEXT("TGCObjectsScopeGuard");
83 }
84
86 {
87 return Objects;
88 }
89
90private:
92};
#define TEXT(x)
Definition Platform.h:1272
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition GCObject.h:128
Definition UObjectGlobals.h:2492
Definition Array.h:670
Definition GCObjectScopeGuard.h:13
TGCObjectScopeGuard & operator=(const TGCObjectScopeGuard &)=delete
virtual FString GetReferencerName() const override
Definition GCObjectScopeGuard.h:36
TGCObjectScopeGuard(const TGCObjectScopeGuard &)=delete
virtual ~TGCObjectScopeGuard()
Definition GCObjectScopeGuard.h:22
TGCObjectScopeGuard(ObjectType *InObject)
Definition GCObjectScopeGuard.h:17
UE_FORCEINLINE_HINT ObjectType * Get() const
Definition GCObjectScopeGuard.h:41
virtual void AddReferencedObjects(FReferenceCollector &Collector) override
Definition GCObjectScopeGuard.h:31
Definition GCObjectScopeGuard.h:57
TGCObjectsScopeGuard & operator=(const TGCObjectsScopeGuard &)=delete
virtual FString GetReferencerName() const override
Definition GCObjectScopeGuard.h:80
virtual ~TGCObjectsScopeGuard()
Definition GCObjectScopeGuard.h:66
virtual void AddReferencedObjects(FReferenceCollector &Collector) override
Definition GCObjectScopeGuard.h:75
TGCObjectsScopeGuard(const TGCObjectsScopeGuard &)=delete
TGCObjectsScopeGuard(const TArray< ObjectType * > &InObjects)
Definition GCObjectScopeGuard.h:61
UE_FORCEINLINE_HINT const TArray< ObjectType * > & Get() const
Definition GCObjectScopeGuard.h:85
Definition ObjectPtr.h:488
Definition PointerIsConvertibleFromTo.h:60