UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMNativeConstructorWrapperInline.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#if WITH_VERSE_VM || defined(__INTELLISENSE__)
5
11
12namespace Verse
13{
14
15inline bool VNativeConstructorWrapper::CreateFieldCached(FAllocationContext Context, FCreateFieldCacheCase Cache)
16{
17 bool bNewField = EmergentTypeOffset != Cache.NextEmergentTypeOffset;
18 switch (Cache.Kind)
19 {
20 case FCreateFieldCacheCase::EKind::NativeStruct:
21 {
22 VNativeStruct& NativeStruct = WrappedObject().template StaticCast<VNativeStruct>();
23 VShape* Shape = NativeStruct.GetEmergentType()->Shape.Get();
24 const VShape::VEntry& Field = Shape->GetField(Cache.FieldIndex);
25 if (bNewField)
26 {
27 SetEmergentType(Context, FHeap::EmergentTypeOffsetToPtr(Cache.NextEmergentTypeOffset));
28 if (Field.IsProperty())
29 {
30 void* Data = NativeStruct.GetData(*NativeStruct.GetEmergentType()->CppClassInfo);
31 Field.UProperty->InitializeValue_InContainer(Data);
32 if (Field.Type == EFieldType::FVerseProperty)
33 {
34 Field.UProperty->ContainerPtrToValuePtr<VRestValue>(Data)->Reset(0);
35 }
36 }
37 }
38 break;
39 }
40 case FCreateFieldCacheCase::EKind::UObject:
41 {
42 UObject* UEObject = WrappedObject().ExtractUObject();
44 VShape& Shape = VerseClass->Shape.Get(Context).StaticCast<VShape>();
45 const VShape::VEntry& Field = Shape.GetField(Cache.FieldIndex);
46 if (bNewField)
47 {
48 SetEmergentType(Context, FHeap::EmergentTypeOffsetToPtr(Cache.NextEmergentTypeOffset));
49 if (Field.IsProperty())
50 {
51 Field.UProperty->InitializeValue_InContainer(UEObject);
52 if (Field.Type == EFieldType::FVerseProperty)
53 {
54 Field.UProperty->ContainerPtrToValuePtr<VRestValue>(UEObject)->Reset(0);
55 }
56 }
57 }
58 break;
59 }
60 }
61 return bNewField;
62}
63
64inline bool VNativeConstructorWrapper::CreateField(FAllocationContext Context, VUniqueString& FieldName, FCreateFieldCacheCase* OutCacheCase)
65{
66 if (VNativeStruct* NativeStruct = WrappedObject().template DynamicCast<VNativeStruct>())
67 {
68 if (VShape* Shape = NativeStruct->GetEmergentType()->Shape.Get())
69 {
70 FSetElementId FieldIndex = Shape->Fields.FindId({Context, FieldName});
71 const VShape::VEntry& Field = Shape->Fields.Get(FieldIndex).Value;
72 if (Field.IsProperty() || Field.IsAccessor())
73 {
74 if (IsFieldCreated(FieldIndex.AsInteger()))
75 {
76 if (OutCacheCase)
77 {
78 OutCacheCase->Kind = FCreateFieldCacheCase::EKind::NativeStruct;
79 OutCacheCase->FieldIndex = FieldIndex.AsInteger();
80 OutCacheCase->NextEmergentTypeOffset = FHeap::EmergentTypePtrToOffset(GetEmergentType());
81 }
82 return false;
83 }
84 VEmergentType* NewType = GetEmergentType()->MarkFieldAsCreated(Context, FieldIndex.AsInteger());
85 SetEmergentType(Context, NewType);
86 if (OutCacheCase)
87 {
88 OutCacheCase->Kind = FCreateFieldCacheCase::EKind::NativeStruct;
89 OutCacheCase->FieldIndex = FieldIndex.AsInteger();
90 OutCacheCase->NextEmergentTypeOffset = FHeap::EmergentTypePtrToOffset(NewType);
91 }
92
93 if (Field.IsProperty())
94 {
95 void* Data = NativeStruct->GetData(*NativeStruct->GetEmergentType()->CppClassInfo);
96 Field.UProperty->InitializeValue_InContainer(Data);
97 if (Field.Type == EFieldType::FVerseProperty)
98 {
99 Field.UProperty->ContainerPtrToValuePtr<VRestValue>(Data)->Reset(0);
100 }
101 }
102 return true;
103 }
104 }
105 }
106 else if (UObject* UEObject = WrappedObject().ExtractUObject(); UEObject)
107 {
109 {
110 VShape& Shape = VerseClass->Shape.Get(Context).StaticCast<VShape>();
111 FSetElementId FieldIndex = Shape.Fields.FindId({Context, FieldName});
112 const VShape::VEntry& Field = Shape.Fields.Get(FieldIndex).Value;
113 if (Field.IsProperty() || Field.IsAccessor())
114 {
115 if (IsFieldCreated(FieldIndex.AsInteger()))
116 {
117 if (OutCacheCase)
118 {
119 OutCacheCase->Kind = FCreateFieldCacheCase::EKind::UObject;
120 OutCacheCase->FieldIndex = FieldIndex.AsInteger();
121 OutCacheCase->NextEmergentTypeOffset = FHeap::EmergentTypePtrToOffset(GetEmergentType());
122 }
123 return false;
124 }
125 VEmergentType* NewType = GetEmergentType()->MarkFieldAsCreated(Context, FieldIndex.AsInteger());
126 SetEmergentType(Context, NewType);
127 if (OutCacheCase)
128 {
129 OutCacheCase->Kind = FCreateFieldCacheCase::EKind::UObject;
130 OutCacheCase->FieldIndex = FieldIndex.AsInteger();
131 OutCacheCase->NextEmergentTypeOffset = FHeap::EmergentTypePtrToOffset(NewType);
132 }
133
134 if (Field.IsProperty())
135 {
136 Field.UProperty->InitializeValue_InContainer(UEObject);
137 if (Field.Type == EFieldType::FVerseProperty)
138 {
139 Field.UProperty->ContainerPtrToValuePtr<VRestValue>(UEObject)->Reset(0);
140 }
141 }
142 return true;
143 }
144 }
145 }
146 V_DIE("Could not create field for imported class/struct!");
147 return false;
148}
149
150inline int32 VNativeConstructorWrapper::GetFieldIndex(FAllocationContext Context, VUniqueString& FieldName)
151{
153 {
154 VEmergentType* EmergentType = NativeStruct->GetEmergentType();
155 if (VShape* Shape = EmergentType->Shape.Get())
156 {
157 const VShape::VEntry* Field = Shape->GetField(FieldName);
158 if (Field->IsProperty() || Field->IsAccessor())
159 {
160 return Shape->GetFieldIndex(Context, FieldName);
161 }
162 }
163 }
164 else if (UObject* UEObject = WrappedObject().ExtractUObject(); UEObject)
165 {
167 {
168 VShape& Shape = VerseClass->Shape.Get(Context).StaticCast<VShape>();
169 const VShape::VEntry* Field = Shape.GetField(FieldName);
170 if (Field->IsProperty() || Field->IsAccessor())
171 {
172 return Shape.GetFieldIndex(Context, FieldName);
173 }
174 }
175 }
176 return -1;
177}
178
179inline VValue VNativeConstructorWrapper::WrappedObject() const
180{
181 return NativeObject.Get();
182}
183} // namespace Verse
184#endif // WITH_VERSE_VM
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition SetUtilities.h:95
constexpr UE_FORCEINLINE_HINT int32 AsInteger() const
Definition SetUtilities.h:116
Definition Object.h:95
Definition VVMVerseClass.h:137
GeometryCollection::Facades::FMuscleActivationData Data
Definition MuscleActivationConstraints.h:15
Definition FieldSystemNoiseAlgo.cpp:6
Definition Archive.h:36