UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FrameValue.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreGlobals.h"
6#include "Misc/Optional.h"
7
13template<typename ValueType>
15{
16private:
17 uint64 FrameSet;
19
20public:
22 TFrameValue(const ValueType& InValue)
23 : FrameSet(GFrameCounter)
24 , Value(InValue)
25 {
26 }
27
28 TFrameValue(ValueType&& InValue)
29 : FrameSet(GFrameCounter)
30 , Value(MoveTemp(InValue))
31 {
32 }
33
36 : FrameSet(GFrameCounter)
37 {
38 }
39
42 : FrameSet(GFrameCounter)
43 {
44 Value = InValue.Value;
45 }
46
48 : FrameSet(GFrameCounter)
49 {
50 Value = MoveTemp(InValue.Value);
51 }
52
54 {
55 Value = InValue.Value;
56 FrameSet = GFrameCounter;
57 return *this;
58 }
59
61 {
62 Value = MoveTemp(InValue.Value);
63 FrameSet = GFrameCounter;
64 return *this;
65 }
66
67 TFrameValue& operator=(const ValueType& InValue)
68 {
69 Value = InValue;
70 FrameSet = GFrameCounter;
71 return *this;
72 }
73
75 {
76 Value = MoveTemp(InValue);
77 FrameSet = GFrameCounter;
78 return *this;
79 }
80
81public:
82
83 bool IsSet() const
84 {
85 return Value.IsSet() && FrameSet == GFrameCounter;
86 }
87
88 const ValueType& GetValue() const
89 {
90 checkf(FrameSet == GFrameCounter, TEXT("Cannot get value on a different frame"));
91 return Value.GetValue();
92 }
93
94 ValueType TryGetValue(ValueType UnsetValue) const&
95 {
96 return IsSet() ? Value.GetValue() : MoveTemp(UnsetValue);
97 }
98
99 ValueType TryGetValue(ValueType UnsetValue) &&
100 {
101 ValueType Result = IsSet() ? MoveTemp(Value.GetValue()) : MoveTemp(UnsetValue);
102 Value.Reset();
103 return Result;
104 }
105};
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
uint64 GFrameCounter
Definition CoreGlobals.cpp:418
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition FrameValue.h:15
TFrameValue(const TFrameValue &InValue)
Definition FrameValue.h:41
TFrameValue & operator=(TFrameValue &&InValue)
Definition FrameValue.h:60
TFrameValue & operator=(const TFrameValue &InValue)
Definition FrameValue.h:53
const ValueType & GetValue() const
Definition FrameValue.h:88
TFrameValue(TFrameValue &&InValue)
Definition FrameValue.h:47
TFrameValue(const ValueType &InValue)
Definition FrameValue.h:22
TFrameValue()
Definition FrameValue.h:35
TFrameValue & operator=(const ValueType &InValue)
Definition FrameValue.h:67
TFrameValue & operator=(ValueType &&InValue)
Definition FrameValue.h:74
ValueType TryGetValue(ValueType UnsetValue) const &
Definition FrameValue.h:94
ValueType TryGetValue(ValueType UnsetValue) &&
Definition FrameValue.h:99
TFrameValue(ValueType &&InValue)
Definition FrameValue.h:28
bool IsSet() const
Definition FrameValue.h:83
Definition Optional.h:131