Open 3D Engine AzCore API Reference  2205.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
AZ::SliceComponent Class Reference

#include <SliceComponent.h>

Inherits AZ::Component, and MultiHandler.

Classes

struct  Ancestor
 
class  DataFlagsPerEntity
 
struct  EntityInfo
 
struct  EntityRestoreInfo
 
struct  InstantiatedContainer
 
class  SliceInstance
 
class  SliceInstanceAddress
 
class  SliceReference
 

Public Types

enum  InstantiateResult { Success, MissingDependency, CyclicalDependency }
 
using SliceInstancePtrSet = AZStd::unordered_set< SliceInstance * >
 
using SliceReferenceToInstancePtrs = AZStd::unordered_map< SliceReference *, SliceInstancePtrSet >
 
using SliceAssetToSliceInstancePtrs = AZStd::unordered_map< Data::Asset< SliceAsset >, SliceInstancePtrSet >
 
using SliceInstanceAddressSet = AZStd::unordered_set< SliceInstanceAddress >
 
using EntityList = AZStd::vector< Entity * >
 
using EntityIdToEntityIdMap = AZStd::unordered_map< EntityId, EntityId >
 
using SliceInstanceEntityIdRemapList = AZStd::vector< AZStd::pair< SliceInstanceAddress, EntityIdToEntityIdMap > >
 
using SliceInstanceToSliceInstanceMap = AZStd::unordered_map< SliceInstanceAddress, SliceInstanceAddress >
 
using EntityIdSet = AZStd::unordered_set< AZ::EntityId >
 
using SliceInstanceId = AZ::Uuid
 
using PrefabReference = SliceReference
 
using PrefabInstance = SliceInstance
 
using PrefabInstanceAddress = SliceInstanceAddress
 
using PrefabInstanceId = SliceInstanceId
 
using EntityDataFlagsMap = AZStd::unordered_map< EntityId, DataPatch::FlagsMap >
 
using EntityAncestorList = AZStd::vector< Ancestor >
 
using EntityRestoreInfoList = AZStd::vector< AZStd::pair< AZ::EntityId, AZ::SliceComponent::EntityRestoreInfo > >
 
using SliceAssetToSliceInstances = AZStd::unordered_map< Data::Asset< SliceAsset >, SliceReference::SliceInstances >
 
using SliceList = AZStd::list< SliceReference >
 
using EntityInfoMap = AZStd::unordered_map< EntityId, EntityInfo >
 
typedef AZStd::unordered_set< Data::AssetIdAssetIdSet
 

Public Member Functions

 AZ_COMPONENT (SliceComponent, "{AFD304E4-1773-47C8-855A-8B622398934F}", Data::AssetEvents)
 
SerializeContextGetSerializeContext () const
 
void SetSerializeContext (SerializeContext *context)
 
void ListenForAssetChanges ()
 Connect to asset bus for dependencies.
 
void ListenForDependentAssetChanges ()
 
const EntityListGetNewEntities () const
 Returns list of the entities that are "new" for the current slice (not based on an existing slice)
 
bool IsNewEntity (EntityId entityId) const
 Returns true for entities that are "new" entities in this slice (entities not based on another slice)
 
bool GetEntities (EntityList &entities)
 
void EraseEntities (const EntityList &entities)
 
void AddEntities (const EntityList &entities)
 
void ReplaceEntities (const EntityList &entities)
 
void AddSliceInstances (SliceAssetToSliceInstancePtrs &sliceInstances, AZStd::unordered_set< const SliceInstance * > &instancesOut)
 
bool GetEntityIds (EntityIdSet &entities)
 
size_t GetInstantiatedEntityCount () const
 
bool GetMetadataEntityIds (EntityIdSet &entities)
 
const SliceListGetSlices () const
 Returns list of all slices and their instantiated entities (for this slice component)
 
SliceListGetSlices ()
 Returns list of all slices and their instantiated entities (for this slice component)
 
const SliceListGetInvalidSlices () const
 
SliceReferenceGetSlice (const Data::Asset< SliceAsset > &sliceAsset)
 
SliceReferenceGetSlice (const Data::AssetId &sliceAssetId)
 
SliceInstanceAddress AddSlice (const Data::Asset< SliceAsset > &sliceAsset, const AZ::IdUtils::Remapper< AZ::EntityId >::IdMapper &customMapper=nullptr, SliceInstanceId sliceInstanceId=SliceInstanceId::CreateRandom())
 
SliceInstanceAddress AddSliceUsingExistingEntities (const Data::Asset< SliceAsset > &sliceAsset, const AZ::SliceComponent::EntityIdToEntityIdMap &assetToLiveMap, SliceInstanceId sliceInstanceId=SliceInstanceId::CreateRandom())
 
SliceReferenceAddSlice (SliceReference &sliceReference)
 Adds a slice reference (moves it) along with its instance information.
 
SliceInstanceAddress AddSliceInstance (SliceReference *sliceReference, SliceInstance *sliceInstance)
 Adds a slice (moves it) from another already generated reference/instance pair.
 
SliceInstanceAddress CloneAndAddSubSliceInstance (const SliceInstance *sourceSliceInstance, const AZStd::vector< AZ::SliceComponent::SliceInstanceAddress > &sourceSubSliceInstanceAncestry, const AZ::SliceComponent::SliceInstanceAddress &sourceSubSliceInstanceAddress, AZ::SliceComponent::EntityIdToEntityIdMap *out_sourceToCloneEntityIdMap=nullptr, bool preserveIds=false)
 
bool RemoveSlice (const Data::Asset< SliceAsset > &sliceAsset)
 Remove an entire slice asset reference and all its instances.
 
bool RemoveSlice (const SliceReference *slice)
 
bool RemoveSliceInstance (SliceInstance *instance)
 Removes the slice instance, if this is last instance the SliceReference will be removed too.
 
bool RemoveSliceInstance (SliceInstanceAddress sliceAddress)
 
void AddEntity (Entity *entity)
 Adds entity to the current slice and takes ownership over it (you should not manage/delete it)
 
AZ::EntityFindEntity (EntityId entityId)
 
bool RemoveEntity (Entity *entity, bool isDeleteEntity=true, bool isRemoveEmptyInstance=true)
 
bool RemoveEntity (EntityId entityId, bool isDeleteEntity=true, bool isRemoveEmptyInstance=true)
 Same as RemoveEntity but by using entityId.
 
bool RemoveMetaDataEntity (EntityId metaDataEntityId)
 
void RemoveAllEntities (bool deleteEntities=true, bool removeEmptyInstances=true)
 
void RemoveLooseEntity (EntityId entityId)
 
SliceInstanceAddress FindSlice (Entity *entity)
 
SliceInstanceAddress FindSlice (EntityId entityId)
 
bool FlattenSlice (SliceReference *toFlatten, const EntityId &toFlattenRoot)
 
bool GetEntityRestoreInfo (const AZ::EntityId entityId, EntityRestoreInfo &info)
 
SliceInstanceAddress RestoreEntity (AZ::Entity *entity, const EntityRestoreInfo &restoreInfo, bool isEntityAdd=false)
 
void SetMyAsset (SliceAsset *asset)
 
const SliceAssetGetMyAsset () const
 
const DataPatch::FlagsMapGetEntityDataFlags (EntityId entityId) const
 
bool SetEntityDataFlags (EntityId entityId, const DataPatch::FlagsMap &dataFlags)
 
DataPatch::Flags GetEffectOfEntityDataFlagsAtAddress (EntityId, const DataPatch::AddressType &dataAddress) const
 
DataPatch::Flags GetEntityDataFlagsAtAddress (EntityId entityId, const DataPatch::AddressType &dataAddress) const
 
bool SetEntityDataFlagsAtAddress (EntityId entityId, const DataPatch::AddressType &dataAddress, DataPatch::Flags flags)
 
bool GetInstanceMetadataEntities (EntityList &outMetadataEntities)
 
bool GetAllInstanceMetadataEntities (EntityList &outMetadataEntities)
 
bool GetAllMetadataEntities (EntityList &outMetadataEntities)
 
AZ::EntityGetMetadataEntity ()
 
void GetReferencedSliceAssets (AssetIdSet &idSet, bool recurse=true)
 
SliceComponentClone (AZ::SerializeContext &serializeContext, SliceInstanceToSliceInstanceMap *sourceToCloneSliceInstanceMap=nullptr) const
 
void AllowPartialInstantiation (bool allow)
 
bool IsAllowPartialInstantiation () const
 
bool IsDynamic () const
 
void SetIsDynamic (bool isDynamic)
 
InstantiateResult Instantiate ()
 
bool IsInstantiated () const
 
void GenerateNewEntityIds (EntityIdToEntityIdMap *previousToNewIdMap=nullptr)
 
void InitMetadata ()
 
void RemoveAndCacheInstances (const SliceReferenceToInstancePtrs &instancesToRemove)
 
void RestoreCachedInstances ()
 
const DataFlagsPerEntityGetDataFlagsForInstances () const
 
- Public Member Functions inherited from AZ::Component
 AZ_RTTI (AZ::Component, "{EDFCB2CF-F75D-43BE-B26B-F35821B29247}")
 
 Component ()
 
virtual ~Component ()
 
EntityGetEntity () const
 
EntityId GetEntityId () const
 
NamedEntityId GetNamedEntityId () const
 
ComponentId GetId () const
 
virtual const TypeIdGetUnderlyingComponentType () const
 
void SetId (const ComponentId &id)
 
virtual ComponentValidationResult ValidateComponentRequirements (const ImmutableEntityVector &, const AZStd::unordered_set< AZ::Crc32 > &) const
 
bool SetConfiguration (const AZ::ComponentConfig &config)
 
bool GetConfiguration (AZ::ComponentConfig &outConfig) const
 

Static Public Member Functions

static void GetMappingBetweenSubsliceAndSourceInstanceEntityIds (const SliceComponent::SliceInstance *sourceSliceInstance, const AZStd::vector< AZ::SliceComponent::SliceInstanceAddress > &sourceSubsliceInstanceAncestry, const AZ::SliceComponent::SliceInstanceAddress &sourceSubsliceInstanceAddress, AZ::SliceComponent::EntityIdToEntityIdMap &subsliceToLiveMappingResult, bool flipMapping=false)
 

Protected Types

typedef AZStd::vector< AZ::Data::AssetIdAssetIdVector
 

Protected Member Functions

void Activate () override
 
void Deactivate () override
 
void OnAssetReloaded (Data::Asset< Data::AssetData > asset) override
 
void PrepareSave ()
 Prepare component entity for save, if this is a leaf entity, data patch will be build.
 
void BuildEntityInfoMap ()
 Populate the entity info map. This will re-populate it even if already populated.
 
void RebuildEntityInfoMapIfNecessary ()
 Repopulate the entity info map if it was already populated.
 
DataFlagsPerEntityGetCorrectBundleOfDataFlags (EntityId entityId)
 Return the appropriate DataFlagsPerEntity collection containing this entity's data flags.
 
const DataFlagsPerEntityGetCorrectBundleOfDataFlags (EntityId entityId) const
 
void BuildDataFlagsForInstances ()
 
void CleanMetadataAssociations ()
 
const EntityInfoMapGetEntityInfoMap () const
 Returns the entity info map (and builds it if necessary).
 
SliceReferenceAddOrGetSliceReference (const Data::Asset< SliceAsset > &sliceAsset)
 Returns the reference associated with the specified asset Id. If none is present, one will be created.
 
SliceComponent::SliceList::iterator RemoveSliceReference (SliceComponent::SliceList::iterator sliceReferenceIt)
 Removes a slice reference (and all instances) by iterator.
 
void PushInstantiateCycle (const AZ::Data::AssetId &assetId)
 Utility function to add an assetId to the cycle checker vector.
 
bool CheckContainsInstantiateCycle (const AZ::Data::AssetId &assetId)
 
void PopInstantiateCycle (const AZ::Data::AssetId &assetId)
 Utility function to pop an assetId to the cycle checker vector (also checks to make sure its at the tail of it and clears it)
 
- Protected Member Functions inherited from AZ::Component
virtual void Init ()
 
virtual bool ReadInConfig (const ComponentConfig *baseConfig)
 
virtual bool WriteOutConfig (ComponentConfig *outBaseConfig) const
 
void SetEntity (Entity *entity)
 

Static Protected Member Functions

static void GetProvidedServices (ComponentDescriptor::DependencyArrayType &provided)
 ComponentDescriptor::GetProvidedServices
 
static void GetDependentServices (ComponentDescriptor::DependencyArrayType &dependent)
 ComponentDescriptor::GetDependentServices
 
static void Reflect (ReflectContext *reflection)
 ComponentDescriptor::Reflect
 
static void ApplyEntityMapId (EntityIdToEntityIdMap &destination, const EntityIdToEntityIdMap &mapping)
 Utility function to apply a EntityIdToEntityIdMap to a EntityIdToEntityIdMap (the mapping will override values in the destination)
 

Protected Attributes

SliceAssetm_myAsset
 Pointer to the asset we belong to, note this is just a reference stored by the handler, we don't need Asset<SliceAsset> as it's not a reference to another asset.
 
SerializeContextm_serializeContext
 
EntityInfoMap m_entityInfoMap
 A cached mapping built for quick lookups between an EntityId and its owning SliceInstance.
 
EntityInfoMap m_metaDataEntityInfoMap
 A cached mapping built for quick lookups between a MetaDataEntityId and its owning SliceInstance.
 
EntityList m_entities
 Entities that are new (not based on a slice).
 
SliceList m_slices
 List of base slices and their instances in the world.
 
SliceAssetToSliceInstances m_cachedSliceInstances
 Slice instances saved in layers on the root slice are cached here during the serialization process.
 
SliceList m_cachedSliceReferences
 Slice references saved in layers on the root slice are cached here during the serialization process.
 
SliceList m_invalidSlices
 List of slice references that did not load correctly.
 
AZ::Entity m_metadataEntity
 Entity for attaching slice metadata components.
 
DataFlagsPerEntity m_dataFlagsForNewEntities
 DataFlags for new entities (DataFlags for entities based on a slice are stored within the SliceInstance)
 
DataFlagsPerEntity m_cachedDataFlagsForInstances
 Cached DataFlags to be used when instantiating instances of this slice.
 
bool m_hasGeneratedCachedDataFlags
 Whether the cached DataFlags have been generated yet.
 
AZStd::atomic< bool > m_slicesAreInstantiated
 Instantiate state of the base slices (they should be instantiated or not)
 
bool m_allowPartialInstantiation
 Instantiation is still allowed even if dependencies are missing.
 
bool m_isDynamic
 Dynamic slices are available for instantiation at runtime.
 
AZ::Data::AssetFilterCB m_assetLoadFilterCB
 Asset load filter callback to apply for internal loads during data patching.
 
AZ::u32 m_filterFlags
 Asset load filter flags to apply for internal loads during data patching.
 
AZStd::recursive_mutex m_instantiateMutex
 Used to prevent multiple threads from trying to instantiate the slices at once.
 
- Protected Attributes inherited from AZ::Component
Entitym_entity
 Reference to the entity that owns the component. The value is null if the component is not attached to an entity.
 
ComponentId m_id
 A component ID that is unique for an entity. This component ID is not unique across all entities.
 

Static Protected Attributes

static AssetIdVector m_instantiateCycleChecker
 Used to prevent cyclic dependencies.
 

Friends

class SliceComponentSerializationEvents
 
class SliceAssetHandler
 

Detailed Description

Slice component manages entities on the project graph (Slice is a node). SliceComponent with nested dependencies is an edit only concept. We have a runtime version with dependencies so that we can accelerate production by live tweaking of game objects. Otherwise all slices should be exported as list of entities (flat structure). There is an exception with the "dynamic" slices, which should still be a flat list of entities that you "clone" for dynamic reuse.

Member Typedef Documentation

◆ PrefabInstance

◆ PrefabInstanceAddress

◆ PrefabInstanceId

Deprecated:
Use SliceInstanceId.

◆ PrefabReference

Member Function Documentation

◆ Activate()

void AZ::SliceComponent::Activate ( )
overrideprotectedvirtual

Puts the component into an active state. The system calls this function once during activation of each entity that owns the component. You must override this function. The system calls a component's Activate() function only if all services and components that the component depends on are present and active. Use GetProvidedServices and GetDependentServices to specify these dependencies.

Implements AZ::Component.

◆ AddEntities()

void AZ::SliceComponent::AddEntities ( const EntityList entities)

Adds the passed in entities to become owned and tracked by this slice. Used by the layer system to return entities that were briefly borrowed from the root slice. entities The list of entitites to add to this slice.

◆ AddSlice()

SliceInstanceAddress AZ::SliceComponent::AddSlice ( const Data::Asset< SliceAsset > &  sliceAsset,
const AZ::IdUtils::Remapper< AZ::EntityId >::IdMapper &  customMapper = nullptr,
SliceInstanceId  sliceInstanceId = SliceInstanceId::CreateRandom() 
)

Adds a dependent slice, and instantiate the slices if needed.

Parameters
sliceAssetslice asset.
customMapperoptional entity runtime id mapper.
assetLoadFilterOptional asset load filter. Any filtered-out asset references that are not already memory-resident will not trigger loads.
sliceInstanceIdThe id assigned to the slice instance to be created. If no argument is passed in a random id will be generated as default. If the same sliceInstanceId is already registered to the underlying SlicReference an invalid SliceInstanceAddress is returned as error.
Returns
A SliceInstanceAddress pointing to the added instance. An invalid SliceInstanceAddress if adding slice failed.

◆ AddSliceInstances()

void AZ::SliceComponent::AddSliceInstances ( SliceAssetToSliceInstancePtrs sliceInstances,
AZStd::unordered_set< const SliceInstance * > &  instancesOut 
)

Adds the passed in slice instances to this slice. Used by the layer system on load, when a layer is loaded, it may contain one or more slice instances. This allows layers to populate the root slice with those instances.

Parameters
sliceInstancesinstances that will be given to this slice. It will be empty after this operation completes.

◆ AddSliceUsingExistingEntities()

SliceInstanceAddress AZ::SliceComponent::AddSliceUsingExistingEntities ( const Data::Asset< SliceAsset > &  sliceAsset,
const AZ::SliceComponent::EntityIdToEntityIdMap assetToLiveMap,
SliceInstanceId  sliceInstanceId = SliceInstanceId::CreateRandom() 
)
Parameters
sliceAssetAsset of the slice being added
assetToLiveMapMapping from the provided slice asset's EntityID's to existing EntityIDs. Existing EntityIDs should be owned by the SliceComponent making this call.
sliceInstanceIdThe id assigned to the slice instance to be created. If no argument is passed in a random id will be generated as default. If the same sliceInstanceId is already registered to an invalid SliceInstanceAddress is returned as error.
Returns
A SliceInstanceAddress pointing to the added instance. A null SliceInstanceAddress if adding slice failed.

◆ AllowPartialInstantiation()

void AZ::SliceComponent::AllowPartialInstantiation ( bool  allow)
inline

Set whether the slice can be instantiated despite missing dependent slices (allowed by default).

◆ CheckContainsInstantiateCycle()

bool AZ::SliceComponent::CheckContainsInstantiateCycle ( const AZ::Data::AssetId assetId)
protected

Utility function to check if the given assetId would cause an instantiation cycle, and if so output the chain of slices that causes the cycle.

◆ CleanMetadataAssociations()

void AZ::SliceComponent::CleanMetadataAssociations ( )
protected

During instance instantiation, entities from root slices may be removed by data patches. We need to remove these from the metadata associations in our newly cloned instance metadata entities.

◆ Clone()

SliceComponent* AZ::SliceComponent::Clone ( AZ::SerializeContext serializeContext,
SliceInstanceToSliceInstanceMap sourceToCloneSliceInstanceMap = nullptr 
) const

Clones the slice, its references, and its instances. Entity Ids are not regenerated during this process. This utility is currently used to clone slice asset data for data-push without modifying the existing asset in-memory.

Parameters
serializeContextSerializeContext to use for cloning
sourceToCloneSliceInstanceMap[out] (optional) The map between source SliceInstances and cloned SliceInstances.
Returns
A clone of this SliceComponent

◆ CloneAndAddSubSliceInstance()

SliceInstanceAddress AZ::SliceComponent::CloneAndAddSubSliceInstance ( const SliceInstance sourceSliceInstance,
const AZStd::vector< AZ::SliceComponent::SliceInstanceAddress > &  sourceSubSliceInstanceAncestry,
const AZ::SliceComponent::SliceInstanceAddress sourceSubSliceInstanceAddress,
AZ::SliceComponent::EntityIdToEntityIdMap out_sourceToCloneEntityIdMap = nullptr,
bool  preserveIds = false 
)

Given a sub-slice instance, create a slice reference based on the sub-slice instance's SliceAsset (if the slice reference doesn't already exist), then clone the sub-slice instance and add the clone to the slice reference just created.

Parameters
sourceSliceInstanceThe slice instance that contains the sub-slice instance.
sourceSubSliceInstanceAncestryThe ancestry in order from sourceSubSlice to sourceSlice
sourceSubSliceInstanceAddressThe address of the sub-slice instance to be cloned.
out_sourceToCloneEntityIdMap[Optional] If provided, the internal source to clone entity ID map will be returned
preserveIds[Optional] If true will not generate new IDs for the clone and will direct entity ID maps from base ID to existing live IDs of the original
Returns
The address of the newly created clone-instance.

◆ Deactivate()

void AZ::SliceComponent::Deactivate ( )
overrideprotectedvirtual

Deactivates the component. The system calls this function when the owning entity is being deactivated. You must override this function. As a best practice, ensure that this function returns the component to a minimal footprint. The order of deactivation is the reverse of activation, so your component is deactivated before the components it depends on.

The system always calls the component's Deactivate() function before destroying the component. However, deactivation is not always followed by the destruction of the component. An entity and its components can be deactivated and reactivated without being destroyed. Ensure that your Deactivate() implementation can handle this scenario.

Implements AZ::Component.

◆ EraseEntities()

void AZ::SliceComponent::EraseEntities ( const EntityList entities)

Erases all entities passed in from this slice's m_entities list of loose, owned entities.

Parameters
entitiesThe list of entities to erase.

◆ FindEntity()

AZ::Entity* AZ::SliceComponent::FindEntity ( EntityId  entityId)

Find an entity in the slice by entity Id.

◆ FindSlice()

SliceInstanceAddress AZ::SliceComponent::FindSlice ( Entity entity)

Returns the slice information about an entity, if it belongs to the component and is in a slice.

Parameters
entitypointer to instantiated entity
Returns
pair of SliceReference and SliceInstance if the entity is in a "child" slice, otherwise null,null. This is true even if entity belongs to the slice (but it's not in a "child" slice)

◆ FlattenSlice()

bool AZ::SliceComponent::FlattenSlice ( SliceReference toFlatten,
const EntityId toFlattenRoot 
)

Flattens a slice reference directly into the slice component and then removes the reference, all dependencies inherited from the reference will become directly owned by the slice component

Parameters
toFlattenThe reference we are flattening into the component
toFlattenRootThe root entity used to determine common ancestry among the entities within the reference
Returns
false if flattening failed

◆ GenerateNewEntityIds()

void AZ::SliceComponent::GenerateNewEntityIds ( EntityIdToEntityIdMap previousToNewIdMap = nullptr)

Generate new entity Ids and remap references

Parameters
previousToNewIdMapOutput map of previous entityIds to newly generated entityIds

◆ GetAllInstanceMetadataEntities()

bool AZ::SliceComponent::GetAllInstanceMetadataEntities ( EntityList outMetadataEntities)

Appends all metadata entities belonging to instances owned by this slice, including those in nested instances to the end of the given list.

◆ GetAllMetadataEntities()

bool AZ::SliceComponent::GetAllMetadataEntities ( EntityList outMetadataEntities)

Gets all metadata entities belonging to this slice. This includes instance metadata components and the slice's own metadata component. Because the contents of the result could come from multiple objects, the calling function must provide its own container. Returns true if the operation succeeded (Even if the resulting container is empty)

◆ GetDataFlagsForInstances()

const DataFlagsPerEntity& AZ::SliceComponent::GetDataFlagsForInstances ( ) const

Returns data flags for use when instantiating an instance of this slice. These data flags include those harvested from the entire slice ancestry.

◆ GetEffectOfEntityDataFlagsAtAddress()

DataPatch::Flags AZ::SliceComponent::GetEffectOfEntityDataFlagsAtAddress ( EntityId  ,
const DataPatch::AddressType &  dataAddress 
) const

Get effect of data flags at a particular address within this entity. Note that the "effect" of data flags could be impacted by data flags set at other addresses, and data flags set in the slice that this entity is based on.

◆ GetEntities()

bool AZ::SliceComponent::GetEntities ( EntityList entities)

Returns all entities including the ones based on instances, you need to provide container as we don't keep all entities in one list (we can change that if we need it easily). If entities are not instantiated (the ones based on slices) Instantiate will be called

Returns
true if entities list has been populated (even if empty), and false if instantiation failed.

◆ GetEntityDataFlags()

const DataPatch::FlagsMap& AZ::SliceComponent::GetEntityDataFlags ( EntityId  entityId) const

Return all data flags set for this entity. Addresses are relative the entity.

◆ GetEntityDataFlagsAtAddress()

DataPatch::Flags AZ::SliceComponent::GetEntityDataFlagsAtAddress ( EntityId  entityId,
const DataPatch::AddressType &  dataAddress 
) const

Get the data flags set at a particular address within this entity.

◆ GetEntityIds()

bool AZ::SliceComponent::GetEntityIds ( EntityIdSet entities)

Adds the IDs of all non-metadata entities, including the ones based on instances, to the provided set.

Parameters
entitiesAn entity ID set to add the IDs to

◆ GetEntityRestoreInfo()

bool AZ::SliceComponent::GetEntityRestoreInfo ( const AZ::EntityId  entityId,
EntityRestoreInfo info 
)

Extracts data required to restore the specified entity.

Returns
false if the entity is not part of an internal instance, and doesn't require any special restore operations.

◆ GetInstanceMetadataEntities()

bool AZ::SliceComponent::GetInstanceMetadataEntities ( EntityList outMetadataEntities)

Appends the metadata entities belonging only directly to each instance in the slice to the given list. Metadata entities belonging to any instances within each instance are omitted.

◆ GetInstantiatedEntityCount()

size_t AZ::SliceComponent::GetInstantiatedEntityCount ( ) const

Returns the count of all instantiated entities, including the ones based on instances. If the slice has not been instantiated then 0 is returned.

◆ GetInvalidSlices()

const SliceList& AZ::SliceComponent::GetInvalidSlices ( ) const

Returns the list of slice references associated with this slice that could not be loaded.

Returns
The list of invalid slice references. This is empty if there are none.

◆ GetMappingBetweenSubsliceAndSourceInstanceEntityIds()

static void AZ::SliceComponent::GetMappingBetweenSubsliceAndSourceInstanceEntityIds ( const SliceComponent::SliceInstance sourceSliceInstance,
const AZStd::vector< AZ::SliceComponent::SliceInstanceAddress > &  sourceSubsliceInstanceAncestry,
const AZ::SliceComponent::SliceInstanceAddress sourceSubsliceInstanceAddress,
AZ::SliceComponent::EntityIdToEntityIdMap subsliceToLiveMappingResult,
bool  flipMapping = false 
)
static
Parameters
sourceSliceInstanceThe slice instance that contains the sub-slice instance
sourceSubsliceInstanceAncestryThe ancestry in order from sourceSubslice to sourceSlice
sourceSubsliceInstanceAddressThe address of the sub-slice instance to be cloned
subsliceToLiveMappingResultStores the resulting mapping from the sub slice's base Entity Ids to the source slice's live Entity Ids
flipMappingsubsliceToLiveMappingResult will be flipped to instead contain the mapping from source slice to sub slice. Defaults to false

◆ GetMetadataEntity()

AZ::Entity* AZ::SliceComponent::GetMetadataEntity ( )

Gets the metadata entity belonging to this slice

◆ GetMetadataEntityIds()

bool AZ::SliceComponent::GetMetadataEntityIds ( EntityIdSet entities)

Adds ID of every metadata entity that's part of this slice, including those based on instances, to the given set.

Parameters
entitiesAn entity ID set to add the IDs to

◆ GetMyAsset()

const SliceAsset* AZ::SliceComponent::GetMyAsset ( ) const
inline

Gets the asset that owns this component.

◆ GetReferencedSliceAssets()

void AZ::SliceComponent::GetReferencedSliceAssets ( AssetIdSet idSet,
bool  recurse = true 
)

Gathers referenced slice assets for this slice (slice assets this contains, slice assets this depends on)

Parameters
idSetthe container that contains the referenced assets after this function is called
recursewhether to recurse. true by default so you get ALL referenced assets, false will return only directly-referenced assets

◆ InitMetadata()

void AZ::SliceComponent::InitMetadata ( )

Newly created slices and legacy slices won't have required metadata components. This will check to see if necessary components to the function of the metadata entities are present and

Parameters
instanceSource slice instance

◆ Instantiate()

InstantiateResult AZ::SliceComponent::Instantiate ( )

Instantiate entities for this slice, otherwise only the data are stored.

◆ IsAllowPartialInstantiation()

bool AZ::SliceComponent::IsAllowPartialInstantiation ( ) const
inline

Returns whether or not the slice allows partial instantiation.

◆ IsDynamic()

bool AZ::SliceComponent::IsDynamic ( ) const
inline

Returns whether or not this is a dynamic slice to be exported for runtime instantiation.

◆ ListenForDependentAssetChanges()

void AZ::SliceComponent::ListenForDependentAssetChanges ( )

This will listen for child asset changes and instruct all other slices in the slice hierarchy to do the same.

◆ RemoveAllEntities()

void AZ::SliceComponent::RemoveAllEntities ( bool  deleteEntities = true,
bool  removeEmptyInstances = true 
)

A performant way to remove every entity from a SliceComponent. Operates in the same way as though you were to loop through every entity in a SliceComponent and call RemoveEntity(entityId) on them, but using this method will be much faster and is highly recommended.

Parameters
deleteEntitiestrue by default as we own all entities, pass false to just remove the entity and gain ownership of it
removeEmptyInstancestrue by default. When set to true, instances will be removed when the last of their entities is removed

◆ RemoveAndCacheInstances()

void AZ::SliceComponent::RemoveAndCacheInstances ( const SliceReferenceToInstancePtrs instancesToRemove)

Removes the passed in instances from this slice, and caches them to restore later. Used by the layer system so layers can briefly take ownership of these instances. This allows the level slice to save with only slice instances and references unique to the level, and allows layers to save slices instances and references to themselves. instancesToRemove The collection of instances that should be removed from this slice.

◆ RemoveMetaDataEntity()

bool AZ::SliceComponent::RemoveMetaDataEntity ( EntityId  metaDataEntityId)

Removes and deletes a meta data entity from the current slice

Parameters
metaDataEntityIdEntityId of the to be removed meta data entity
Returns
Returns true if the operation succeeds. Otherwise returns false and logs an error.

◆ ReplaceEntities()

void AZ::SliceComponent::ReplaceEntities ( const EntityList entities)

Clears the m_entities list for this slice and replaces it with the passed in entity list. Used by the layer system to return entities it borrowed. Used as a performance shortcut, the layer system will have already retrieved a complete list of all entities managed by this slice.

Parameters
entitiesThe list of entities to replace m_entities with.

◆ RestoreCachedInstances()

void AZ::SliceComponent::RestoreCachedInstances ( )

Restores slice instances that were cached when RemoveAndCacheInstances was called.

◆ RestoreEntity()

SliceInstanceAddress AZ::SliceComponent::RestoreEntity ( AZ::Entity entity,
const EntityRestoreInfo restoreInfo,
bool  isEntityAdd = false 
)

Adds an entity back to an existing instance. This create a reference for the specified asset if it doesn't already exist. If the reference exists, but the instance with the specified id does not, one will be created. Ownership of the entity is transferred to the instance.

Parameters
entityA pointer to the entity to be restored.
restoreInfoAn object holding various information for restoring the entity. Please see EntityRestoreInfo.
isEntityAddspecifies if the entity we're restoring is part of an entity add. Skips checks for if the entity is in the SliceComponent. As the entity will not be a part of the SliceComponent until it is restored. Defaults to false.
Returns
A pair of SliceReference and SliceInstance, or null if the operation failed.

◆ SetEntityDataFlags()

bool AZ::SliceComponent::SetEntityDataFlags ( EntityId  entityId,
const DataPatch::FlagsMap dataFlags 
)

Set all data flags for this entity. Addresses should be relative the entity.

Returns
True if flags are set. False if the entity does not exist in this slice.

◆ SetEntityDataFlagsAtAddress()

bool AZ::SliceComponent::SetEntityDataFlagsAtAddress ( EntityId  entityId,
const DataPatch::AddressType &  dataAddress,
DataPatch::Flags  flags 
)

Set the data flags at a particular address within this entity.

Returns
True if flags are set. False if the entity does not exist in this slice.

◆ SetIsDynamic()

void AZ::SliceComponent::SetIsDynamic ( bool  isDynamic)
inline

Designates this slice as dynamic (can be instantiated at runtime).

◆ SetMyAsset()

void AZ::SliceComponent::SetMyAsset ( SliceAsset asset)
inline

Sets the asset that owns this component, which allows us to listen for asset changes.


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