Skip to content

Commit e3a4ba9

Browse files
committed
Update to version 1.4.1. Code refactoring and decomposition. Improving code security. Cleaning up the chaos in the DemoFiles folder after the latest patch and putting things in order. Redesign of the data asset loading tag system.
1 parent a11696b commit e3a4ba9

14 files changed

Lines changed: 639 additions & 534 deletions

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.4.0",
4+
"VersionName": "1.4.1",
55
"FriendlyName": "Async Data Asset Manager",
66
"Description": "Asynchronous management of data assets.",
77
"Category": "Async Technologies",
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Pavel Gornostaev <https://github.com/Pavreally>
2+
3+
#include "AsyncDataAssetManagerSubsystem.h"
4+
5+
#include "Engine/AssetManager.h"
6+
#include "Engine/DataAsset.h"
7+
#include "AsyncTechnologiesSettings.h"
8+
9+
TArray<FMirrorADAM> UAsyncDataAssetManagerSubsystem::GetDataADAM()
10+
{
11+
int32 Length = DataADAM.Num();
12+
TArray<FMirrorADAM> MirrorDataADAM;
13+
14+
if (Length == 0)
15+
return MirrorDataADAM;
16+
17+
for (int32 i = 0; i < Length; i++)
18+
{
19+
FMirrorADAM MirrorDataAsset;
20+
MirrorDataAsset.PrimaryDataAssetName = DataADAM[i].SoftReference.GetAssetName();
21+
MirrorDataAsset.SoftReference = DataADAM[i].SoftReference;
22+
MirrorDataAsset.Tag = DataADAM[i].Tag;
23+
MirrorDataADAM.Add(MirrorDataAsset);
24+
}
25+
26+
return MirrorDataADAM;
27+
}
28+
29+
TMap<FName, int32> UAsyncDataAssetManagerSubsystem::GetCollectionByTagADAM()
30+
{
31+
TMap<FName, int32> TagCollection;
32+
33+
if (DataADAM.Num() == 0)
34+
return TagCollection;
35+
36+
for (const FMemoryADAM& Data : DataADAM)
37+
{
38+
if (TagCollection.Contains(Data.Tag))
39+
{
40+
TagCollection[Data.Tag]++;
41+
}
42+
else
43+
{
44+
TagCollection.Add(Data.Tag, 1);
45+
}
46+
}
47+
48+
return TagCollection;
49+
}
50+
51+
UObject* UAsyncDataAssetManagerSubsystem::GetObjectDataADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, bool& IsValid )
52+
{
53+
if (PrimaryDataAsset.IsNull())
54+
{
55+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Get Object): No reference is specified in function."));
56+
57+
return nullptr;
58+
}
59+
60+
int32 ObjectIndex = GetIndexDataADAM(PrimaryDataAsset);
61+
62+
if (ObjectIndex == -1)
63+
{
64+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Get Object): The requested data asset \"%s\" is not in the memory of the ADAM subsystem."), *PrimaryDataAsset.GetAssetName());
65+
66+
return nullptr;
67+
}
68+
69+
UObject* DataAsset = DataADAM[ObjectIndex].MemoryReference->GetLoadedAsset();
70+
71+
// Return bool value. Checking of Data Asset
72+
IsValid = DataAsset != nullptr;
73+
74+
return DataAsset;
75+
}
76+
77+
int32 UAsyncDataAssetManagerSubsystem::GetIndexDataADAM(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset)
78+
{
79+
for (int32 i = 0; i < DataADAM.Num(); i++)
80+
{
81+
if (DataADAM[i].SoftReference == PrimaryDataAsset)
82+
return i;
83+
}
84+
85+
return -1;
86+
}
87+
88+
TArray<TSoftObjectPtr<UPrimaryDataAsset>> UAsyncDataAssetManagerSubsystem::FindNestedAssets(UPrimaryDataAsset* DataAsset)
89+
{
90+
TArray<TSoftObjectPtr<UPrimaryDataAsset>> NestedAssets;
91+
92+
if (!DataAsset)
93+
{
94+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Recursive Load): Received a null value."));
95+
96+
return NestedAssets;
97+
}
98+
99+
// Storage of unique asset names for duplicate control.
100+
TArray<FString> UniqueAssetNames;
101+
102+
// Use reflection to search for nested Data Assets
103+
for (TFieldIterator<FProperty> PropIterator(DataAsset->GetClass()); PropIterator; ++PropIterator)
104+
{
105+
const FProperty* Prop = *PropIterator;
106+
107+
// Look for properties of type TSoftObjectPtr<UPrimaryDataAsset>
108+
if (const FSoftObjectProperty* SoftObjectProperty = CastField<FSoftObjectProperty>(Prop))
109+
{
110+
if (SoftObjectProperty->PropertyClass->IsChildOf(UPrimaryDataAsset::StaticClass()))
111+
{
112+
TSoftObjectPtr<UPrimaryDataAsset> ChildAsset = *SoftObjectProperty->ContainerPtrToValuePtr<TSoftObjectPtr<UPrimaryDataAsset>>(DataAsset);
113+
FString ChildAssetName = ChildAsset.GetAssetName();
114+
// Filtering and adding data
115+
if (!ChildAssetName.IsEmpty() && !UniqueAssetNames.Contains(ChildAssetName))
116+
{
117+
UniqueAssetNames.AddUnique(ChildAssetName);
118+
NestedAssets.Add(ChildAsset);
119+
}
120+
}
121+
}
122+
123+
// If the array of soft references
124+
if (const FArrayProperty* ArrayProp = CastField<FArrayProperty>(Prop))
125+
{
126+
if (const FSoftObjectProperty* InnerSoftObjectProperty = CastField<FSoftObjectProperty>(ArrayProp->Inner))
127+
{
128+
if (InnerSoftObjectProperty->PropertyClass->IsChildOf(UPrimaryDataAsset::StaticClass()))
129+
{
130+
FScriptArrayHelper ArrayHelper(ArrayProp, ArrayProp->ContainerPtrToValuePtr<void>(DataAsset));
131+
132+
for (int32 i = 0; i < ArrayHelper.Num(); ++i)
133+
{
134+
TSoftObjectPtr<UPrimaryDataAsset> ChildAsset = *reinterpret_cast<TSoftObjectPtr<UPrimaryDataAsset>*>(ArrayHelper.GetRawPtr(i));
135+
FString ChildAssetName = ChildAsset.GetAssetName();
136+
// Filtering and adding data
137+
if (!ChildAssetName.IsEmpty() && !UniqueAssetNames.Contains(ChildAssetName))
138+
{
139+
UniqueAssetNames.AddUnique(ChildAssetName);
140+
NestedAssets.Add(ChildAsset);
141+
}
142+
}
143+
}
144+
}
145+
}
146+
}
147+
148+
if (EnableLog && NestedAssets.Num() == 0)
149+
{
150+
UE_LOG(LogTemp, Display, TEXT("ADAM (Recursive data): Iteration is complete. All nested data is loaded!"));
151+
}
152+
153+
return NestedAssets;
154+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Pavel Gornostaev <https://github.com/Pavreally>
2+
3+
#include "AsyncDataAssetManagerSubsystem.h"
4+
5+
#include "Engine/AssetManager.h"
6+
#include "Engine/DataAsset.h"
7+
#include "AsyncTechnologiesSettings.h"
8+
9+
void UAsyncDataAssetManagerSubsystem::RecursiveLoad(TSoftObjectPtr<UPrimaryDataAsset> PrimaryDataAsset, FName Tag, bool NotifyAfterFullLoaded)
10+
{
11+
if (PrimaryDataAsset.IsNull())
12+
{
13+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Recursive Load): No reference is specified in function."));
14+
15+
return;
16+
}
17+
18+
UPrimaryDataAsset* Asset = PrimaryDataAsset.Get();
19+
20+
if (!Asset)
21+
{
22+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Recursive Load): Received a null value."));
23+
24+
return;
25+
}
26+
27+
// Checking nested files
28+
TArray<TSoftObjectPtr<UPrimaryDataAsset>> NestedAssets = FindNestedAssets(Asset);
29+
30+
if (NestedAssets.Num() == 0)
31+
{
32+
if (EnableLog)
33+
{
34+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Recursive Load): No nested files were found in file \"%s\"."), *PrimaryDataAsset.GetAssetName());
35+
}
36+
37+
return;
38+
}
39+
40+
for (TSoftObjectPtr<UPrimaryDataAsset>& NestedAsset : NestedAssets)
41+
{
42+
// Calling asynchronous loading
43+
if (!NotifyAfterFullLoaded)
44+
{
45+
// Stop execution if there is a duplicate in memory
46+
if (GetIndexDataADAM(NestedAsset) >= 0)
47+
{
48+
if (EnableLog)
49+
{
50+
UE_LOG(LogTemp, Warning, TEXT("ADAM (Recursive Load): You are trying to load the same Data Asset \"%s\" twice."), *NestedAsset.GetAssetName());
51+
}
52+
53+
continue;
54+
}
55+
56+
AddToADAM(NestedAsset, Tag, true);
57+
}
58+
else
59+
{
60+
AddAllToADAM(NestedAsset, Tag, true);
61+
}
62+
}
63+
}
64+
65+
FName UAsyncDataAssetManagerSubsystem::GetTagNameFromStruct(FTagADAM& Tag)
66+
{
67+
if (Tag.GameplayTag.IsValid())
68+
{
69+
return Tag.GameplayTag.GetTagName();
70+
}
71+
else if (!Tag.TagName.IsNone())
72+
{
73+
return Tag.TagName;
74+
}
75+
76+
return NAME_None;
77+
}

0 commit comments

Comments
 (0)