UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::Geometry::TConstObjectSharedAccess< ObjectType > Class Template Reference

#include <MeshSharingUtil.h>

Public Member Functions

 TConstObjectSharedAccess ()
 
 TConstObjectSharedAccess (const ObjectType *Object)
 
 TConstObjectSharedAccess (TSharedPtr< ObjectType > Object)
 
 ~TConstObjectSharedAccess ()
 
void ReleaseSharedObject ()
 
bool AccessSharedObject (TFunctionRef< void(const ObjectType &)> ProcessFunc)
 

Protected Attributes

const ObjectType * ObjectRawPtr = nullptr
 
TSharedPtr< ObjectType > ObjectSharedPtr
 
ObjectType EmptyObject
 
FCriticalSection ObjectLock
 

Detailed Description

template<typename ObjectType>
class UE::Geometry::TConstObjectSharedAccess< ObjectType >

TConstObjectSharedAccess provides a way for the owner of some object (eg a Mesh) to share read-only access to that object with background threads.

This avoids the obvious alternative, using TSharedPtr, which tends to result in some bad patterns (in particular calling code that /doesn't/ have a shared pointer to the object, now has to make a copy, or also convert all related code to use a shared pointer).

Currently TConstObjectSharedAccess's template ObjectType must be default constructible. This allows the background threads to still access an instance of ObjectType even if the owner thread/code decides to revoke access. In that case, TConstObjectSharedAccess provides an "empty" ObjectType instead. (the background processing code must handle this case).

TConstObjectSharedAccess can be constructed with either a raw pointer to ObjectType, or a TSharedPtr. In the raw pointer case, the creator is responsible for destruction.

The standard usage pattern is:

[Owner thread] T* ObjectPtr = (...); TSharedPtr<TConstObjectSharedAccess<T>> SharedAccess = MakeShared<TConstObjectSharedAccess<T>>(ObjectPtr); pass_to_background_thread(SharedAccess);

[Background thread] SharedAccess->AccessSharedObject( [](const ObjectType& Object) { do_my_stuff(Object); } );

[Owner thread (later)] SharedAccess->ReleaseSharedObject();

Note that a TSharedPtr does not strictly need to be used. However this allows the Owner thread to destruct the Object, and/or terminate, and the background thread can still safely access a shared ObjectType (now empty).

Constructor & Destructor Documentation

◆ TConstObjectSharedAccess() [1/3]

template<typename ObjectType >
UE::Geometry::TConstObjectSharedAccess< ObjectType >::TConstObjectSharedAccess ( )
inline

◆ TConstObjectSharedAccess() [2/3]

template<typename ObjectType >
UE::Geometry::TConstObjectSharedAccess< ObjectType >::TConstObjectSharedAccess ( const ObjectType *  Object)
inline

Construct shared access to a raw pointer of ObjectType

◆ TConstObjectSharedAccess() [3/3]

template<typename ObjectType >
UE::Geometry::TConstObjectSharedAccess< ObjectType >::TConstObjectSharedAccess ( TSharedPtr< ObjectType >  Object)
inline

Construct shared access to a shared pointer of ObjectType

◆ ~TConstObjectSharedAccess()

template<typename ObjectType >
UE::Geometry::TConstObjectSharedAccess< ObjectType >::~TConstObjectSharedAccess ( )
inline

Member Function Documentation

◆ AccessSharedObject()

template<typename ObjectType >
bool UE::Geometry::TConstObjectSharedAccess< ObjectType >::AccessSharedObject ( TFunctionRef< void(const ObjectType &)>  ProcessFunc)
inline

Call ProcessFunc(Object) on the shared Object.

Returns
false if the Object was empty, ie if ReleaseSharedObject() has been called
Warning
calling code must not store a reference to ObjectType!

◆ ReleaseSharedObject()

template<typename ObjectType >
void UE::Geometry::TConstObjectSharedAccess< ObjectType >::ReleaseSharedObject ( )
inline

Release the shared object. Generally this is intended to only be called by the "owner" of the object.

Member Data Documentation

◆ EmptyObject

template<typename ObjectType >
ObjectType UE::Geometry::TConstObjectSharedAccess< ObjectType >::EmptyObject
protected

◆ ObjectLock

template<typename ObjectType >
FCriticalSection UE::Geometry::TConstObjectSharedAccess< ObjectType >::ObjectLock
protected

◆ ObjectRawPtr

template<typename ObjectType >
const ObjectType* UE::Geometry::TConstObjectSharedAccess< ObjectType >::ObjectRawPtr = nullptr
protected

◆ ObjectSharedPtr

template<typename ObjectType >
TSharedPtr<ObjectType> UE::Geometry::TConstObjectSharedAccess< ObjectType >::ObjectSharedPtr
protected

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