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::Instance Class Reference

Class that represents a prefab instance instantiated from a prefab template. More...

#include <Instance.h>

Public Types

using AliasToInstanceMap = AZStd::unordered_map< InstanceAlias, AZStd::unique_ptr< Instance > >
 
using AliasToEntityMap = AZStd::unordered_map< EntityAlias, AZStd::unique_ptr< AZ::Entity > >
 

Public Member Functions

 AZ_CLASS_ALLOCATOR (Instance, AZ::SystemAllocator)
 
 AZ_RTTI (Instance, "{D4219332-A648-4285-9CA6-B7F095987CD3}")
 
virtual ~Instance ()
 Destructor.
 
TemplateId GetTemplateId () const
 
void SetTemplateId (TemplateId templateId)
 
const AZ::IO::Path & GetTemplateSourcePath () const
 
void SetTemplateSourcePath (AZ::IO::Path sourcePath)
 
void SetContainerEntityName (AZStd::string containerName)
 
AZStd::unique_ptr< AZ::Entity > DetachEntity (const AZ::EntityId &entityId)
 
void DetachEntities (const AZStd::function< void(AZStd::unique_ptr< AZ::Entity >)> &callback)
 
void DetachAllEntitiesInHierarchy (const AZStd::function< void(AZStd::unique_ptr< AZ::Entity >)> &callback)
 
bool DestroyEntity (const AZ::EntityId &entityId)
 
AZStd::unique_ptr< AZ::Entity > ReplaceEntity (AZStd::unique_ptr< AZ::Entity > &&entity, EntityAliasView alias)
 
void RemoveEntitiesInHierarchy (const AZStd::function< bool(const AZStd::unique_ptr< AZ::Entity > &)> &filter)
 
InstanceAddInstance (AZStd::unique_ptr< Instance > instance)
 
AZStd::unique_ptr< InstanceDetachNestedInstance (const InstanceAlias &instanceAlias)
 
void DetachNestedInstances (const AZStd::function< void(AZStd::unique_ptr< Instance >)> &callback)
 
void Reset ()
 
AZStd::vector< EntityAlias > GetEntityAliases ()
 
size_t GetEntityAliasCount () const
 
void GetNestedInstances (const AZStd::function< void(AZStd::unique_ptr< Instance > &)> &callback)
 
AZ::EntityId GetEntityId (const EntityAlias &alias) const
 
AZ::EntityId GetEntityIdFromAliasPath (AliasPathView relativeAliasPath) const
 
AZStd::vector< InstanceAlias > GetNestedInstanceAliases (TemplateId templateId) const
 
void ActivateContainerEntity ()
 Activates the container entity.
 
void SetLinkId (LinkId linkId)
 
LinkId GetLinkId () const
 
AZStd::unique_ptr< AZ::Entity > DetachContainerEntity ()
 
bool DestroyContainerEntity ()
 
const InstanceAlias & GetInstanceAlias () const
 
AliasPath GetAbsoluteInstanceAliasPath () const
 
AliasPath GetAliasPathRelativeToInstance (const AZ::EntityId &entity) const
 
 Instance ()
 
 Instance (AZStd::unique_ptr< AZ::Entity > containerEntity)
 
 Instance (InstanceOptionalReference parent)
 
 Instance (InstanceOptionalReference parent, InstanceAlias alias)
 
 Instance (InstanceOptionalReference parent, InstanceAlias alias, EntityIdInstanceRelationship entityIdInstanceRelationship)
 
 Instance (AZStd::unique_ptr< AZ::Entity > containerEntity, InstanceOptionalReference parent)
 
 Instance (InstanceAlias alias)
 
 Instance (EntityIdInstanceRelationship entityIdInstanceRelationship)
 
 Instance (InstanceAlias alias, EntityIdInstanceRelationship entityIdInstanceRelationship)
 
 Instance (const Instance &rhs)=delete
 
Instanceoperator= (const Instance &rhs)=delete
 
bool AddEntity (AZ::Entity &entity)
 
bool AddEntity (AZStd::unique_ptr< AZ::Entity > &&entity)
 
bool AddEntity (AZ::Entity &entity, EntityAlias entityAlias)
 
bool AddEntity (AZStd::unique_ptr< AZ::Entity > &&entity, EntityAlias entityAlias)
 
void GetEntityIds (const AZStd::function< bool(AZ::EntityId)> &callback) const
 
void GetEntityIdToAlias (const AZStd::function< bool(AZ::EntityId, EntityAliasView)> &callback) const
 
void GetEntities (const AZStd::function< bool(AZStd::unique_ptr< AZ::Entity > &)> &callback)
 
void GetConstEntities (const AZStd::function< bool(const AZ::Entity &)> &callback) const
 
void GetAllEntityIdsInHierarchy (const AZStd::function< bool(AZ::EntityId)> &callback) const
 
void GetAllEntitiesInHierarchy (const AZStd::function< bool(AZStd::unique_ptr< AZ::Entity > &)> &callback)
 
void GetAllEntitiesInHierarchyConst (const AZStd::function< bool(const AZ::Entity &)> &callback) const
 
EntityAliasOptionalReference GetEntityAlias (AZ::EntityId id)
 
EntityAliasView GetEntityAlias (AZ::EntityId id) const
 
AZStd::pair< Instance *, EntityAliasView > FindInstanceAndAlias (AZ::EntityId entity)
 
AZStd::pair< const Instance *, EntityAliasView > FindInstanceAndAlias (AZ::EntityId entity) const
 
EntityOptionalReference GetEntity (const EntityAlias &alias)
 
EntityOptionalConstReference GetEntity (const EntityAlias &alias) const
 
AZStd::pair< Instance *, AZ::EntityId > GetInstanceAndEntityIdFromAliasPath (AliasPathView relativeAliasPath)
 
AZStd::pair< const Instance *, AZ::EntityId > GetInstanceAndEntityIdFromAliasPath (AliasPathView relativeAliasPath) const
 
InstanceOptionalReference FindNestedInstance (const InstanceAlias &nestedInstanceAlias)
 
InstanceOptionalConstReference FindNestedInstance (const InstanceAlias &nestedInstanceAlias) const
 
InstanceOptionalReference GetParentInstance ()
 
InstanceOptionalConstReference GetParentInstance () const
 
bool HasParentInstance () const
 
bool IsParentInstance (const Instance &instance) const
 
AZ::EntityId GetContainerEntityId () const
 
bool HasContainerEntity () const
 
EntityOptionalReference GetContainerEntity ()
 
EntityOptionalConstReference GetContainerEntity () const
 
void SetContainerEntity (AZ::Entity &entity)
 
PrefabDomConstReference GetCachedInstanceDom () const
 
PrefabDomReference GetCachedInstanceDom ()
 
void SetCachedInstanceDom (PrefabDomValueConstReference instanceDom)
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 
static EntityAlias GenerateEntityAlias ()
 
static InstanceAlias GenerateInstanceAlias ()
 

Friends

class AzToolsFramework::PrefabEditorEntityOwnershipService
 
class JsonInstanceSerializer
 
class InstanceEntityIdMapper
 

Detailed Description

Class that represents a prefab instance instantiated from a prefab template.

Constructor & Destructor Documentation

◆ Instance() [1/2]

AzToolsFramework::Prefab::Instance::Instance ( )

Construtors.

◆ Instance() [2/2]

AzToolsFramework::Prefab::Instance::Instance ( const Instance rhs)
delete

Disables copy constructor and copy assignment.

Member Function Documentation

◆ AddEntity()

bool AzToolsFramework::Prefab::Instance::AddEntity ( AZ::Entity &  entity)

Adds entity to the instance. It registers the entity id and moves the entity ownership to the instance.

◆ AddInstance()

Instance & AzToolsFramework::Prefab::Instance::AddInstance ( AZStd::unique_ptr< Instance instance)

Adds a new nested instance.

Parameters
instanceThe new nested instance.
Returns
Reference to the new nested instance.

◆ DestroyContainerEntity()

bool AzToolsFramework::Prefab::Instance::DestroyContainerEntity ( )

Detaches and deletes the container entity from the instance.

Returns
True if the container entity was detached and destroyed, false otherwise.

◆ DestroyEntity()

bool AzToolsFramework::Prefab::Instance::DestroyEntity ( const AZ::EntityId &  entityId)

Detaches and deletes an entity from the instance.

Parameters
entityIdThe entity id to be detached and destroyed.
Returns
True if the entity was detached and destroyed, false otherwise.

◆ DetachAllEntitiesInHierarchy()

void AzToolsFramework::Prefab::Instance::DetachAllEntitiesInHierarchy ( const AZStd::function< void(AZStd::unique_ptr< AZ::Entity >)> &  callback)

Detaches all entities in the instance hierarchy. Includes all direct entities, all nested entities, and all container entities. Note that without container entities the hierarchy that remains cannot be used further without restoring new ones.

Parameters
callbackA user provided callback that can be used to capture ownership and manipulate the detached entities.

◆ DetachContainerEntity()

AZStd::unique_ptr< AZ::Entity > AzToolsFramework::Prefab::Instance::DetachContainerEntity ( )

Detaches the container entity from the instance. It unregisters the entity id and moves the entity ownership to the caller.

Returns
Unique pointer to the container entity.

◆ DetachEntities()

void AzToolsFramework::Prefab::Instance::DetachEntities ( const AZStd::function< void(AZStd::unique_ptr< AZ::Entity >)> &  callback)

Detaches entities from the instance. It unregisters the entity ids and moves the entity ownerships to the callback provided by the caller.

Parameters
callbackA user provided callback that can be used to capture ownership and manipulate the detached entities.

◆ DetachEntity()

AZStd::unique_ptr< AZ::Entity > AzToolsFramework::Prefab::Instance::DetachEntity ( const AZ::EntityId &  entityId)

Detaches an entity from the instance. It unregisters the entity id and moves the entity ownership to the caller.

Parameters
entityIdThe entity id to be detached.
Returns
Unique pointer to the entity.

◆ DetachNestedInstance()

AZStd::unique_ptr< Instance > AzToolsFramework::Prefab::Instance::DetachNestedInstance ( const InstanceAlias &  instanceAlias)

Detaches a nested instance from the instance. It removes the nested instance and moves the instance ownership to the caller.

Parameters
entityIdThe entity id to be detached.
Returns
Unique pointer to the entity.

◆ DetachNestedInstances()

void AzToolsFramework::Prefab::Instance::DetachNestedInstances ( const AZStd::function< void(AZStd::unique_ptr< Instance >)> &  callback)

Detaches entities from the instance. It removes nested instances and moves the instance ownerships to the callback provided by the caller.

Parameters
callbackA user provided callback that can be used to capture ownership and manipulate the detached instances.

◆ FindInstanceAndAlias()

AZStd::pair< Instance *, EntityAliasView > AzToolsFramework::Prefab::Instance::FindInstanceAndAlias ( AZ::EntityId  entity)

Searches for the entity in this instance and its nested instances. If the entity isn't found then the returned instance will be null and the alias will be empty.

◆ FindNestedInstance()

InstanceOptionalReference AzToolsFramework::Prefab::Instance::FindNestedInstance ( const InstanceAlias &  nestedInstanceAlias)

Finds a nested instance non-recursively by instance alias.

◆ GenerateEntityAlias()

static EntityAlias AzToolsFramework::Prefab::Instance::GenerateEntityAlias ( )
static

Entity and instance alias generator functions.

◆ GetAbsoluteInstanceAliasPath()

AliasPath AzToolsFramework::Prefab::Instance::GetAbsoluteInstanceAliasPath ( ) const

Gets absolute instance alias path seen from root instance.

Returns
Alias path seen from root instance.

◆ GetAliasPathRelativeToInstance()

AliasPath AzToolsFramework::Prefab::Instance::GetAliasPathRelativeToInstance ( const AZ::EntityId &  entity) const

Gets relative alias path to entity.

Parameters
entityThe entity that the relative path points to.
Returns
Alias path to the provided entity.

◆ GetAllEntityIdsInHierarchy()

void AzToolsFramework::Prefab::Instance::GetAllEntityIdsInHierarchy ( const AZStd::function< bool(AZ::EntityId)> &  callback) const

Gets the entity ids for all entities in hierarchy in the Instance DOM. A callback can be provided to manipulates the entities. Note: These are recursive operations that trace all nested instances.

◆ GetCachedInstanceDom()

PrefabDomConstReference AzToolsFramework::Prefab::Instance::GetCachedInstanceDom ( ) const

Getter and setter for cached instance DOM.

◆ GetContainerEntityId()

AZ::EntityId AzToolsFramework::Prefab::Instance::GetContainerEntityId ( ) const

Query, getter and setter functions for container entity.

◆ GetEntity()

EntityOptionalReference AzToolsFramework::Prefab::Instance::GetEntity ( const EntityAlias &  alias)

Gets entity by a user provided entity alias.

◆ GetEntityAlias()

EntityAliasOptionalReference AzToolsFramework::Prefab::Instance::GetEntityAlias ( AZ::EntityId  id)

Gets the entity alias for a given entity id in the Instance DOM.

◆ GetEntityAliasCount()

size_t AzToolsFramework::Prefab::Instance::GetEntityAliasCount ( ) const

Gets the entity alias count in the Instance DOM.

Returns
The entity alias count.

◆ GetEntityAliases()

AZStd::vector< EntityAlias > AzToolsFramework::Prefab::Instance::GetEntityAliases ( )

Gets the aliases for the entities in the Instance DOM.

Returns
The list of EntityAliases.

◆ GetEntityId()

AZ::EntityId AzToolsFramework::Prefab::Instance::GetEntityId ( const EntityAlias &  alias) const

Gets the id for a given EnitityAlias in the Instance DOM.

Parameters
aliasEntity alias used to retrieve the entity id.
Returns
entityId, invalid ID if not found.

◆ GetEntityIdFromAliasPath()

AZ::EntityId AzToolsFramework::Prefab::Instance::GetEntityIdFromAliasPath ( AliasPathView  relativeAliasPath) const

Retrieves the entity id from an alias path that's relative to this instance.

Parameters
relativeAliasPathEntity alias path relative to this instance.
Returns
entityId, invalid ID if not found.

◆ GetEntityIds()

void AzToolsFramework::Prefab::Instance::GetEntityIds ( const AZStd::function< bool(AZ::EntityId)> &  callback) const

Gets the entities or entity ids in the Instance DOM. A callback can be provided to manipulates the entities. Note: These are non-recursive operations.

◆ GetInstanceAlias()

const InstanceAlias & AzToolsFramework::Prefab::Instance::GetInstanceAlias ( ) const

Getter for instance alias.

Returns
Instance alias string.

◆ GetInstanceAndEntityIdFromAliasPath()

AZStd::pair< Instance *, AZ::EntityId > AzToolsFramework::Prefab::Instance::GetInstanceAndEntityIdFromAliasPath ( AliasPathView  relativeAliasPath)

Retrieves the instance pointer and entity id from an alias path that's relative to this instance. It returns a pair with the Instance and entity id. The Instance is set to null and entityId is set to invalid if not found.

◆ GetLinkId()

LinkId AzToolsFramework::Prefab::Instance::GetLinkId ( ) const

Gets link id.

Returns
Link id of the instance.

◆ GetNestedInstanceAliases()

AZStd::vector< InstanceAlias > AzToolsFramework::Prefab::Instance::GetNestedInstanceAliases ( TemplateId  templateId) const

Gets the aliases of all the nested instances, which are sourced by the template with the given id.

Parameters
templateIdThe source template id of the nested instances.
Returns
The list of aliases of the nested instances.

◆ GetNestedInstances()

void AzToolsFramework::Prefab::Instance::GetNestedInstances ( const AZStd::function< void(AZStd::unique_ptr< Instance > &)> &  callback)

Gets the nested instances in the instance DOM. Note: This is a non-recursive operation.

Parameters
callbackA user provided callback that manipulates the nested instances.

◆ GetParentInstance()

InstanceOptionalReference AzToolsFramework::Prefab::Instance::GetParentInstance ( )

Query functions for parent instance.

◆ GetTemplateId()

TemplateId AzToolsFramework::Prefab::Instance::GetTemplateId ( ) const

Gets template id.

Returns
Template id of the instance.

◆ GetTemplateSourcePath()

const AZ::IO::Path & AzToolsFramework::Prefab::Instance::GetTemplateSourcePath ( ) const

Gets template source path.

Returns
Template source path of the instance.

◆ Reflect()

static void AzToolsFramework::Prefab::Instance::Reflect ( AZ::ReflectContext *  context)
static

AzCore Reflection.

Parameters
contextreflection context.

◆ RemoveEntitiesInHierarchy()

void AzToolsFramework::Prefab::Instance::RemoveEntitiesInHierarchy ( const AZStd::function< bool(const AZStd::unique_ptr< AZ::Entity > &)> &  filter)

Detaches entities in the instance hierarchy based on the provided filter.

Parameters
filterA user provided filter used to decide whether an entity should be detached. Returns true to detach.

◆ ReplaceEntity()

AZStd::unique_ptr< AZ::Entity > AzToolsFramework::Prefab::Instance::ReplaceEntity ( AZStd::unique_ptr< AZ::Entity > &&  entity,
EntityAliasView  alias 
)

Replaces the entity stored under the provided alias with a new one.

Parameters
entityThe new entity.
aliasThe alias of the entity that will be replaced.
Returns
The original entity or a nullptr if not found.

◆ Reset()

void AzToolsFramework::Prefab::Instance::Reset ( )

Resets the instance to an initial state. It unregisters the instance, entities and nested instances.

◆ SetContainerEntityName()

void AzToolsFramework::Prefab::Instance::SetContainerEntityName ( AZStd::string  containerName)

Sets container entity name.

Parameters
containerNameNew container entity name to be set.

◆ SetLinkId()

void AzToolsFramework::Prefab::Instance::SetLinkId ( LinkId  linkId)

Sets link id.

Parameters
linkIdLink id to be set.

◆ SetTemplateId()

void AzToolsFramework::Prefab::Instance::SetTemplateId ( TemplateId  templateId)

Sets template id.

Parameters
templateIdTemplate id to be set.

◆ SetTemplateSourcePath()

void AzToolsFramework::Prefab::Instance::SetTemplateSourcePath ( AZ::IO::Path  sourcePath)

Sets template source path.

Parameters
sourcePathTemplate source path to be set.

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