| 542 | } |
| 543 | |
| 544 | bool PrefabManager::ApplyAll(Actor* instance) |
| 545 | { |
| 546 | PROFILE_CPU_NAMED("Prefab.ApplyAll"); |
| 547 | |
| 548 | // Validate input |
| 549 | if (instance == nullptr) |
| 550 | { |
| 551 | Log::ArgumentNullException(); |
| 552 | return true; |
| 553 | } |
| 554 | if (!instance->HasPrefabLink() || instance->GetPrefabID() == Guid::Empty) |
| 555 | { |
| 556 | Log::ArgumentException(TEXT("The modified actor instance has missing prefab link.")); |
| 557 | return true; |
| 558 | } |
| 559 | |
| 560 | // Get prefab asset |
| 561 | auto prefab = Content::LoadAsync<Prefab>(instance->GetPrefabID()); |
| 562 | if (prefab == nullptr) |
| 563 | { |
| 564 | Log::Exception(TEXT("Missing prefab asset.")); |
| 565 | return true; |
| 566 | } |
| 567 | if (prefab->WaitForLoaded()) |
| 568 | { |
| 569 | Log::Exception(TEXT("Failed to load prefab asset.")); |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | // Get root object of this prefab instance |
| 574 | // Note: given actor instance can be already part of the spawned prefab or be a new actor added to the prefab instance |
| 575 | // Find the actual root of the prefab instance |
| 576 | const auto rootObjectId = prefab->GetRootObjectId(); |
| 577 | auto rootObjectInstance = instance; |
| 578 | while (rootObjectInstance && rootObjectInstance->GetPrefabObjectID() != rootObjectId) |
| 579 | { |
| 580 | rootObjectInstance = rootObjectInstance->GetParent(); |
| 581 | } |
| 582 | if (rootObjectInstance == nullptr) |
| 583 | { |
| 584 | // Use the input object as fallback |
| 585 | rootObjectInstance = instance; |
| 586 | } |
| 587 | while (rootObjectInstance->GetParent() && rootObjectInstance->GetParent()->GetPrefabID() == rootObjectInstance->GetPrefabID()) |
| 588 | { |
| 589 | // Move up to the root of the prefab instance (eg. in case of root change on instance to apply) |
| 590 | rootObjectInstance = rootObjectInstance->GetParent(); |
| 591 | } |
| 592 | |
| 593 | return prefab->ApplyAll(rootObjectInstance); |
| 594 | } |
| 595 | |
| 596 | #endif |
nothing calls this directly
no test coverage detected