{ghi7197} update the prefab path for procedural prefabs (#7260)

update the prefab path for procedural prefabs so that the prefab template
can be found from the level prefab load event. It is important that it
points to the realative/path/to/the.procprefab using the correct
front slashes for the source asset path


Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>
monroegm-disable-blank-issue-2
Allen Jackson 4 years ago committed by GitHub
parent 05ece2adba
commit 8710130d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -318,13 +318,17 @@ namespace AZ::SceneAPI::Behaviors
{ {
AZ::Interface<AzToolsFramework::Prefab::PrefabSystemComponentInterface>::Get()->RemoveAllTemplates(); AZ::Interface<AzToolsFramework::Prefab::PrefabSystemComponentInterface>::Get()->RemoveAllTemplates();
AZStd::string prefabTemplateName { relativeSourcePath };
AZ::StringFunc::Path::ReplaceFullName(prefabTemplateName, filenameOnly.c_str());
AZ::StringFunc::Replace(prefabTemplateName, "\\", "/"); // the source folder uses forward slash
// create prefab group for entire stack // create prefab group for entire stack
AzToolsFramework::Prefab::TemplateId prefabTemplateId; AzToolsFramework::Prefab::TemplateId prefabTemplateId;
AzToolsFramework::Prefab::PrefabSystemScriptingBus::BroadcastResult( AzToolsFramework::Prefab::PrefabSystemScriptingBus::BroadcastResult(
prefabTemplateId, prefabTemplateId,
&AzToolsFramework::Prefab::PrefabSystemScriptingBus::Events::CreatePrefabTemplate, &AzToolsFramework::Prefab::PrefabSystemScriptingBus::Events::CreatePrefabTemplate,
entities, entities,
filenameOnly); prefabTemplateName);
if (prefabTemplateId == AzToolsFramework::Prefab::InvalidTemplateId) if (prefabTemplateId == AzToolsFramework::Prefab::InvalidTemplateId)
{ {
@ -349,12 +353,12 @@ namespace AZ::SceneAPI::Behaviors
prefabDom.Parse(outcome.GetValue().c_str()); prefabDom.Parse(outcome.GetValue().c_str());
auto prefabGroup = AZStd::make_shared<AZ::SceneAPI::SceneData::PrefabGroup>(); auto prefabGroup = AZStd::make_shared<AZ::SceneAPI::SceneData::PrefabGroup>();
prefabGroup->SetName(relativeSourcePath); prefabGroup->SetName(prefabTemplateName);
prefabGroup->SetPrefabDom(AZStd::move(prefabDom)); prefabGroup->SetPrefabDom(AZStd::move(prefabDom));
prefabGroup->SetId(DataTypes::Utilities::CreateStableUuid( prefabGroup->SetId(DataTypes::Utilities::CreateStableUuid(
scene, scene,
azrtti_typeid<AZ::SceneAPI::SceneData::PrefabGroup>(), azrtti_typeid<AZ::SceneAPI::SceneData::PrefabGroup>(),
relativeSourcePath)); prefabTemplateName));
manifestUpdates.emplace_back(prefabGroup); manifestUpdates.emplace_back(prefabGroup);
@ -414,7 +418,7 @@ namespace AZ::SceneAPI::Behaviors
AZ::StringFunc::Replace(relativeSourcePath, ".", "_"); AZ::StringFunc::Replace(relativeSourcePath, ".", "_");
AZStd::string filenameOnly{ relativeSourcePath }; AZStd::string filenameOnly{ relativeSourcePath };
AZ::StringFunc::Path::GetFileName(filenameOnly.c_str(), filenameOnly); AZ::StringFunc::Path::GetFileName(filenameOnly.c_str(), filenameOnly);
AZ::StringFunc::Path::ReplaceExtension(filenameOnly, "prefab"); AZ::StringFunc::Path::ReplaceExtension(filenameOnly, "procprefab");
ManifestUpdates manifestUpdates; ManifestUpdates manifestUpdates;
@ -482,7 +486,10 @@ namespace AZ::SceneAPI::Behaviors
// The originPath we pass to LoadTemplateFromString must be the relative path of the file // The originPath we pass to LoadTemplateFromString must be the relative path of the file
AZ::IO::Path templateName(prefabGroup->GetName()); AZ::IO::Path templateName(prefabGroup->GetName());
templateName.ReplaceExtension(AZ::Prefab::PrefabGroupAssetHandler::s_Extension); templateName.ReplaceExtension(AZ::Prefab::PrefabGroupAssetHandler::s_Extension);
if (!AZ::StringFunc::StartsWith(templateName.c_str(), relativePath.c_str()))
{
templateName = relativePath / templateName; templateName = relativePath / templateName;
}
auto templateId = prefabLoaderInterface->LoadTemplateFromString(sb.GetString(), templateName.Native().c_str()); auto templateId = prefabLoaderInterface->LoadTemplateFromString(sb.GetString(), templateName.Native().c_str());
if (templateId == InvalidTemplateId) if (templateId == InvalidTemplateId)
@ -569,11 +576,12 @@ namespace AZ::SceneAPI::Behaviors
// Get the relative path of the source and then take just the path portion of it (no file name) // Get the relative path of the source and then take just the path portion of it (no file name)
AZ::IO::Path relativePath = context.GetScene().GetSourceFilename(); AZ::IO::Path relativePath = context.GetScene().GetSourceFilename();
relativePath = relativePath.LexicallyRelative(AZStd::string_view(context.GetScene().GetWatchFolder())); relativePath = relativePath.LexicallyRelative(AZStd::string_view(context.GetScene().GetWatchFolder()));
relativePath = relativePath.ParentPath(); AZStd::string relativeSourcePath { AZStd::move(relativePath.ParentPath().Native()) };
AZ::StringFunc::Replace(relativeSourcePath, "\\", "/"); // the source paths use forward slashes
for (const auto* prefabGroup : prefabGroupCollection) for (const auto* prefabGroup : prefabGroupCollection)
{ {
auto result = CreateProductAssetData(prefabGroup, relativePath); auto result = CreateProductAssetData(prefabGroup, relativeSourcePath);
if (!result) if (!result)
{ {
return Events::ProcessingResult::Failure; return Events::ProcessingResult::Failure;

Loading…
Cancel
Save