diff --git a/AutomatedTesting/Editor/Scripts/scene_mesh_to_prefab.py b/AutomatedTesting/Editor/Scripts/scene_mesh_to_prefab.py index 4aeff06f18..e832b1f82b 100644 --- a/AutomatedTesting/Editor/Scripts/scene_mesh_to_prefab.py +++ b/AutomatedTesting/Editor/Scripts/scene_mesh_to_prefab.py @@ -54,6 +54,30 @@ def get_mesh_node_names(sceneGraph): return meshDataList, paths +def add_material_component(entity_id): + # Create an override AZ::Render::EditorMaterialComponent + editor_material_component = azlmbr.entity.EntityUtilityBus( + azlmbr.bus.Broadcast, + "GetOrAddComponentByTypeName", + entity_id, + "EditorMaterialComponent") + + # this fills out the material asset to a known product AZMaterial asset relative path + json_update = json.dumps({ + "Controller": { "Configuration": { "materials": [ + { + "Key": {}, + "Value": { "MaterialAsset":{ + "assetHint": "materials/basic_grey.azmaterial" + }} + }] + }} + }); + result = azlmbr.entity.EntityUtilityBus(azlmbr.bus.Broadcast, "UpdateComponentForEntity", entity_id, editor_material_component, json_update) + + if not result: + raise RuntimeError("UpdateComponentForEntity for editor_material_component failed") + def update_manifest(scene): import json import uuid, os @@ -75,6 +99,7 @@ def update_manifest(scene): created_entities = [] previous_entity_id = azlmbr.entity.InvalidEntityId + first_mesh = True # Loop every mesh node in the scene for activeMeshIndex in range(len(mesh_name_list)): @@ -112,6 +137,11 @@ def update_manifest(scene): if not result: raise RuntimeError("UpdateComponentForEntity failed for Mesh component") + # an example of adding a material component to override the default material + if previous_entity_id is not None and first_mesh: + first_mesh = False + add_material_component(entity_id) + # Get the transform component transform_component = azlmbr.entity.EntityUtilityBus(azlmbr.bus.Broadcast, "GetOrAddComponentByTypeName", entity_id, "27F1E1A1-8D9D-4C3B-BD3A-AFB9762449C0") diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp index 16e3c047b5..526912cf29 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp @@ -766,15 +766,8 @@ namespace AzToolsFramework { return false; } - outPrefabAssetPath = product->GetRelativePath(); - - auto asset = AZ::Data::AssetManager::Instance().GetAsset( - product->GetAssetId(), - azrtti_typeid(), - AZ::Data::AssetLoadBehavior::Default); - - return asset.BlockUntilLoadComplete() != AZ::Data::AssetData::AssetStatus::Error; + return true; } void PrefabIntegrationManager::WarnUserOfError(AZStd::string_view title, AZStd::string_view message) diff --git a/Gems/Prefab/PrefabBuilder/PrefabGroup/PrefabGroupBehavior.cpp b/Gems/Prefab/PrefabBuilder/PrefabGroup/PrefabGroupBehavior.cpp index 44a95c1b6b..3bc8e9bff9 100644 --- a/Gems/Prefab/PrefabBuilder/PrefabGroup/PrefabGroupBehavior.cpp +++ b/Gems/Prefab/PrefabBuilder/PrefabGroup/PrefabGroupBehavior.cpp @@ -174,7 +174,7 @@ namespace AZ::SceneAPI::Behaviors const auto bytesWritten = fileStream.Write(sb.GetSize(), sb.GetString()); if (bytesWritten > 1) { - AZ::u32 subId = AZ::Crc32(filePath.c_str()); + AZ::u32 subId = AZ::Crc32(assetPath.c_str()); context.GetProductList().AddProduct( filePath, context.GetScene().GetSourceGuid(),