Open 3D Engine AzFramework 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.
AzFramework::SpawnableEntitiesContainer Class Reference

#include <SpawnableEntitiesContainer.h>

Public Types

enum class  CheckIfSpawnableIsLoaded : bool { Yes , No }
 
using AlertCallback = AZStd::function< void(uint32_t generation)>
 

Public Member Functions

 SpawnableEntitiesContainer ()=default
 Constructs a new spawnables entity container that has not been connected.
 
 SpawnableEntitiesContainer (AZ::Data::Asset< Spawnable > spawnable)
 
bool IsSet () const
 Returns true if the container has a spawnable set and can process requests, otherwise returns falls.
 
uint32_t GetCurrentGeneration () const
 
void SpawnAllEntities (SpawnAllEntitiesOptionalArgs optionalArgs={})
 
void SpawnEntities (AZStd::vector< uint32_t > entityIndices)
 
void DespawnAllEntities ()
 Puts in a request to despawn all previous spawned entities.
 
void Reset (AZ::Data::Asset< Spawnable > spawnable)
 
void Clear ()
 
void Alert (AlertCallback callback, CheckIfSpawnableIsLoaded spawnableCheck=CheckIfSpawnableIsLoaded::No)
 

Detailed Description

A utility class to simplify the life-cycle management of entities created from a Spawnable. This class will keep track of the created entities and take appropriate action when the spawnable changes. Calls to this container should be done from the same thread, but multiple threads can create their own container for the same Spawnable. This container is for simple use cases. Complex situations can directly call the SpawnablesEntitesInterface and use the SpawnableMonitor if needed.

Constructor & Destructor Documentation

◆ SpawnableEntitiesContainer()

AzFramework::SpawnableEntitiesContainer::SpawnableEntitiesContainer ( AZ::Data::Asset< Spawnable spawnable)
explicit

Constructs a new spawnables entity container that connects to the provided spawnable.

Parameters
spawnableThe Spawnable that will be monitored and used as a template to create entities from.

Member Function Documentation

◆ Alert()

void AzFramework::SpawnableEntitiesContainer::Alert ( AlertCallback  callback,
CheckIfSpawnableIsLoaded  spawnableCheck = CheckIfSpawnableIsLoaded::No 
)

Adds an alert that will trigger the provided callback once all previous calls to change the container have completed. This includes calls to (de)spawn entities, reset the container or clear. The callback can be called from threads other than the calling thread including the main thread. Note that because the alert is queued it can still be called after the container has been deleted or can be called for a previously assigned spawnable. In the latter case check if the current generation matches the generation provided with the callback.

Parameters
callbackThe function called when the alert triggers. This can be called from a different thread than the one that the one that made the call to Alert.
checkSpawnableIsLoadedIf true the alert will also block until the spawnable has been loaded. If false then it will be called after all previous calls have completed, but the spawnable may not be loaded at that point.

◆ Clear()

void AzFramework::SpawnableEntitiesContainer::Clear ( )

Puts in a request to disconnect from the connected spawnable. This will immediately clear the internal state to allow for a Reset, but the release of the spawnable itself will be delayed. As a result any pending and in-flight requests will complete first. If a callback has been set it will be called one more time after this function returns, possibly outliving the lifetime of the container.

◆ GetCurrentGeneration()

uint32_t AzFramework::SpawnableEntitiesContainer::GetCurrentGeneration ( ) const

Returns a number that identifies the current generation of the container with. The completion callback can still receive calls from older generations as processing completes on those. The returned value can be used to help calls tell older versions apart from newer ones.

◆ Reset()

void AzFramework::SpawnableEntitiesContainer::Reset ( AZ::Data::Asset< Spawnable spawnable)

Resets the spawnable and completion callback. This call will clear first if a spawnable has already been set. See Clear for more details.

Parameters
spawnableThe Spawnable that will be monitored and used as a template to create entities from.

◆ SpawnAllEntities()

void AzFramework::SpawnableEntitiesContainer::SpawnAllEntities ( SpawnAllEntitiesOptionalArgs  optionalArgs = {})

Puts in a request to spawn entities using all entities in the provided spawnable as a template.

Parameters
optionalArgsoptional arguments for spawning

◆ SpawnEntities()

void AzFramework::SpawnableEntitiesContainer::SpawnEntities ( AZStd::vector< uint32_t >  entityIndices)

Puts in a request to spawn entities using the entities found in the spawnable at the provided indices as a template.

Parameters
entityIndicesA list of indices to the entities in the spawnable.

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