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::SliceUtilities::SliceTransaction Class Reference

#include <SliceTransaction.h>

Public Types

enum  SliceCreationFlags { CreateAsDynamic = (1<<0) }
 
enum  SlicePushFlags
 
enum  SliceAddEntityFlags { DiscardSliceAncestry = (1<<0) }
 
enum  SliceCommitFlags { DisableUndoCapture = (1<<0) }
 
typedef AZ::Outcome< void, AZStd::string > Result
 
typedef AZStd::intrusive_ptr< SliceTransactionTransactionPtr
 
typedef AZ::Data::Asset< AZ::SliceAsset > SliceAssetPtr
 
typedef AZStd::function< Result(TransactionPtr, const char *, SliceAssetPtr &)> PreSaveCallback
 
typedef AZStd::function< void(TransactionPtr, const char *, const SliceAssetPtr &)> PostSaveCallback
 

Public Member Functions

 AZ_CLASS_ALLOCATOR (SliceTransaction, AZ::SystemAllocator)
 
Result UpdateEntity (AZ::Entity *entity)
 
Result UpdateEntity (const AZ::EntityId &entityId)
 
Result UpdateEntityField (AZ::Entity *entity, const InstanceDataNode::Address &fieldNodeAddress)
 
Result UpdateEntityField (const AZ::EntityId &entityId, const InstanceDataNode::Address &fieldNodeAddress)
 
Result AddEntity (const AZ::Entity *entity, AZ::u32 addEntityFlags=0)
 
Result AddEntity (AZ::EntityId entityId, AZ::u32 addEntityFlags=0)
 
Result RemoveEntity (AZ::Entity *entity)
 
Result RemoveEntity (AZ::EntityId entityId)
 
Result AddSliceInstance (const AZ::SliceComponent::SliceInstanceAddress &sliceAddress)
 
Result Commit (const char *fullPath, PreSaveCallback preSaveCallback, PostSaveCallback postSaveCallback, AZ::u32 sliceCommitFlags=0)
 
Result Commit (const AZ::Data::AssetId &targetAssetId, PreSaveCallback preSaveCallback, PostSaveCallback postSaveCallback, AZ::u32 sliceCommitFlags=SliceCommitFlags::DisableUndoCapture)
 
const AZ::SliceComponent::EntityIdToEntityIdMap & GetLiveToAssetEntityIdMap () const
 
bool AddLiveToAssetEntityIdMapping (const AZStd::pair< AZ::EntityId, AZ::EntityId > &mapping)
 
const AZ::SliceComponent::EntityIdToEntityIdMap & GetAddedEntityIdRemaps () const
 
const SliceAssetPtr & GetTargetAsset () const
 
const SliceAssetPtr & GetOriginalTargetAsset () const
 

Static Public Member Functions

static TransactionPtr BeginNewSlice (const char *name, AZ::SerializeContext *serializeContext=nullptr, AZ::u32 sliceCreationFlags=0)
 
static TransactionPtr BeginSliceOverwrite (const SliceAssetPtr &asset, const AZ::SliceComponent &overwriteComponent, AZ::SerializeContext *serializeContext=nullptr)
 
static TransactionPtr BeginSlicePush (const SliceAssetPtr &asset, AZ::SerializeContext *serializeContext=nullptr, AZ::u32 slicePushFlags=0)
 

Friends

struct AZStd::IntrusivePtrCountPolicy< SliceTransaction >
 

Detailed Description

Utility class for performing transactional operations on slices, such as creating or pushing changes to slices. Use SliceTransaction::BeginNewSlice or SliceTransaction::BeginSlicePush to create a new transaction. See the above methods' API documentation for more information about populating and committing transactions.

A single transaction should not be interacted with simultaneously from different threads. However, it is safe to pass a transaction pointer across threads, to jobs, etc.

Member Enumeration Documentation

◆ SliceAddEntityFlags

Flags passed to AddEntity().

Enumerator
DiscardSliceAncestry 

Adds the entity as a loose entity, detaching it from any existing slice hierarchy, meaning it will no longer inherit changes to any slice instances it was part of.

◆ SliceCommitFlags

Flags passed to Commit().

Enumerator
DisableUndoCapture 

Disables undo batches from being created within the transaction.

◆ SliceCreationFlags

◆ SlicePushFlags

Member Function Documentation

◆ AddEntity() [1/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::AddEntity ( AZ::EntityId  entityId,
AZ::u32  addEntityFlags = 0 
)

For new slice or push transactions. Adds a new entity to the target slice, keeping slice ancestry by default if it is part of a slice. Use SliceAddEntityFlags::DiscardSliceAncestry to add as a loose entity.

Parameters
entity- live entity to add.
addEntityFlags- SliceAddEntityFlags
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ AddEntity() [2/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::AddEntity ( const AZ::Entity *  entity,
AZ::u32  addEntityFlags = 0 
)

For new slice or push transactions. Adds a new entity to the target slice, keeping slice ancestry by default if it is part of a slice. Use SliceAddEntityFlags::DiscardSliceAncestry to add as a loose entity.

Parameters
entity- live entity to add.
addEntityFlags- SliceAddEntityFlags
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ AddSliceInstance()

Result AzToolsFramework::SliceUtilities::SliceTransaction::AddSliceInstance ( const AZ::SliceComponent::SliceInstanceAddress &  sliceAddress)

For new slice or push transactions. Adds a live slice instance to be nested in the target slice.

Parameters
sliceAddress- pointer to live slice instance.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ BeginNewSlice()

static TransactionPtr AzToolsFramework::SliceUtilities::SliceTransaction::BeginNewSlice ( const char *  name,
AZ::SerializeContext *  serializeContext = nullptr,
AZ::u32  sliceCreationFlags = 0 
)
static

Begin a transaction for creating a new slice. Entities and nested slice instances can be added via AddEntity() and AddSliceInstance(). Use AddEntity() to add new entities to the slice. Use AddSliceInstance() to add new nested slice instances.

Parameters
name- Optional internal naming for slice. Will use "Slice" if none is provided.
serializeContext- Optional serialize context instance. Global serialize context will be used if none is provided.
sliceCreationFlags- See SliceCreationFlags
Returns
Always returns a valid pointer to the new transaction.

◆ BeginSliceOverwrite()

static TransactionPtr AzToolsFramework::SliceUtilities::SliceTransaction::BeginSliceOverwrite ( const SliceAssetPtr &  asset,
const AZ::SliceComponent &  overwriteComponent,
AZ::SerializeContext *  serializeContext = nullptr 
)
static

Begin a transaction for overwriting a slice with another slice component

Parameters
asset- Pointer to Slice asset being overwritten
overwriteComponent- Slice component containing overwrite data
serializeContext- Optional serialize context instance. Global serialize context will be used if none is provided.
Returns
pointer to the new transaction, is null if the specified asset is invalid.

◆ BeginSlicePush()

static TransactionPtr AzToolsFramework::SliceUtilities::SliceTransaction::BeginSlicePush ( const SliceAssetPtr &  asset,
AZ::SerializeContext *  serializeContext = nullptr,
AZ::u32  slicePushFlags = 0 
)
static

Begin a transaction for pushing changes to an existing slice asset. Use AddEntity() to add new entities to the slice. Use AddSliceInstance() to add new nested slice instances. Use UpdateEntity() to update whole existing entities. Use UpdateEntityField() to update a single field on an existing entity.

Parameters
asset- Pointer to slice asset to which changes are being pushed.
serializeContext- Optional serialize context instance. Global serialize context will be used if none is provided.
slicePushFlags- See SlicePushFlags
Returns
pointer to the new transaction, is null if the specified asset is invalid.

◆ Commit() [1/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::Commit ( const AZ::Data::AssetId &  targetAssetId,
PreSaveCallback  preSaveCallback,
PostSaveCallback  postSaveCallback,
AZ::u32  sliceCommitFlags = SliceCommitFlags::DisableUndoCapture 
)

Completes and commits the transaction to disk at the specified location.

Parameters
targetAssetId- Asset Id to be committed.
preSaveCallback- user providable callback to pre-process the asset just prior to writing to disk.
postSaveCallback- user providable callback invoked just after the asset is written to disk.
sliceCommitFlags- SliceCommitFlags
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ Commit() [2/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::Commit ( const char *  fullPath,
PreSaveCallback  preSaveCallback,
PostSaveCallback  postSaveCallback,
AZ::u32  sliceCommitFlags = 0 
)

Completes and commits the transaction to disk at the specified location.

Parameters
fullPath- full path to which the asset will be written.
preSaveCallback- user providable callback to pre-process the asset just prior to writing to disk.
postSaveCallback- user providable callback invoked just after the asset is written to disk.
sliceCommitFlags- SliceCommitFlags
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ GetLiveToAssetEntityIdMap()

const AZ::SliceComponent::EntityIdToEntityIdMap & AzToolsFramework::SliceUtilities::SliceTransaction::GetLiveToAssetEntityIdMap ( ) const

Retrieves an EntityId->EntityId map from the live entities that were added to the slice individually or as instances, to the Ids of the corresponding ancestor within the target slice. This can be useful if after creating a slice, you'd like a full mapping from the live entities used to create the slice to their respective entities in the asset.

◆ GetOriginalTargetAsset()

const SliceAssetPtr & AzToolsFramework::SliceUtilities::SliceTransaction::GetOriginalTargetAsset ( ) const
inline

Retrieves a pointer to the original target asset. If this is a new slice operation it will be an empty asset as there was no original target. If this is to update an existing slice it will represent the slice asset being updated.

◆ GetTargetAsset()

const SliceAssetPtr & AzToolsFramework::SliceUtilities::SliceTransaction::GetTargetAsset ( ) const
inline

Retrieves a pointer to the target asset. This is a modified clone of the original target asset that shares the correct asset id.

◆ RemoveEntity() [1/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::RemoveEntity ( AZ::Entity *  entity)

For push transactions only: Removes an existing entity from the slice.

Parameters
entity- live entity whose ancestor should be removed from the slice, or entity directly in target slice to remove.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ RemoveEntity() [2/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::RemoveEntity ( AZ::EntityId  entityId)

For push transactions only: Removes an existing entity from the slice.

Parameters
entity- live entity whose ancestor should be removed from the slice, or entity directly in target slice to remove.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ UpdateEntity() [1/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::UpdateEntity ( AZ::Entity *  entity)

For push transactions only: Adds a live entity to the transaction. Entity's data will be pushed to its ancestor in the slice.

Parameters
entity- live entity to update.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ UpdateEntity() [2/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::UpdateEntity ( const AZ::EntityId &  entityId)

For push transactions only: Adds a live entity to the transaction. Entity's data will be pushed to its ancestor in the slice.

Parameters
entity- live entity to update.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ UpdateEntityField() [1/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::UpdateEntityField ( AZ::Entity *  entity,
const InstanceDataNode::Address &  fieldNodeAddress 
)

For push transactions only: Adds a live entity to the transaction, but with a specific field address. Field data will be pushed to its ancestor in the slice.

Parameters
entity- live entity to update.
fieldNodeAddress- InstanceDataHierarchy address of the field to push to the entity in the slice.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

◆ UpdateEntityField() [2/2]

Result AzToolsFramework::SliceUtilities::SliceTransaction::UpdateEntityField ( const AZ::EntityId &  entityId,
const InstanceDataNode::Address &  fieldNodeAddress 
)

For push transactions only: Adds a live entity to the transaction, but with a specific field address. Field data will be pushed to its ancestor in the slice.

Parameters
entity- live entity to update.
fieldNodeAddress- InstanceDataHierarchy address of the field to push to the entity in the slice.
Returns
Result, AZ::Success if successful, otherwise AZ::Failure. Use GetError() to retrieve string describing error.

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