Open 3D Engine AzToolsFramework API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AzToolsFramework::Prefab::PrefabSystemComponent Class Reference

#include <PrefabSystemComponent.h>

Inherits AZ::Component, AzToolsFramework::Prefab::PrefabSystemComponentInterface, AZ::SystemTickBus::Handler, and AzToolsFramework::AssetBrowser::AssetBrowserFileActionNotificationBus::Handler.

Public Types

using TargetTemplateIdToLinkIdMap = AZStd::unordered_map< TemplateId, AZStd::pair< AZStd::unordered_set< LinkId >, bool > >
 

Public Member Functions

 AZ_COMPONENT (PrefabSystemComponent, "{27203AE6-A398-4614-881B-4EEB5E9B34E9}")
 
void Init () override
 
void Activate () override
 
void Deactivate () override
 
void OnSystemTick () override
 
void OnSourceFilePathNameChanged (const AZStd::string_view fromPathName, const AZStd::string_view toPathName) override
 
void OnSourceFolderPathNameChanged (const AZStd::string_view fromPathName, const AZStd::string_view toPathName) override
 
TemplateReference FindTemplate (TemplateId id) override
 
LinkReference FindLink (const LinkId &id) override
 
TemplateId AddTemplate (const AZ::IO::Path &filePath, PrefabDom prefabDom) override
 
void UpdateTemplateFilePath (TemplateId templateId, const AZ::IO::PathView &filePath) override
 
void RemoveTemplate (TemplateId templateId) override
 
void RemoveAllTemplates () override
 
AZStd::unique_ptr< InstanceInstantiatePrefab (AZ::IO::PathView filePath, InstanceOptionalReference parent=AZStd::nullopt, const InstantiatedEntitiesCallback &instantiatedEntitiesCallback={}) override
 
AZStd::unique_ptr< InstanceInstantiatePrefab (TemplateId templateId, InstanceOptionalReference parent=AZStd::nullopt, const InstantiatedEntitiesCallback &instantiatedEntitiesCallback={}) override
 
LinkId AddLink (TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomValue::MemberIterator &instanceIterator, InstanceOptionalReference instance) override
 
LinkId CreateLink (TemplateId linkTargetId, TemplateId linkSourceId, const InstanceAlias &instanceAlias, const PrefabDomConstReference linkPatches, const LinkId &linkId=InvalidLinkId) override
 
bool RemoveLink (const LinkId &linkId) override
 
TemplateId GetTemplateIdFromFilePath (AZ::IO::PathView filePath) const override
 
bool IsTemplateDirty (TemplateId templateId) override
 
void SetTemplateDirtyFlag (TemplateId templateId, bool dirty) override
 
bool AreDirtyTemplatesPresent (TemplateId rootTemplateId) override
 
void SaveAllDirtyTemplates (TemplateId rootTemplateId) override
 
AZStd::set< AZ::IO::PathView > GetDirtyTemplatePaths (TemplateId rootTemplateId) override
 
AZStd::unique_ptr< InstanceCreatePrefab (const AZStd::vector< AZ::Entity * > &entities, AZStd::vector< AZStd::unique_ptr< Instance > > &&nestedInstances, AZ::IO::PathView filePath, AZStd::unique_ptr< AZ::Entity > containerEntity=nullptr, InstanceOptionalReference parent=AZStd::nullopt, bool shouldCreateLinks=true) override
 
AZStd::unique_ptr< InstanceCreatePrefabWithCustomEntityAliases (const AZStd::map< EntityAlias, AZ::Entity * > &entities, AZStd::vector< AZStd::unique_ptr< Instance > > &&nestedInstances, AZ::IO::PathView filePath, AZStd::unique_ptr< AZ::Entity > containerEntity=nullptr, InstanceOptionalReference parent=AZStd::nullopt, bool shouldCreateLinks=true) override
 
PrefabDom & FindTemplateDom (TemplateId templateId) override
 
void UpdatePrefabTemplate (TemplateId templateId, const PrefabDom &updatedDom) override
 
void PropagateTemplateChanges (TemplateId templateId, InstanceOptionalConstReference instanceToExclude=AZStd::nullopt) override
 
void UpdatePrefabInstances (TemplateId templateId, InstanceOptionalConstReference instanceToExclude=AZStd::nullopt)
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 
static void GetProvidedServices (AZ::ComponentDescriptor::DependencyArrayType &provided)
 
static void GetRequiredServices (AZ::ComponentDescriptor::DependencyArrayType &required)
 
static void GetIncompatibleServices (AZ::ComponentDescriptor::DependencyArrayType &incompatible)
 

Detailed Description

The prefab system component provides a central point for owning manipulating prefabs.

Member Function Documentation

◆ AddLink()

LinkId AzToolsFramework::Prefab::PrefabSystemComponent::AddLink ( TemplateId  sourceTemplateId,
TemplateId  targetTemplateId,
PrefabDomValue::MemberIterator &  instanceIterator,
InstanceOptionalReference  instance 
)
overridevirtual

Add a new Link into Prefab System Component and create a unique id for it.

Parameters
sourceTemplateIdThe Id of Template whose instance is referred by targetTemplate.
targetTemplateIdThe Id of Template which owns this Link.
instanceIteratorThe Prefab DOM value iterator that points to the instance associated by this Link.
instanceThe instance that this link may point to. This is optional and can also take the value of nullopt.
Returns
A unique id for the new Link.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ AddTemplate()

TemplateId AzToolsFramework::Prefab::PrefabSystemComponent::AddTemplate ( const AZ::IO::Path &  filePath,
PrefabDom  prefabDom 
)
overridevirtual

Add a new Template into Prefab System Component and create a unique id for it.

Parameters
filePathA file path where the Template file is located.
prefabDomA Prefab DOM presenting this Template.
Returns
A unique id for the new Template.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ AreDirtyTemplatesPresent()

bool AzToolsFramework::Prefab::PrefabSystemComponent::AreDirtyTemplatesPresent ( TemplateId  rootTemplateId)
overridevirtual

Recursive function to check if the template is dirty or if any dirty templates are presents in the links of the template.

Parameters
rootTemplateIdThe id of the template provided as the beginning template to check the outgoing links.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ CreateLink()

LinkId AzToolsFramework::Prefab::PrefabSystemComponent::CreateLink ( TemplateId  linkTargetId,
TemplateId  linkSourceId,
const InstanceAlias &  instanceAlias,
const PrefabDomConstReference  linkPatches,
const LinkId &  linkId = InvalidLinkId 
)
overridevirtual

Create a new Link with Prefab System Component and create a unique id for it.

Parameters
linkTargetIdThe Id of Template which owns this Link.
linkSourceIdThe Id of Template whose instance is referred by targetTemplate.
instanceAliasThe alias of the instance that should be included in link.
linkIdThe id of the link. If invalid, create a new link id. If valid, use to recreate a prior link.
Returns
A unique id for the new Link.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ CreatePrefab()

AZStd::unique_ptr< Instance > AzToolsFramework::Prefab::PrefabSystemComponent::CreatePrefab ( const AZStd::vector< AZ::Entity * > &  entities,
AZStd::vector< AZStd::unique_ptr< Instance > > &&  nestedInstances,
AZ::IO::PathView  filePath,
AZStd::unique_ptr< AZ::Entity >  containerEntity = nullptr,
InstanceOptionalReference  parent = AZStd::nullopt,
bool  shouldCreateLinks = true 
)
overridevirtual

Builds a new Prefab Template out of entities and instances and returns the first instance comprised of these entities and instances.

Parameters
entitiesA vector of entities that will be used in the new instance. May be empty.
nestedInstancesA vector of Prefab Instances that will be nested in the new instance, will be consumed and moved. May be empty.
filePathThe path to associate the template of the new instance to.
containerEntityThe container entity for the prefab to be created. It will be created if a nullptr is provided.
parentReference of an instance the created instance will be placed under, if given.
shouldCreateLinksThe flag indicating if links should be created between the templates of the instance and its nested instances.
Returns
A pointer to the newly created instance. nullptr on failure.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ CreatePrefabWithCustomEntityAliases()

AZStd::unique_ptr< Instance > AzToolsFramework::Prefab::PrefabSystemComponent::CreatePrefabWithCustomEntityAliases ( const AZStd::map< EntityAlias, AZ::Entity * > &  entities,
AZStd::vector< AZStd::unique_ptr< Instance > > &&  nestedInstances,
AZ::IO::PathView  filePath,
AZStd::unique_ptr< AZ::Entity >  containerEntity = nullptr,
InstanceOptionalReference  parent = AZStd::nullopt,
bool  shouldCreateLinks = true 
)
overridevirtual

Creates a prefab instance using the entities and nested instances provided.

Parameters
entitiesThe map of entities to add to the instance. Map ensures insertion order.
nestedInstancesThe instances to add to the newly created instance.
filePathThe path at which the prefab should be created.
containerEntityThe container entity for the new instance.
parentThe parent instance of the newly created instance.
Returns
The new instance created.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ FindLink()

LinkReference AzToolsFramework::Prefab::PrefabSystemComponent::FindLink ( const LinkId &  id)
overridevirtual

Find Link with given Link id from Prefab System Component.

Parameters
idA unique id of a Link.
Returns
Reference of Link if the Link exists.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ FindTemplate()

TemplateReference AzToolsFramework::Prefab::PrefabSystemComponent::FindTemplate ( TemplateId  id)
overridevirtual

Find Template with given Template id from Prefab System Component.

Parameters
idA unique id of a Template.
Returns
Reference of Template if the Template exists.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ FindTemplateDom()

PrefabDom & AzToolsFramework::Prefab::PrefabSystemComponent::FindTemplateDom ( TemplateId  templateId)
overridevirtual

◆ GetDirtyTemplatePaths()

AZStd::set< AZ::IO::PathView > AzToolsFramework::Prefab::PrefabSystemComponent::GetDirtyTemplatePaths ( TemplateId  rootTemplateId)
overridevirtual

Recursive function that fetches the set of dirty templates given a starting template to check for outgoing links.

Parameters
rootTemplateIdThe id of the template provided as the beginning template to check the outgoing links.
Returns
The set of dirty template paths populated.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ GetTemplateIdFromFilePath()

TemplateId AzToolsFramework::Prefab::PrefabSystemComponent::GetTemplateIdFromFilePath ( AZ::IO::PathView  filePath) const
overridevirtual

Get id of Template on given file path if it has already been loaded into Prefab System Component.

Parameters
filePathA path to a Prefab Template file.
Returns
A unique id of Template on filePath. Return InvalidTemplateId if Template on filePath doesn't exist.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ InstantiatePrefab() [1/2]

AZStd::unique_ptr< Instance > AzToolsFramework::Prefab::PrefabSystemComponent::InstantiatePrefab ( AZ::IO::PathView  filePath,
InstanceOptionalReference  parent = AZStd::nullopt,
const InstantiatedEntitiesCallback &  instantiatedEntitiesCallback = {} 
)
overridevirtual

Generates a new Prefab Instance based on the Template whose source is stored in filepath.

Parameters
filePathThe path to the prefab source file containing the template being instantiated.
parentReference of the target instance the instantiated instance will be placed under.
instantiatedEntitiesCallbackAn optional callback that can be used to modify the instantiated entities.
Returns
A unique_ptr to the newly instantiated instance. Null if operation failed.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ InstantiatePrefab() [2/2]

AZStd::unique_ptr< Instance > AzToolsFramework::Prefab::PrefabSystemComponent::InstantiatePrefab ( TemplateId  templateId,
InstanceOptionalReference  parent = AZStd::nullopt,
const InstantiatedEntitiesCallback &  instantiatedEntitiesCallback = {} 
)
overridevirtual

Generates a new Prefab Instance based on the Template referenced by templateId.

Parameters
templateIdThe id of the template being instantiated.
parentReference of the target instance the instantiated instance will be placed under.
instantiatedEntitiesCallbackAn optional callback that can be used to modify the instantiated entities.
Returns
A unique_ptr to the newly instantiated instance. Null if operation failed.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ IsTemplateDirty()

bool AzToolsFramework::Prefab::PrefabSystemComponent::IsTemplateDirty ( TemplateId  templateId)
overridevirtual

Gets the value of the dirty flag of the template with the id provided.

Parameters
templateIdThe id of the template to query.
Returns
The value of the dirty flag on the template.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ PropagateTemplateChanges()

void AzToolsFramework::Prefab::PrefabSystemComponent::PropagateTemplateChanges ( TemplateId  templateId,
InstanceOptionalConstReference  instanceToExclude = AZStd::nullopt 
)
overridevirtual

◆ RemoveAllTemplates()

void AzToolsFramework::Prefab::PrefabSystemComponent::RemoveAllTemplates ( )
overridevirtual

Remove all Templates from the Prefab System Component.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ RemoveLink()

bool AzToolsFramework::Prefab::PrefabSystemComponent::RemoveLink ( const LinkId &  linkId)
overridevirtual

Remove the Link associated with the given id from Prefab System Component.

Parameters
linkIdA unique id of a Link.
Returns
whether link was successfully removed or not.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ RemoveTemplate()

void AzToolsFramework::Prefab::PrefabSystemComponent::RemoveTemplate ( TemplateId  templateId)
overridevirtual

Remove the Template associated with the given id from Prefab System Component.

Parameters
templateIdA unique id of a Template.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ SaveAllDirtyTemplates()

void AzToolsFramework::Prefab::PrefabSystemComponent::SaveAllDirtyTemplates ( TemplateId  rootTemplateId)
overridevirtual

Recursive function to save if the template is dirty and save all the dirty templates in the links of the template.

Parameters
rootTemplateIdThe id of the template provided as the beginning template to check the outgoing links.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ SetTemplateDirtyFlag()

void AzToolsFramework::Prefab::PrefabSystemComponent::SetTemplateDirtyFlag ( TemplateId  templateId,
bool  dirty 
)
overridevirtual

Sets the dirty flag of the template to the value provided.

Parameters
templateIdThe id of the template to flag.
dirtyThe new value of the dirty flag.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ UpdatePrefabInstances()

void AzToolsFramework::Prefab::PrefabSystemComponent::UpdatePrefabInstances ( TemplateId  templateId,
InstanceOptionalConstReference  instanceToExclude = AZStd::nullopt 
)

Updates all Instances owned by a Template.

Parameters
templateIdThe id of the Template owning Instances to update.
instanceToExcludeAn optional reference to an instance of the template being updated that should not be refreshed as part of propagation.Defaults to nullopt, which means that all instances will be refreshed.

◆ UpdatePrefabTemplate()

void AzToolsFramework::Prefab::PrefabSystemComponent::UpdatePrefabTemplate ( TemplateId  templateId,
const PrefabDom &  updatedDom 
)
overridevirtual

Updates a template with the given updated DOM.

Parameters
templateIdThe id of the template to update.
updatedDomThe DOM to update the template with.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.

◆ UpdateTemplateFilePath()

void AzToolsFramework::Prefab::PrefabSystemComponent::UpdateTemplateFilePath ( TemplateId  templateId,
const AZ::IO::PathView &  filePath 
)
overridevirtual

Updates relative filepath location of a prefab (in case of SaveAs operation).

Parameters
templateIdAn id of a Template to change filepath of.
filePathnew relative path of the Template.

Implements AzToolsFramework::Prefab::PrefabSystemComponentInterface.


The documentation for this class was generated from the following file: