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::Layers::EditorLayerComponent Class Reference

#include <EditorLayerComponent.h>

Inherits AzToolsFramework::Components::EditorComponentBase, EditorLayerComponentRequestBus::Handler, EditorLayerInfoRequestsBus::Handler, and AZ::TransformNotificationBus::Handler.

Public Member Functions

 AZ_EDITOR_COMPONENT (EditorLayerComponent, "{976E05F0-FAC7-43B6-B621-66108AE73FD4}")
 
LayerResult WriteLayerAndGetEntities (QString levelAbsoluteFolder, EntityList &entityList, AZ::SliceComponent::SliceReferenceToInstancePtrs &layerInstances) override
 
void RestoreEditorData () override
 
bool HasLayer () override
 
void UpdateLayerNameConflictMapping (AZStd::unordered_map< AZStd::string, int > &nameConflictsMapping) override
 
QColor GetLayerColor () override
 
AZ::Color GetColorPropertyValue () override
 
bool IsSaveFormatBinary () override
 
bool IsLayerNameValid () override
 
AZ::Outcome< AZStd::string, AZStd::string > GetLayerBaseFileName () override
 
AZ::Outcome< AZStd::string, AZStd::string > GetLayerFullFileName () override
 
AZ::Outcome< AZStd::string, AZStd::string > GetLayerFullFilePath (const QString &levelAbsoluteFolder) override
 
void SetLayerChildrenVisibility (bool visible) override
 
bool AreLayerChildrenVisible () override
 
bool HasUnsavedChanges () override
 
void MarkLayerWithUnsavedChanges () override
 
void SetOverwriteFlag (bool set) override
 
bool GetOverwriteFlag () override
 
bool DoesLayerFileExistOnDisk (const QString &levelAbsoluteFolder) override
 
bool GatherSaveDependencies (AZStd::unordered_set< AZ::EntityId > &allLayersToSave, bool &mustSaveLevel) override
 
void AddLayerSaveDependency (const AZ::EntityId &layerSaveDependency) override
 
void AddLevelSaveDependency () override
 
void GatherLayerEntitiesWithName (const AZStd::string &layerName, EntityIdSet &layerEntities) override
 
void CanParentChange (bool &parentCanChange, AZ::EntityId oldParent, AZ::EntityId newParent) override
 
LayerResult ReadLayer (QString levelPakFile, AZ::SliceComponent::SliceAssetToSliceInstancePtrs &sliceInstances, AZStd::unordered_map< AZ::EntityId, AZ::Entity * > &uniqueEntities)
 
AZStd::string GetCachedLayerBaseFileName ()
 
void CleanupLoadedLayer ()
 
void SetLayerColor (AZ::Color newColor) override
 
void SetSaveFormat (LayerProperties::SaveFormat saveFormat)
 
AzToolsFramework::Layers::LayerProperties::SaveFormat GetSaveFormat ()
 
- Public Member Functions inherited from AzToolsFramework::Components::EditorComponentBase
 AZ_RTTI (EditorComponentBase, "{D5346BD4-7F20-444E-B370-327ACD03D4A0}", AZ::Component)
 
 EditorComponentBase ()
 
void SetDirty ()
 
virtual void Init () override
 
virtual void Activate () override
 
virtual void Deactivate () override
 
void OnAfterEntitySet () override final
 
void SetSerializedIdentifier (AZStd::string serializedIdentifier) override final
 
AZStd::string GetSerializedIdentifier () const override final
 
AZ::TransformInterface * GetTransform () const
 
AZ::Transform GetWorldTM () const
 
AZ::Transform GetLocalTM () const
 
bool IsSelected () const
 
virtual void BuildGameEntity (AZ::Entity *)
 
virtual void SetPrimaryAsset (const AZ::Data::AssetId &)
 
virtual void AddContextMenuActions (QMenu *)
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 
static void GetProvidedServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
static void GetIncompatibleServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
static void GetRequiredServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
static void CreateLayerAssetContextMenu (QMenu *menu, const AZStd::string &fullFilePath, QString levelPath)
 
static void RecoverLayer (const AZStd::string &fullFilePath)
 
static LayerResult RecoverEditorLayer (const AZStd::shared_ptr< Layers::EditorLayer > editorLayer, const AZStd::string &newLayerName, const AZ::EntityId &layerParentId)
 
static const char * GetLayerExtension ()
 
static AZStd::string GetLayerExtensionWithDot ()
 
static AZ::EntityId CreateLayerEntity (const AZStd::string &name, const AZ::Color &layerColor, const LayerProperties::SaveFormat &saveAsBinary=LayerProperties::SaveFormat::Xml, const AZ::EntityId &optionalEntityId=AZ::EntityId())
 
static AZ::EntityId CreateLayerEntityFromName (const AZStd::string &name)
 
- Static Public Member Functions inherited from AzToolsFramework::Components::EditorComponentBase
static void Reflect (AZ::ReflectContext *context)
 

Protected Member Functions

void Init () override
 
void Activate () override
 
void Deactivate () override
 
LayerResult PrepareLayerForSaving (EditorLayer &layer, EntityList &entityList, AZ::SliceComponent::SliceReferenceToInstancePtrs &layerInstances)
 
LayerResult WriteLayerToStream (const EditorLayer &layer, AZ::IO::ByteContainerStream< AZStd::vector< char > > &entitySaveStream)
 
LayerResult WriteLayerStreamToDisk (QString levelAbsoluteFolder, const AZ::IO::ByteContainerStream< AZStd::vector< char > > &entitySaveStream)
 
LayerResult CreateDirectoryAtPath (const QString &path)
 
LayerResult PopulateFromLoadedLayerData (const EditorLayer &loadedLayer, AZ::SliceComponent::SliceAssetToSliceInstancePtrs &sliceInstances, AZStd::unordered_map< AZ::EntityId, AZ::Entity * > &uniqueEntities)
 
void AddUniqueEntitiesAndInstancesFromEditorLayer (const EditorLayer &loadedLayer, AZ::SliceComponent::SliceAssetToSliceInstancePtrs &sliceInstances, AZStd::unordered_map< AZ::EntityId, AZ::Entity * > &uniqueEntities)
 
QString GetLayerDirectory () const
 
QString GetLayerTempDirectory () const
 
QString GetLayerTempExtension () const
 
int GetMaxTempFileWriteAttempts () const
 
LayerResult GenerateLayerFileName ()
 
LayerResult GetFileHash (QString filePath, QCryptographicHash &hash)
 
LayerResult GenerateCleanupFailureWarningResult (QString message, const LayerResult *currentFailure)
 
LayerResult CleanupTempFileAndFolder (QString tempFile, const QDir &layerTempFolder, const LayerResult *currentFailure)
 
LayerResult CleanupTempFolder (const QDir &layerTempFolder, const LayerResult *currentFailure)
 
void GatherAllNonLayerNonSliceDescendants (EntityList &entityList, EditorLayer &layer, const AZStd::unordered_map< AZ::EntityId, AZ::Entity * > &entityIdsToEntityPtrs, AzToolsFramework::Components::TransformComponent &transformComponent) const
 
void SetUnsavedChanges (bool unsavedChanges)
 

Static Protected Member Functions

static bool CanAttemptToRecoverLayerAndGetLayerInfo (const AZStd::string &fullFilePath, AZStd::string &newLayerName, AZ::EntityId &layerParentId)
 
static LayerResult IsLayerDataSafeToRecover (const AZStd::shared_ptr< Layers::EditorLayer > loadedLayer, AZ::SliceComponent &rootSlice)
 
static AZ::EntityId CreateMissingLayerAncestors (const AZStd::string &nearestLayerAcenstorName)
 
static LayerResult UpdateListOfDiscoveredEntityIds (AZStd::unordered_set< AZ::EntityId > &discoveredIds, const AZ::EntityId &newEntity)
 
static AZStd::string GetLayerSeparator ()
 

Protected Attributes

EditorLayerm_loadedLayer = nullptr
 
AZStd::string m_layerFileName
 
LayerProperties m_editableLayerProperties
 
LayerProperties m_cachedLayerProperties
 
bool m_hasUnsavedChanges = false
 
AZStd::unordered_set< AZ::EntityId > m_otherLayersToSave
 
bool m_mustSaveLevelWhenLayerSaves = true
 
bool m_overwriteCheck = false
 

Detailed Description

This editor component marks an entity as a layer entity. Layer entities allow the level to be split into multiple files, so content creators can work on the same level at the same time, without conflict.

Member Function Documentation

◆ Activate()

void AzToolsFramework::Layers::EditorLayerComponent::Activate ( )
overrideprotectedvirtual

Gets the transform component and selection component of the entity that the component belongs to, if the entity has them. Overrides AZ::Component::Activate().

Important: Components derived from EditorComponentBase must call the Activate() function of the base class.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.

◆ CanAttemptToRecoverLayerAndGetLayerInfo()

static bool AzToolsFramework::Layers::EditorLayerComponent::CanAttemptToRecoverLayerAndGetLayerInfo ( const AZStd::string &  fullFilePath,
AZStd::string &  newLayerName,
AZ::EntityId &  layerParentId 
)
staticprotected

Verifies that the passed in layer path is safe to begin a recovery attempt. If so, also populates necessary info to recover this layer. Also retrieves the name of the layer to use when creating the entity. Checks if the ancestry of the layer is available. If not, prompts the user if they want it created, or if they want to bail out of the operation.

Parameters
fullFilePathThe full path to the layer file.
newLayerNameAn output paramater that will be populated with the entity name for this layer.
layerParentIdAn output parameter that will be populated with the ID of the parent of the layer, if it has one.

◆ CreateLayerAssetContextMenu()

static void AzToolsFramework::Layers::EditorLayerComponent::CreateLayerAssetContextMenu ( QMenu *  menu,
const AZStd::string &  fullFilePath,
QString  levelPath 
)
static

Creates the right click context menu for layers in the asset browser.

Parameters
menuThe menu to parent this to.
fullFilePathThe full file path of the slice.
levelPathThe path to the level file.

◆ CreateLayerEntity()

static AZ::EntityId AzToolsFramework::Layers::EditorLayerComponent::CreateLayerEntity ( const AZStd::string &  name,
const AZ::Color &  layerColor,
const LayerProperties::SaveFormat &  saveAsBinary = LayerProperties::SaveFormat::Xml,
const AZ::EntityId &  optionalEntityId = AZ::EntityId() 
)
static

Creates a layer entity with the given name, and returns the EntityId of the layer entity.

Parameters
nameName to use for the new layer.
layerColorcolor of the layer in editor.
saveAsBinarysave format for layer, xml or binary.
optionalEntityIdoptional param to specify entity ID for created layer.
Returns
a valid entity ID on successful entity creation

◆ CreateLayerEntityFromName()

static AZ::EntityId AzToolsFramework::Layers::EditorLayerComponent::CreateLayerEntityFromName ( const AZStd::string &  name)
static

Helper function for script reflection friendly override. Creates a layer entity with the given name, default color and xml save format. Returns the EntityId of the layer.

Parameters
nameName to use for the new layer
Returns
a valid entity ID on successful entity creation

◆ CreateMissingLayerAncestors()

static AZ::EntityId AzToolsFramework::Layers::EditorLayerComponent::CreateMissingLayerAncestors ( const AZStd::string &  nearestLayerAcenstorName)
staticprotected

Creates a layer entity with the given ancestor name. This is not parsed for deeper ancestry, if you give this "Grandparent.Parent" and have an entity in your scene already named "Grandparent", this won't create "Parent" as a child of "Grandparent".

Parameters
nearestLayerAncestorNamethe full ancestor name.
Returns
The entity ID fo the missing ancestor.

◆ Deactivate()

void AzToolsFramework::Layers::EditorLayerComponent::Deactivate ( )
overrideprotectedvirtual

Sets the component's pointers to the transform component and selection component to null. Overrides AZ::Component::Deactivate().

Important: Components derived from EditorComponentBase must call the Deactivate() function of the base class.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.

◆ Init()

void AzToolsFramework::Layers::EditorLayerComponent::Init ( )
overrideprotectedvirtual

Initializes the component's resources. Overrides AZ::Component::Init().

Important: Components derived from EditorComponentBase must call the Init() function of the base class.

(Optional) You can override this function to initialize resources that the component needs.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.

◆ IsLayerDataSafeToRecover()

static LayerResult AzToolsFramework::Layers::EditorLayerComponent::IsLayerDataSafeToRecover ( const AZStd::shared_ptr< Layers::EditorLayer loadedLayer,
AZ::SliceComponent &  rootSlice 
)
staticprotected

Returns true if the passed in layer is safe to spawn in the scene, false if not. This checks for duplicate entity IDs.

Parameters
loadedLayerThe layer to validate.
rootSliceThe root slice for the level.
Returns
A success if the layer is safe to recover, otherwise an error with a message if not.

◆ RecoverEditorLayer()

static LayerResult AzToolsFramework::Layers::EditorLayerComponent::RecoverEditorLayer ( const AZStd::shared_ptr< Layers::EditorLayer editorLayer,
const AZStd::string &  newLayerName,
const AZ::EntityId &  layerParentId 
)
static

Attempts to recover the passed in EditorLayer object. Most call sites should use the RecoverLayer that takes in a path to the layer file.

Parameters
editorLayerThe layer object to recover.
newLayerNameThe name to give the layer entity when it's recovered.
layerParentIdThe parent for the new layer. Passed in the invalid entity ID for loose layers with no parents.
Returns
A success if the layer was recovered, an error if it was not.

◆ RecoverLayer()

static void AzToolsFramework::Layers::EditorLayerComponent::RecoverLayer ( const AZStd::string &  fullFilePath)
static

Attempts to recover the passed in layer file. This is used when content creators accidentally step on each other's toes, and a layer entity gets deleted in a scene.

Parameters
fullFilePathThe full path to the layer to attempt to recover.

◆ UpdateListOfDiscoveredEntityIds()

static LayerResult AzToolsFramework::Layers::EditorLayerComponent::UpdateListOfDiscoveredEntityIds ( AZStd::unordered_set< AZ::EntityId > &  discoveredIds,
const AZ::EntityId &  newEntity 
)
staticprotected

Checks if the given entity ID was already discovered. Updates the discovery list with the passed in ID. Reports an error if the entity ID was already found. Returns true if it was, false if not. This is used when recovering layers, to search for potential entity ID collisions, and cancel the recovery if there is a collision.

Parameters
discoveredIdsA list of entity already found.
newEntityThe entity to update the list with, and report an error if it was already found.
Returns
A success if the entity ID is safe to recover, a failure if not.

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