UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FUObjectAnnotationSparse< TAnnotation, bAutoRemove > Class Template Reference

#include <UObjectAnnotation.h>

+ Inheritance diagram for FUObjectAnnotationSparse< TAnnotation, bAutoRemove >:

Public Member Functions

virtual void NotifyUObjectDeleted (const UObjectBase *Object, int32 Index) override
 
virtual void OnUObjectArrayShutdown () override
 
 FUObjectAnnotationSparse ()
 
virtual ~FUObjectAnnotationSparse ()
 
void AddAnnotation (const UObjectBase *Object, TAnnotation &&Annotation)
 
void AddAnnotation (const UObjectBase *Object, const TAnnotation &Annotation)
 
TAnnotation GetAndRemoveAnnotation (const UObjectBase *Object)
 
void RemoveAnnotation (const UObjectBase *Object)
 
void RemoveAllAnnotations ()
 
TAnnotation GetAnnotation (const UObjectBase *Object)
 
const TMap< const UObjectBase *, TAnnotation > & GetAnnotationMap () const
 
void Reserve (int32 ExpectedNumElements)
 
virtual SIZE_T GetAllocatedSize () const override
 
- Public Member Functions inherited from FUObjectArray::FUObjectDeleteListener
virtual ~FUObjectDeleteListener ()
 
virtual void NotifyUObjectDeleted (const class UObjectBase *Object, int32 Index)=0
 

Protected Attributes

FTransactionallySafeRWLock AnnotationMapCritical
 
FTransactionallySafeRWLock AnnotationCacheCritical
 
TMap< const UObjectBase *, TAnnotationAnnotationMap
 
const UObjectBaseAnnotationCacheKey = nullptr
 
TAnnotation AnnotationCacheValue
 
bool bRegistered = false
 

Detailed Description

template<typename TAnnotation, bool bAutoRemove>
class FUObjectAnnotationSparse< TAnnotation, bAutoRemove >

FUObjectAnnotationSparse is a helper class that is used to store sparse, slow, temporary, editor only, external or other low priority information about UObjects.

There is a notion of a default annotation and UObjects default to this annotation and this takes no storage.

Annotations are automatically cleaned up when UObjects are destroyed. Annotation are not "garbage collection aware", so it isn't safe to store pointers to other UObjects in an annotation unless external guarantees are made such that destruction of the other object removes the annotation.

Parameters
TAnnotationtype of the annotation
bAutoRemoveif true, annotation will automatically be removed, otherwise in non-final builds it will verify that the annotation was removed by other means prior to destruction.

Constructor & Destructor Documentation

◆ FUObjectAnnotationSparse()

Constructor, initializes to nothing

◆ ~FUObjectAnnotationSparse()

Destructor, removes all annotations, which removes the annotation as a uobject destruction listener

Member Function Documentation

◆ AddAnnotation() [1/2]

template<typename TAnnotation , bool bAutoRemove>
void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AddAnnotation ( const UObjectBase Object,
const TAnnotation Annotation 
)
inline

◆ AddAnnotation() [2/2]

template<typename TAnnotation , bool bAutoRemove>
void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AddAnnotation ( const UObjectBase Object,
TAnnotation &&  Annotation 
)
inline

Add an annotation to the annotation list. If the Annotation is the default, then the annotation is removed.

Parameters
ObjectObject to annotate.
AnnotationAnnotation to associate with Object.

◆ GetAllocatedSize()

template<typename TAnnotation , bool bAutoRemove>
virtual SIZE_T FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::GetAllocatedSize ( ) const
inlineoverridevirtual

Returns the size of heap memory allocated internally by this listener

Reimplemented from FUObjectArray::FUObjectDeleteListener.

Reimplemented in FUObjectAnnotationSparseSearchable< TAnnotation, bAutoRemove >.

◆ GetAndRemoveAnnotation()

template<typename TAnnotation , bool bAutoRemove>
TAnnotation FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::GetAndRemoveAnnotation ( const UObjectBase Object)
inline

Removes an annotation from the annotation list and returns the annotation if it had one

Parameters
ObjectObject to de-annotate.
Returns
Old annotation

◆ GetAnnotation()

template<typename TAnnotation , bool bAutoRemove>
TAnnotation FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::GetAnnotation ( const UObjectBase Object)
inline

Return the annotation associated with a uobject

Parameters
ObjectObject to return the annotation for

◆ GetAnnotationMap()

template<typename TAnnotation , bool bAutoRemove>
const TMap< const UObjectBase *, TAnnotation > & FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::GetAnnotationMap ( ) const
inline

Return the annotation map. Caution, this is for low level use

Returns
A mapping from UObjectBase to annotation for non-default annotations

◆ NotifyUObjectDeleted()

template<typename TAnnotation , bool bAutoRemove>
virtual void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::NotifyUObjectDeleted ( const UObjectBase Object,
int32  Index 
)
inlineoverridevirtual

Interface for FUObjectAllocator::FUObjectDeleteListener

Parameters
Objectobject that has been destroyed
Indexindex of object that is being deleted

Reimplemented in FUObjectAnnotationSparseSearchable< TAnnotation, bAutoRemove >.

◆ OnUObjectArrayShutdown()

template<typename TAnnotation , bool bAutoRemove>
virtual void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::OnUObjectArrayShutdown ( )
inlineoverridevirtual

Called when UObject Array is being shut down, this is where all listeners should be removed from it

Implements FUObjectArray::FUObjectDeleteListener.

Reimplemented in FUObjectAnnotationSparseSearchable< TAnnotation, bAutoRemove >.

◆ RemoveAllAnnotations()

template<typename TAnnotation , bool bAutoRemove>
void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::RemoveAllAnnotations ( )
inline

Removes all annotation from the annotation list.

◆ RemoveAnnotation()

template<typename TAnnotation , bool bAutoRemove>
void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::RemoveAnnotation ( const UObjectBase Object)
inline

Removes an annotation from the annotation list.

Parameters
ObjectObject to de-annotate.

◆ Reserve()

template<typename TAnnotation , bool bAutoRemove>
void FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::Reserve ( int32  ExpectedNumElements)
inline

Reserves memory for the annotation map for the specified number of elements, used to avoid reallocations.

Member Data Documentation

◆ AnnotationCacheCritical

template<typename TAnnotation , bool bAutoRemove>
FTransactionallySafeRWLock FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AnnotationCacheCritical
mutableprotected

◆ AnnotationCacheKey

template<typename TAnnotation , bool bAutoRemove>
const UObjectBase* FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AnnotationCacheKey = nullptr
protected

Key for a one-item cache of the last lookup into AnnotationMap. Guarded by AnnotationCacheCritical. Annotation are often called back-to-back so this is a performance optimization for that.

◆ AnnotationCacheValue

template<typename TAnnotation , bool bAutoRemove>
TAnnotation FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AnnotationCacheValue
protected

Value for a one-item cache of the last lookup into AnnotationMap. Guarded by AnnotationCacheCritical.

◆ AnnotationMap

template<typename TAnnotation , bool bAutoRemove>
TMap<const UObjectBase *, TAnnotation> FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AnnotationMap
protected

Map from live objects to an annotation. Guarded by AnnotationMapCritical.

◆ AnnotationMapCritical

template<typename TAnnotation , bool bAutoRemove>
FTransactionallySafeRWLock FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::AnnotationMapCritical
mutableprotected

Guards the annotation map, cache key and cache value.

◆ bRegistered

template<typename TAnnotation , bool bAutoRemove>
bool FUObjectAnnotationSparse< TAnnotation, bAutoRemove >::bRegistered = false
protected

Monitor registration to GUObjectArray/UObjectDeleteListener.


The documentation for this class was generated from the following file: