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

Method Deserialize

Source/Engine/Level/SceneObjectsFactory.cpp:259–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259void SceneObjectsFactory::Deserialize(Context& context, SceneObject* obj, ISerializable::DeserializeStream& stream)
260{
261 CHECK_DEBUG(obj);
262 ISerializeModifier* modifier = context.GetModifier();
263 LogContextScope logContext(obj->GetID());
264
265 // Check for prefab instance
266 Guid prefabObjectId;
267 if (JsonTools::GetGuidIfValid(prefabObjectId, stream, "PrefabObjectID"))
268 {
269 // Get prefab asset id
270 const Guid prefabId = JsonTools::GetGuid(stream, "PrefabID");
271 if (!prefabId.IsValid())
272 {
273 LOG(Warning, "Invalid prefab id.");
274 return;
275 }
276
277 // Load prefab
278 auto prefab = Content::LoadAsync<Prefab>(prefabId);
279 if (prefab == nullptr)
280 {
281 LOG(Warning, "Missing prefab {0}.", prefabId);
282 return;
283 }
284 if (prefab->WaitForLoaded())
285 {
286 LOG(Warning, "Failed to load prefab {0}.", prefab->ToString());
287 return;
288 }
289
290 // Get prefab object data from the prefab
291 const ISerializable::DeserializeStream* prefabData;
292 if (!prefab->ObjectsDataCache.TryGet(prefabObjectId, prefabData))
293 {
294 LOG(Warning, "Missing object {1} data in prefab {0}.", prefab->ToString(), prefabObjectId);
295 return;
296 }
297
298 // Deserialize prefab data (recursive prefab loading to support nested prefabs)
299 const auto prevVersion = modifier->EngineBuild;
300 modifier->EngineBuild = prefab->DataEngineBuild;
301#if USE_EDITOR
302 bool prevDeprecated = ContentDeprecated::Clear();
303#endif
304 Deserialize(context, obj, *(ISerializable::DeserializeStream*)prefabData);
305#if USE_EDITOR
306 if (ContentDeprecated::Clear(prevDeprecated))
307 {
308 // Prefab contains deprecated data format
309 context.Locker.Lock();
310 context.DeprecatedPrefabs.Add(prefab);
311 context.Locker.Unlock();
312 }
313#endif
314 modifier->EngineBuild = prevVersion;
315 }
316

Callers 1

SetReferenceScriptMethod · 0.45

Calls 13

GetGuidFunction · 0.85
GetModifierMethod · 0.80
GetIDMethod · 0.80
WaitForLoadedMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
SetupIdsMappingMethod · 0.80
ClearFunction · 0.50
DeserializeFunction · 0.50
IsValidMethod · 0.45
ToStringMethod · 0.45
TryGetMethod · 0.45

Tested by

no test coverage detected