Add content deprecation upgrades support to prefabs and scenes when loading levels

This commit is contained in:
Wojtek Figat
2025-01-20 23:53:13 +01:00
parent 67f12596e2
commit 7d0804af91
7 changed files with 113 additions and 7 deletions

View File

@@ -732,6 +732,50 @@ bool Prefab::ApplyAll(Actor* targetActor)
return false;
}
bool Prefab::Resave()
{
if (OnCheckSave())
return true;
PROFILE_CPU_NAMED("Prefab.Resave");
ScopeLock lock(Locker);
Dictionary<Guid, Guid> objectIds;
objectIds.EnsureCapacity(ObjectsIds.Count());
for (int32 i = 0; i < ObjectsIds.Count(); i++)
{
Guid id = ObjectsIds[i];
objectIds.Add(id, id);
}
PrefabManager::SpawnOptions options;
options.WithLink = false;
options.IDs = &objectIds;
auto instance = PrefabManager::SpawnPrefab(this, options);
if (instance == nullptr)
return true;
// Serialize to json data
CollectionPoolCache<ActorsCache::SceneObjectsListType>::ScopeCache sceneObjects = ActorsCache::SceneObjectsListCache.Get();
SceneQuery::GetAllSerializableSceneObjects(instance, *sceneObjects.Value);
rapidjson_flax::StringBuffer dataBuffer;
{
PrettyJsonWriter writerObj(dataBuffer);
PrefabInstanceData::SerializeObjects(*sceneObjects.Value, writerObj);
}
// Remove temporary objects
instance->DeleteObject();
instance = nullptr;
// Save to file
if (CreateJson::Create(GetPath(), dataBuffer, TypeName))
{
LOG(Warning, "Failed to serialize prefab data to the asset.");
return true;
}
return false;
}
bool Prefab::ApplyAllInternal(Actor* targetActor, bool linkTargetActorObjectToPrefab, PrefabInstancesData& prefabInstancesData)
{
PROFILE_CPU_NAMED("Prefab.Apply");