@@ -36,9 +36,61 @@ URealtimeMesh::URealtimeMesh(const FObjectInitializer& ObjectInitializer)
3636{
3737}
3838
39+ void URealtimeMesh::BroadcastBoundsChangedEvent ()
40+ {
41+ if (!IsInGameThread ())
42+ {
43+ TWeakObjectPtr<URealtimeMesh> WeakThis (this );
44+ AsyncTask (ENamedThreads::GameThread, [WeakThis]()
45+ {
46+ if (const auto Mesh = WeakThis.Get ())
47+ {
48+ Mesh->BoundsChangedEvent .Broadcast (Mesh);
49+ }
50+ });
51+ }
52+ else
53+ {
54+ BoundsChangedEvent.Broadcast (this );
55+ }
56+ }
57+
58+ void URealtimeMesh::BroadcastRenderDataChangedEvent (bool bShouldRecreateProxies)
59+ {
60+ if (!IsInGameThread ())
61+ {
62+ TWeakObjectPtr<URealtimeMesh> WeakThis (this );
63+ AsyncTask (ENamedThreads::GameThread, [WeakThis, bShouldRecreateProxies]()
64+ {
65+ if (const auto Mesh = WeakThis.Get ())
66+ {
67+ Mesh->RenderDataChangedEvent .Broadcast (Mesh, bShouldRecreateProxies);
68+ }
69+ });
70+ }
71+ else
72+ {
73+ RenderDataChangedEvent.Broadcast (this , bShouldRecreateProxies);
74+ }
75+ }
76+
3977void URealtimeMesh::BroadcastCollisionBodyUpdatedEvent (UBodySetup* NewBodySetup)
4078{
41- CollisionBodyUpdatedEvent.Broadcast (this , NewBodySetup);
79+ if (!IsInGameThread ())
80+ {
81+ TWeakObjectPtr<URealtimeMesh> WeakThis (this );
82+ AsyncTask (ENamedThreads::GameThread, [WeakThis, NewBodySetup]()
83+ {
84+ if (const auto Mesh = WeakThis.Get ())
85+ {
86+ Mesh->CollisionBodyUpdatedEvent .Broadcast (Mesh, NewBodySetup);
87+ }
88+ });
89+ }
90+ else
91+ {
92+ CollisionBodyUpdatedEvent.Broadcast (this , NewBodySetup);
93+ }
4294}
4395
4496void URealtimeMesh::Initialize (const TSharedRef<RealtimeMesh::FRealtimeMeshSharedResources>& InSharedResources)
@@ -64,6 +116,8 @@ void URealtimeMesh::Initialize(const TSharedRef<RealtimeMesh::FRealtimeMeshShare
64116
65117void URealtimeMesh::Reset (bool bCreateNewMeshData)
66118{
119+ RealtimeMesh::FRealtimeMeshScopeGuardWrite ScopeGuard (SharedResources->GetGuard ());
120+
67121 UE_LOG (LogTemp, Warning, TEXT (" RM Resetting... %s" ), *GetName ());
68122 if (!bCreateNewMeshData)
69123 {
@@ -122,6 +176,8 @@ void URealtimeMesh::RemoveTrailingLOD()
122176
123177void URealtimeMesh::SetupMaterialSlot (int32 MaterialSlot, FName SlotName, UMaterialInterface* InMaterial)
124178{
179+ RealtimeMesh::FRealtimeMeshScopeGuardWrite ScopeGuard (SharedResources->GetGuard ());
180+
125181 // Does this slot already exist?
126182 if (SlotNameLookup.Contains (SlotName))
127183 {
@@ -148,39 +204,47 @@ void URealtimeMesh::SetupMaterialSlot(int32 MaterialSlot, FName SlotName, UMater
148204
149205int32 URealtimeMesh::GetMaterialIndex (FName MaterialSlotName) const
150206{
207+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
208+
151209 const int32* SlotIndex = SlotNameLookup.Find (MaterialSlotName);
152210 return SlotIndex ? *SlotIndex : INDEX_NONE;
153211}
154212
155213bool URealtimeMesh::IsMaterialSlotNameValid (FName MaterialSlotName) const
156214{
215+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
157216 return SlotNameLookup.Contains (MaterialSlotName);
158217}
159218
160219FRealtimeMeshMaterialSlot URealtimeMesh::GetMaterialSlot (int32 SlotIndex) const
161220{
221+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
162222 return MaterialSlots[SlotIndex];
163223}
164224
165225int32 URealtimeMesh::GetNumMaterials () const
166226{
227+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
167228 return MaterialSlots.Num ();
168229}
169230
170231TArray<FName> URealtimeMesh::GetMaterialSlotNames () const
171232{
233+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
172234 TArray<FName> OutNames;
173235 SlotNameLookup.GetKeys (OutNames);
174236 return OutNames;
175237}
176238
177239TArray<FRealtimeMeshMaterialSlot> URealtimeMesh::GetMaterialSlots () const
178240{
241+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
179242 return MaterialSlots;
180243}
181244
182245UMaterialInterface* URealtimeMesh::GetMaterial (int32 SlotIndex) const
183246{
247+ RealtimeMesh::FRealtimeMeshScopeGuardRead ScopeGuard (SharedResources->GetGuard ());
184248 if (MaterialSlots.IsValidIndex (SlotIndex))
185249 {
186250 return MaterialSlots[SlotIndex].Material ;
0 commit comments