@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Prefab.h"
|
||||
#include "Engine/Serialization/JsonTools.h"
|
||||
#include "Engine/Content/Content.h"
|
||||
#include "Engine/Content/Factories/JsonAssetFactory.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Level/Prefabs/PrefabManager.h"
|
||||
@@ -21,6 +22,36 @@ Prefab::Prefab(const SpawnParams& params, const AssetInfo* info)
|
||||
{
|
||||
}
|
||||
|
||||
Guid Prefab::GetRootObjectId() const
|
||||
{
|
||||
ASSERT(IsLoaded());
|
||||
ScopeLock lock(Locker);
|
||||
|
||||
// Root is always the first but handle case when prefab root was reordered in the base prefab while the nested prefab has still the old state
|
||||
// TODO: resave and force sync prefabs during game cooking so this step could be skipped in game
|
||||
int32 objectIndex = 0;
|
||||
if (NestedPrefabs.HasItems())
|
||||
{
|
||||
const auto& data = *Data;
|
||||
const Guid basePrefabId = JsonTools::GetGuid(data[objectIndex], "PrefabID");
|
||||
if (const auto basePrefab = Content::Load<Prefab>(basePrefabId))
|
||||
{
|
||||
const Guid basePrefabRootId = basePrefab->GetRootObjectId();
|
||||
for (int32 i = 0; i < ObjectsCount; i++)
|
||||
{
|
||||
const Guid prefabObjectId = JsonTools::GetGuid(data[i], "PrefabObjectID");
|
||||
if (prefabObjectId == basePrefabRootId)
|
||||
{
|
||||
objectIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ObjectsIds[objectIndex];
|
||||
}
|
||||
|
||||
Actor* Prefab::GetDefaultInstance()
|
||||
{
|
||||
ScopeLock lock(Locker);
|
||||
|
||||
Reference in New Issue
Block a user