Skip to content

Commit a656555

Browse files
committed
Update to version 1.1. Optimization and security improved. Tag support added.
1 parent 1c51d05 commit a656555

8 files changed

Lines changed: 128 additions & 41 deletions

File tree

Plugins/AsyncDataAssetManager/AsyncDataAssetManager.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "1.0",
4+
"VersionName": "1.1",
55
"FriendlyName": "Async Data Asset Manager",
66
"Description": "Asynchronous management of data assets.",
77
"Category": "Async Technologies",
Binary file not shown.

Plugins/AsyncDataAssetManager/Source/AsyncDataAssetManager/Private/AsyncDataAssetManagerSubsystem.cpp

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "AsyncTechnologiesSettings.h"
88

99
// Initialize subsystem
10-
void UAsyncDataAssetManagerSubsystem::Initialize(FSubsystemCollectionBase &Collection)
10+
void UAsyncDataAssetManagerSubsystem::Initialize(FSubsystemCollectionBase& Collection)
1111
{
1212
Super::Initialize(Collection);
1313

@@ -24,13 +24,13 @@ void UAsyncDataAssetManagerSubsystem::Deinitialize()
2424
{
2525
Super::Deinitialize();
2626

27-
DataADAM.Empty();
27+
UnloadAllADAM(true);
2828

2929
OnLoadedADAM.Clear();
3030
}
3131

3232
// BlueprintCallable Function. Asynchronous loading of Primary Data Asset
33-
void UAsyncDataAssetManagerSubsystem::LoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, TSoftObjectPtr<UPrimaryDataAsset> &ReturnPrimaryDataAsset)
33+
void UAsyncDataAssetManagerSubsystem::LoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, FName Tag, TSoftObjectPtr<UPrimaryDataAsset>& ReturnPrimaryDataAsset)
3434
{
3535
if (PrimaryDataAsset.IsNull())
3636
{
@@ -49,14 +49,14 @@ void UAsyncDataAssetManagerSubsystem::LoadADAM(TSoftObjectPtr<UPrimaryDataAsset>
4949
}
5050

5151
// Add in array ADAM and async load
52-
AddToADAM(PrimaryDataAsset);
52+
AddToADAM(PrimaryDataAsset, Tag);
5353

5454
// Return the value of a soft link
5555
ReturnPrimaryDataAsset = PrimaryDataAsset;
5656
}
5757

5858
// BlueprintCallable Function. Asynchronous loading of an array of Primary Data Asset
59-
void UAsyncDataAssetManagerSubsystem::LoadArrayADAM(TArray<TSoftObjectPtr<UPrimaryDataAsset>> PrimaryDataAssets, TArray<TSoftObjectPtr<UPrimaryDataAsset>> &ReturnPrimaryDataAssets)
59+
void UAsyncDataAssetManagerSubsystem::LoadArrayADAM(TArray<TSoftObjectPtr<UPrimaryDataAsset>> PrimaryDataAssets, FName Tag, TArray<TSoftObjectPtr<UPrimaryDataAsset>>& ReturnPrimaryDataAssets)
6060
{
6161
if (PrimaryDataAssets.IsEmpty())
6262
{
@@ -77,15 +77,15 @@ void UAsyncDataAssetManagerSubsystem::LoadArrayADAM(TArray<TSoftObjectPtr<UPrima
7777
}
7878

7979
// Add in array ADAM and async load
80-
AddToADAM(DataAsset);
80+
AddToADAM(DataAsset, Tag);
8181
}
8282

8383
// Return an array of soft links
8484
ReturnPrimaryDataAssets = PrimaryDataAssets;
8585
}
8686

8787
// Add Data Asset to the ADAM array and load asynchronously
88-
void UAsyncDataAssetManagerSubsystem::AddToADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset)
88+
void UAsyncDataAssetManagerSubsystem::AddToADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, FName Tag)
8989
{
9090
// Create a delegate
9191
FStreamableManager& StreamableManager = UAssetManager::GetStreamableManager();
@@ -110,6 +110,7 @@ void UAsyncDataAssetManagerSubsystem::AddToADAM(TSoftObjectPtr<UPrimaryDataAsset
110110
FMemoryADAM NewDataAsset;
111111
NewDataAsset.SoftReference = PrimaryDataAsset;
112112
NewDataAsset.MemoryReference = DataAssetHandle;
113+
NewDataAsset.Tag = Tag;
113114
DataADAM.Add(NewDataAsset);
114115
}
115116

@@ -131,7 +132,7 @@ void UAsyncDataAssetManagerSubsystem::OnLoaded(TSoftObjectPtr<UPrimaryDataAsset>
131132
}
132133

133134
// Loading a Data Asset without storing it in memory
134-
void UAsyncDataAssetManagerSubsystem::FastLoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, TSoftObjectPtr<UPrimaryDataAsset> &ReturnPrimaryDataAsset)
135+
void UAsyncDataAssetManagerSubsystem::FastLoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, TSoftObjectPtr<UPrimaryDataAsset>& ReturnPrimaryDataAsset)
135136
{
136137
if (PrimaryDataAsset.IsNull())
137138
{
@@ -178,14 +179,17 @@ void UAsyncDataAssetManagerSubsystem::UnloadADAM(TSoftObjectPtr<UPrimaryDataAsse
178179
return;
179180
}
180181

182+
// Deletion of target data from ADAM if deletion by tag was not triggered.
181183
int32 TargetIndex = GetIndexDataADAM(PrimaryDataAsset);
182184

183-
RemoveFromADAM(TargetIndex, ForcedUnload);
185+
if (TargetIndex == -1) return;
184186

185187
if (EnableLog)
186188
{
187189
UE_LOG(LogTemp, Display, TEXT("ADAM: Unload data asset \"%s\" (index: %d)"), *PrimaryDataAsset.GetAssetName(), TargetIndex);
188190
}
191+
192+
RemoveFromADAM(TargetIndex, ForcedUnload);
189193
}
190194

191195
// BlueprintCallable Function. Unload all items from the ADAM collection
@@ -197,14 +201,36 @@ void UAsyncDataAssetManagerSubsystem::UnloadAllADAM(bool ForcedUnload)
197201
return;
198202
}
199203

204+
// Remove all from ADAM
200205
for (int32 i = DataADAM.Num() - 1; i >= 0; i--)
201206
{
202-
RemoveFromADAM(i, ForcedUnload);
203-
204207
if (EnableLog)
205208
{
206209
UE_LOG(LogTemp, Display, TEXT("ADAM: Unload data asset (index: %d)"), i);
207210
}
211+
212+
RemoveFromADAM(i, ForcedUnload);
213+
}
214+
}
215+
216+
// Unload all data assets with the specified tag from the array and memory. Unloading in descending order.
217+
void UAsyncDataAssetManagerSubsystem::UnloadAllTagsADAM(FName Tag, bool ForcedUnload)
218+
{
219+
// Remove of all data with a similar target tag
220+
if (Tag != "None")
221+
{
222+
for (int32 i = DataADAM.Num() - 1; i >= 0; i--)
223+
{
224+
if (DataADAM[i].Tag == Tag)
225+
{
226+
if (EnableLog)
227+
{
228+
UE_LOG(LogTemp, Display, TEXT("ADAM: Unload data asset \"%s\" (index: %d)"), *DataADAM[i].SoftReference.GetAssetName(), i);
229+
}
230+
231+
RemoveFromADAM(i, ForcedUnload);
232+
}
233+
}
208234
}
209235
}
210236

@@ -231,25 +257,50 @@ void UAsyncDataAssetManagerSubsystem::RemoveFromADAM(int32 DataAssetIndex, bool
231257
}
232258
}
233259

234-
// BlueprintCallable Function. Return the length of the main array of the subsystem - DataADAM
235-
void UAsyncDataAssetManagerSubsystem::GetDataADAM(TArray<FMirrorADAM> &MirrorDataADAM, int32 &Length)
260+
// BlueprintCallable Function. Returns the ADAM mirror array formed it the main array with a reference to the destructor.
261+
TArray<FMirrorADAM> UAsyncDataAssetManagerSubsystem::GetDataADAM()
262+
{
263+
int32 Length = DataADAM.Num();
264+
TArray<FMirrorADAM> MirrorDataADAM;
265+
266+
if (Length == 0) return MirrorDataADAM;
267+
268+
for (int32 i = 0; i < Length; i++)
269+
{
270+
FMirrorADAM MirrorDataAsset;
271+
MirrorDataAsset.PrimaryDataAssetName = DataADAM[i].SoftReference.GetAssetName();
272+
MirrorDataAsset.SoftReference = DataADAM[i].SoftReference;
273+
MirrorDataAsset.Tag = DataADAM[i].Tag;
274+
MirrorDataADAM.Add(MirrorDataAsset);
275+
}
276+
277+
return MirrorDataADAM;
278+
}
279+
280+
// BlueprintCallable Function. Returns an TMap that shows how many data items there are in the ADAM system for each unique tag.
281+
TMap<FName, int32> UAsyncDataAssetManagerSubsystem::GetCollectionByTagADAM()
236282
{
237-
Length = DataADAM.Num();
283+
TMap<FName, int32> TagCollection;
284+
285+
if (DataADAM.Num() == 0) return TagCollection;
238286

239-
if (Length >= 0)
287+
for (const FMemoryADAM& Data : DataADAM)
240288
{
241-
for (int32 i = 0; i < Length; i++)
289+
if (TagCollection.Contains(Data.Tag))
242290
{
243-
FMirrorADAM MirrorDataAsset;
244-
MirrorDataAsset.PrimaryDataAssetName = DataADAM[i].SoftReference.GetAssetName();
245-
MirrorDataAsset.SoftReference = DataADAM[i].SoftReference;
246-
MirrorDataADAM.Add(MirrorDataAsset);
291+
TagCollection[Data.Tag]++;
292+
}
293+
else
294+
{
295+
TagCollection.Add(Data.Tag, 1);
247296
}
248297
}
298+
299+
return TagCollection;
249300
}
250301

251302
// BlueprintCallable Function. Returns a pointer to the Data Asset (ADAM) object stored in memory.
252-
UObject* UAsyncDataAssetManagerSubsystem::GetObjectDataADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, bool &IsValid )
303+
UObject* UAsyncDataAssetManagerSubsystem::GetObjectDataADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, bool& IsValid )
253304
{
254305
if (PrimaryDataAsset.IsNull())
255306
{

Plugins/AsyncDataAssetManager/Source/AsyncDataAssetManager/Public/AsyncDataAssetManagerSubsystem.h

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ struct FMemoryADAM
1818
GENERATED_USTRUCT_BODY()
1919

2020
public:
21+
UPROPERTY()
2122
TSoftObjectPtr<UPrimaryDataAsset> SoftReference;
2223

2324
TSharedPtr<FStreamableHandle> MemoryReference;
25+
26+
UPROPERTY()
27+
FName Tag;
2428
};
2529

2630
// Designed to output information about the current storage of data assets.
@@ -35,6 +39,9 @@ struct FMirrorADAM
3539

3640
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "ADAM Subsystem")
3741
TSoftObjectPtr<UPrimaryDataAsset> SoftReference;
42+
43+
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "ADAM Subsystem")
44+
FName Tag;
3845
};
3946

4047
#pragma endregion STRUCTS
@@ -48,14 +55,14 @@ class ASYNCDATAASSETMANAGER_API UAsyncDataAssetManagerSubsystem : public UGameIn
4855
GENERATED_BODY()
4956

5057
public:
51-
virtual void Initialize(FSubsystemCollectionBase &Collection) override;
58+
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
5259
virtual void Deinitialize() override;
5360

5461
#pragma region DELEGATES
5562
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnLoadedADAM, UObject*, LoadedObject, TSoftObjectPtr<UPrimaryDataAsset>, LoadedPrimaryDataAsset);
5663

5764
// Indicates that the download is complete
58-
UPROPERTY(BLueprintAssignable, Category = "ADAM Subsystem")
65+
UPROPERTY(BlueprintAssignable, Category = "ADAM Subsystem")
5966
FOnLoadedADAM OnLoadedADAM;
6067

6168
#pragma endregion DELEGATES
@@ -71,21 +78,26 @@ class ASYNCDATAASSETMANAGER_API UAsyncDataAssetManagerSubsystem : public UGameIn
7178
TArray<FString> QueueADAM;
7279

7380
#pragma region BlueprintFunctions
74-
// Async loading of a Data Asset and storing it in memory.
81+
/**
82+
* Async loading of a Data Asset and storing it in memory.
83+
* @param Tag Designed for data grouping.
84+
*/
7585
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
76-
void LoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, TSoftObjectPtr<UPrimaryDataAsset> &ReturnPrimaryDataAsset);
86+
void LoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, FName Tag, TSoftObjectPtr<UPrimaryDataAsset>& ReturnPrimaryDataAsset);
7787

78-
// Async loading of an array of Data Asset and storing each element in memory.
88+
/**
89+
* Async loading of an array of Data Asset and storing each element in memory.
90+
* @param Tag Designed for data grouping.
91+
*/
7992
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
80-
void LoadArrayADAM(TArray<TSoftObjectPtr<UPrimaryDataAsset>> PrimaryDataAssets, TArray<TSoftObjectPtr<UPrimaryDataAsset>> &ReturnPrimaryDataAssets);
93+
void LoadArrayADAM(TArray<TSoftObjectPtr<UPrimaryDataAsset>> PrimaryDataAssets, FName Tag, TArray<TSoftObjectPtr<UPrimaryDataAsset>>& ReturnPrimaryDataAssets);
8194

8295
// Loading a Data Asset without storing it in memory.
8396
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
84-
void FastLoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, TSoftObjectPtr<UPrimaryDataAsset> &ReturnPrimaryDataAsset);
97+
void FastLoadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, TSoftObjectPtr<UPrimaryDataAsset>& ReturnPrimaryDataAsset);
8598

8699
/**
87100
* Unload one Data Asset from array and memory.
88-
*
89101
* @param ForcedUnload If true, the function call will stop loading the Data Asset
90102
* asynchronously and will make the target resource available for memory freeing,
91103
* on the next rubbish collection. If false, the function call will immediately clear memory from the target resource.
@@ -94,8 +106,7 @@ class ASYNCDATAASSETMANAGER_API UAsyncDataAssetManagerSubsystem : public UGameIn
94106
void UnloadADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, bool ForcedUnload);
95107

96108
/**
97-
* Unload all Data Assets from array and memory. Unloading takes place in the order of very.
98-
*
109+
* Unload all Data Assets from array and memory. Unloading in descending order.
99110
* @param ForcedUnload If true, the function call will stop loading the Data Asset
100111
* asynchronously and will make the target resource available for memory freeing,
101112
* on the next rubbish collection. If false, the function call will immediately clear memory from the target resource.
@@ -104,17 +115,35 @@ class ASYNCDATAASSETMANAGER_API UAsyncDataAssetManagerSubsystem : public UGameIn
104115
void UnloadAllADAM(bool ForcedUnload);
105116

106117
/**
107-
* Returns the state of the main Data ADAM array
118+
* Unload all data assets with the specified tag from the array and memory. Unloading in descending order.
119+
* @param Tag Alternative deletion option. If this value is changed, all Data Assets with the specified tag will be removed from memory.
120+
* @param ForcedUnload If true, the function call will stop loading the Data Asset
121+
* asynchronously and will make the target resource available for memory freeing,
122+
* on the next rubbish collection. If false, the function call will immediately clear memory from the target resource.
123+
*/
124+
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
125+
void UnloadAllTagsADAM(FName Tag, bool ForcedUnload);
126+
127+
/**
128+
* Returns the ADAM mirror array formed it the main array with a reference to the destructor.
129+
* @return Returns a mirrored array of DataADAM.
130+
*/
131+
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
132+
TArray<FMirrorADAM> GetDataADAM();
133+
134+
/**
135+
* Returns an array that shows how many data items there are in the ADAM system for each unique tag.
136+
* @return Returns the tag values and the corresponding number of Data Assets.
108137
*/
109138
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
110-
void GetDataADAM(TArray<FMirrorADAM> &MirrorDataADAM, int32 &Length);
139+
TMap<FName, int32> GetCollectionByTagADAM();
111140

112141
/**
113142
* Returns a pointer to the Data Asset ADAM object stored in memory.
114143
* @param IsValid Returns the validity state of the object.
115144
*/
116145
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
117-
UObject* GetObjectDataADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, bool &IsValid);
146+
UObject* GetObjectDataADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, bool& IsValid);
118147

119148
// Returns the index from the array of the ADAM data asset collection. If nothing is found returns -1.
120149
UFUNCTION(BlueprintCallable, Category = "ADAM Subsystem")
@@ -134,7 +163,7 @@ class ASYNCDATAASSETMANAGER_API UAsyncDataAssetManagerSubsystem : public UGameIn
134163
void RemoveFromADAM(int32 DataAssetIndex, bool ForcedUnload);
135164

136165
UFUNCTION()
137-
void AddToADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset);
166+
void AddToADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, FName Tag);
138167

139168
UFUNCTION()
140169
void OnLoaded(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset);

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
# Async Data Asset Manager
44
`BETA`<br><br>
5-
ADAM is a plugin for Unreal Engine 5 that adds a subsystem for managing asynchronous loading and unloading of Data Assets. This subsystem simplifies the approach to data management, which can be used in both Blueprint and C++.
5+
ADAM is a plugin for Unreal Engine 5 that adds a subsystem for asynchronous loading and unloading of Data Assets. This subsystem simplifies data management and can be used in both Blueprints and C++.
66

7-
<br><br><i>(The plugin has been pre-packaged only for Win64 and Android)</i>
7+
<br>
8+
> [!NOTE]
9+
> The plugin has been pre-packaged only for Win64 and Android.
810
911
# Latest Updates
10-
`Version 1.0`
12+
`Version 1.1`
1113
- Build version for Unreal Engine 5.5.
12-
- Release experimental version of the plugin.
14+
- Refactoring and optimization of the code.
15+
- Enhanced security for memory resource management.
16+
- Added the ability to specify a tag for uploaded files.
17+
- Added a new function `UnloadAllTagsADAM`, which will unload DataAssets stored in memory by the specified tag.
18+
- Added a new function `GetCollectionByTagADAM`, which will display a list of tags stored in the ADAM system (including default tags - NONE) and their total count.
1319

1420
## What it's for
1521
- Load and unload Data Assets asynchronously using simple functions.
@@ -19,6 +25,7 @@ ADAM is a plugin for Unreal Engine 5 that adds a subsystem for managing asynchro
1925
- Fast and simple management of asynchronous Data Asset loading without the need to use C++ code.
2026
- The ADAM subsystem supports parallel asynchronous loading of Data Assets from multiple sources, controlling random duplicate load and unload requests in real-time.
2127
- Supports bulk asynchronous loading of unique Data Assets.
28+
- Group your uploaded DataAssets using tags so that they can be unloaded at the right moment <i>(for example, this can be useful if you are uploading DataAssets in parts and want to unload them without affecting other necessary data still stored in memory)</i>.
2229
- Supports asynchronous loading without memory retention (e.g., if you need to immediately access data and then free up memory).
2330
- Disableable debug logs allow you to monitor the entire asynchronous data management process. Plugin settings are located in `Project Settings > Plugins > Async Technologies - ADAM`.
2431

@@ -36,4 +43,4 @@ An interactive step-by-step tutorial on how to use ADAM can be found in the file
3643
![Window Manager](./_Misc/Tutorial/Tutorial_3.jpg)
3744

3845
## (C++) Documentaion
39-
All sources contain self-documenting code. C++ and BP functions are completely identical and interchangeable.
46+
All sources contain self-documenting code.

_Misc/Tutorial/Tutorial_1.jpg

0 Bytes
Loading

_Misc/Tutorial/Tutorial_2.jpg

0 Bytes
Loading

_Misc/Tutorial/Tutorial_3.jpg

25.7 KB
Loading

0 commit comments

Comments
 (0)