MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / loadAsset

Method loadAsset

Source/Engine/Level/Prefabs/Prefab.cpp:126–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126Asset::LoadResult Prefab::loadAsset()
127{
128 // Base
129 const auto result = JsonAssetBase::loadAsset();
130 if (result != LoadResult::Ok)
131 return result;
132
133 // Validate data schema
134 if (!Data->IsArray())
135 {
136 LOG(Warning, "Invalid prefab data.");
137 return LoadResult::InvalidData;
138 }
139
140 // Get objects amount
141 const int32 objectsCount = Data->GetArray().Size();
142 if (objectsCount <= 0)
143 {
144 LOG(Warning, "Prefab is empty or has invalid amount of objects.");
145 return LoadResult::InvalidData;
146 }
147
148 // Allocate memory for objects
149 ObjectsIds.EnsureCapacity(objectsCount);
150 ObjectsDataCache.EnsureCapacity(objectsCount);
151
152 // Find serialized object ids (actors and scripts), they are used later for IDs mapping on prefab spawning via PrefabManager
153 const auto& data = *Data;
154 for (int32 objectIndex = 0; objectIndex < objectsCount; objectIndex++)
155 {
156 auto& objData = data[objectIndex];
157
158 Guid objectId = JsonTools::GetGuid(objData, "ID");
159 if (!objectId.IsValid())
160 {
161 LOG(Warning, "The object inside prefab has invalid ID.");
162 return LoadResult::InvalidData;
163 }
164
165 ObjectsIds.Add(objectId);
166 ObjectsDataCache.Add(objectId, &objData);
167 ObjectsCount++;
168
169 Guid parentID;
170 if (JsonTools::GetGuidIfValid(parentID, objData, "ParentID"))
171 ObjectsHierarchyCache[parentID].Add(objectId);
172
173 Guid prefabId = JsonTools::GetGuid(objData, "PrefabID");
174 if (prefabId.IsValid() && !NestedPrefabs.Contains(prefabId))
175 {
176 if (prefabId == _id)
177 {
178 LOG(Error, "Circular reference in prefab.");
179 return LoadResult::InvalidData;
180 }
181
182 NestedPrefabs.Add(prefabId);
183 }

Callers

nothing calls this directly

Calls 7

GetGuidFunction · 0.85
SizeMethod · 0.45
GetArrayMethod · 0.45
EnsureCapacityMethod · 0.45
IsValidMethod · 0.45
AddMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected