Skip to content

Commit

Permalink
Prefab references still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Sep 29, 2023
1 parent f53a794 commit 2a70ac3
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 114 deletions.
28 changes: 27 additions & 1 deletion Volt/Sandbox/src/Sandbox/Window/SceneViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ void SceneViewPanel::UpdatePrefabsInScene(Ref<Volt::Prefab> prefab, Volt::Entity
return;
}

m_scene->ForEachWithComponents<const Volt::PrefabComponent>([&](const entt::entity id, const Volt::PrefabComponent& prefabComp)
m_scene->ForEachWithComponents<const Volt::PrefabComponent>([&](const entt::entity id, const Volt::PrefabComponent& prefabComp)
{
if (id == srcEntity.GetID())
{
Expand All @@ -1079,6 +1079,32 @@ void SceneViewPanel::UpdatePrefabsInScene(Ref<Volt::Prefab> prefab, Volt::Entity

prefabAsset->UpdateEntityInScene(Volt::Entity{ id, m_scene });
});

if (prefabAsset->IsReference(srcEntity))
{
m_scene->ForEachWithComponents<const Volt::PrefabComponent>([&](const entt::entity id, const Volt::PrefabComponent& prefabComp)
{
if (id == srcEntity.GetID())
{
return;
}

const auto& prefabRefData = prefabAsset->GetReferenceData(srcEntity);

if (prefabComp.prefabAsset != prefabRefData.prefabAsset || prefabComp.prefabEntity != prefabRefData.prefabReferenceEntity)
{
return;
}

Ref<Volt::Prefab> prefabRefAsset = Volt::AssetManager::GetAsset<Volt::Prefab>(prefabRefData.prefabAsset);
if (!prefabRefAsset || !prefabRefAsset->IsValid())
{
return;
}

prefabRefAsset->UpdateEntityInScene(Volt::Entity{ id, m_scene });
});
}
}

bool SceneViewPanel::SearchRecursively(Volt::Entity entity, const std::string& filter, uint32_t maxSearchDepth, uint32_t currentDepth)
Expand Down
11 changes: 8 additions & 3 deletions Volt/Sandbox/src/Sandbox/Window/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,18 @@ bool ViewportPanel::OnKeyPressedEvent(Volt::KeyPressedEvent& e)
EditorCommandStack::GetInstance().PushUndo(command);

bool shouldUpdateNavMesh = false;
for (const auto& i : entitiesToRemove)
for (const auto& entity : entitiesToRemove)
{
if (!shouldUpdateNavMesh && Sandbox::Get().CheckForUpdateNavMesh(i))
if (!entity)
{
continue;
}

if (!shouldUpdateNavMesh && Sandbox::Get().CheckForUpdateNavMesh(entity))
{
shouldUpdateNavMesh = true;
}
m_editorScene->RemoveEntity(i);
m_editorScene->RemoveEntity(entity);
}

if (shouldUpdateNavMesh)
Expand Down
9 changes: 7 additions & 2 deletions Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ namespace Volt
{
entt::entity entityId = streamReader.ReadKey("entity", (entt::entity)entt::null);
AssetHandle prefabHandle = streamReader.ReadKey("prefabHandle", Asset::Null());
prefab->m_prefabReferencesMap[entityId] = prefabHandle;
entt::entity prefabEntityReference = streamReader.ReadKey("prefabEntityReference", (entt::entity)entt::null);

auto& prefabRefData = prefab->m_prefabReferencesMap[entityId];
prefabRefData.prefabAsset = prefabHandle;
prefabRefData.prefabReferenceEntity = prefabEntityReference;
});
}
streamReader.ExitScope();
Expand Down Expand Up @@ -78,7 +82,8 @@ namespace Volt
{
streamWriter.BeginMap();
streamWriter.SetKey("entity", ref.first);
streamWriter.SetKey("prefabHandle", ref.second);
streamWriter.SetKey("prefabHandle", ref.second.prefabAsset);
streamWriter.SetKey("prefabEntityReference", ref.second.prefabReferenceEntity);
streamWriter.EndMap();
}
}
Expand Down
Loading

0 comments on commit 2a70ac3

Please sign in to comment.