Open 3D Engine AzCore 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.
AZ::ScriptSystemComponent Class Reference

#include <ScriptSystemComponent.h>

Inherits AZ::Component, ScriptSystemRequestBus::Handler, SystemTickBus::Handler, AZ::Data::AssetHandler, AssetTypeInfoBus::Handler, and Data::AssetBus::MultiHandler.

Classes

struct  ContextContainer
 
struct  LoadedScriptInfo
 

Protected Member Functions

void Activate () override
 
void Deactivate () override
 
ScriptContextAddContext (ScriptContext *context, int garbageCollectorStep=-1) override
 
ScriptContextAddContextWithId (ScriptContextId id) override
 Add a context with an ID, the system will handle the ownership of the context (delete it when removed and the system deactivates)
 
bool RemoveContext (ScriptContext *context) override
 Removes a script context (without calling delete on it)
 
bool RemoveContextWithId (ScriptContextId id) override
 Removes and deletes a script context.
 
ScriptContextGetContext (ScriptContextId id=ScriptContextIds::DefaultScriptContextId) override
 Returns the script context that has been registered with the app, if there is one.
 
void GarbageCollect () override
 
void GarbageCollectStep (int numberOfSteps) override
 
bool Load (const Data::Asset< ScriptAsset > &asset, const char *mode, ScriptContextId id) override
 
ScriptLoadResult LoadAndGetNativeContext (const Data::Asset< ScriptAsset > &asset, const char *mode, ScriptContextId id) override
 
void ClearAssetReferences (Data::AssetId assetBaseId) override
 
void RestoreDefaultRequireHook (ScriptContextId id=ScriptContextIds::DefaultScriptContextId) override
 
void UseInMemoryRequireHook (const InMemoryScriptModules &modules, ScriptContextId id=ScriptContextIds::DefaultScriptContextId) override
 
void OnSystemTick () override
 
Data::AssetPtr CreateAsset (const Data::AssetId &id, const Data::AssetType &type) override
 Called by the asset database to create a new asset. No loading should during this call.
 
Data::AssetHandler::LoadResult LoadAssetData (const Data::Asset< Data::AssetData > &asset, AZStd::shared_ptr< Data::AssetDataStream > stream, const AZ::Data::AssetFilterCB &assetLoadFilterCB) override
 Called by the asset database to perform actual asset load.
 
void DestroyAsset (Data::AssetPtr ptr) override
 Called by the asset database when an asset should be deleted.
 
void GetHandledAssetTypes (AZStd::vector< Data::AssetType > &assetTypes) override
 Return handled asset types.
 
AZ::Data::AssetType GetAssetType () const override
 
const char * GetAssetTypeDisplayName () const override
 
const char * GetGroup () const override
 
const char * GetBrowserIcon () const override
 
AZ::Uuid GetComponentTypeId () const override
 
void GetAssetTypeExtensions (AZStd::vector< AZStd::string > &extensions) override
 
bool CanCreateComponent (const AZ::Data::AssetId &assetId) const override
 
void OnAssetReloaded (Data::Asset< Data::AssetData > asset) override
 Called before an asset reload has started.
 
void LoadReadyAsset (Data::Asset< Data::AssetData > asset)
 
ContextContainerGetContextContainer (ScriptContextId id)
 
int DefaultRequireHook (lua_State *l, ScriptContext *context, const char *module)
 
int InMemoryRequireHook (lua_State *l, ScriptContext *context, const char *module)
 
- Protected Member Functions inherited from AZ::Component
virtual void Init ()
 
virtual void Activate ()=0
 
virtual void Deactivate ()=0
 
virtual bool ReadInConfig (const ComponentConfig *baseConfig)
 
virtual bool WriteOutConfig (ComponentConfig *outBaseConfig) const
 
virtual void SetEntity (Entity *entity)
 
virtual void OnAfterEntitySet ()
 Function to call after setting the entity in this component.
 
virtual LoadResult LoadAssetData (const Asset< AssetData > &asset, AZStd::shared_ptr< AssetDataStream > stream, const AZ::Data::AssetFilterCB &assetLoadFilterCB)=0
 

Static Protected Member Functions

static void GetProvidedServices (ComponentDescriptor::DependencyArrayType &provided)
 ComponentDescriptor::GetProvidedServices
 
static void GetIncompatibleServices (ComponentDescriptor::DependencyArrayType &incompatible)
 ComponentDescriptor::GetIncompatibleServices
 
static void GetDependentServices (ComponentDescriptor::DependencyArrayType &dependent)
 ComponentDescriptor::GetDependentServices
 
static void Reflect (ReflectContext *reflection)
 \red ComponentDescriptor::Reflect
 

Protected Attributes

int m_defaultGarbageCollectorSteps
 
InMemoryScriptModules m_inMemoryModules
 
AZStd::vector< ContextContainerm_contexts
 
- 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.
 

Additional Inherited Members

- Public Types inherited from AZ::Data::AssetHandler
enum class  LoadResult : u8 { Error , MoreDataRequired , LoadComplete }
 Result from LoadAssetData - it either finished loading, didn't finish and is waiting for more data, or had an error.
 
- Public Member Functions inherited from AZ::Component
 AZ_TYPE_INFO_WITH_NAME_DECL (Component)
 
 AZ_RTTI_NO_TYPE_INFO_DECL ()
 
 Component ()
 
virtual ~Component ()
 
EntityGetEntity () const
 
EntityId GetEntityId () const
 
NamedEntityId GetNamedEntityId () const
 
ComponentId GetId () const
 
virtual TypeId GetUnderlyingComponentType () const
 
void SetId (const ComponentId &id)
 
virtual void SetSerializedIdentifier (AZStd::string serializedIdentifer)
 
virtual AZStd::string GetSerializedIdentifier () const
 
virtual ComponentValidationResult ValidateComponentRequirements (const ImmutableEntityVector &, const AZStd::unordered_set< AZ::Crc32 > &) const
 
bool SetConfiguration (const AZ::ComponentConfig &config)
 
bool GetConfiguration (AZ::ComponentConfig &outConfig) const
 
- Public Member Functions inherited from AZ::Data::AssetHandler
 AZ_RTTI (AssetHandler, "{58BD1FDF-E668-42E5-9091-16F46022F551}")
 
virtual AssetPtr CreateAsset (const AssetId &id, const AssetType &type)=0
 
LoadResult LoadAssetDataFromStream (const Asset< AssetData > &asset, AZStd::shared_ptr< AssetDataStream > stream, const AZ::Data::AssetFilterCB &assetLoadFilterCB)
 
virtual bool SaveAssetData (const Asset< AssetData > &asset, IO::GenericStream *stream)
 
virtual AZ::Data::AssetId AssetMissingInCatalog (const Asset< AssetData > &)
 
virtual void InitAsset (const Asset< AssetData > &asset, bool loadStageSucceeded, bool isReload)
 
virtual void DestroyAsset (AssetPtr ptr)=0
 
virtual void GetHandledAssetTypes (AZStd::vector< AssetType > &assetTypes)=0
 
virtual bool CanHandleAsset (const AssetId &) const
 
virtual void GetCustomAssetStreamInfoForLoad (AssetStreamInfo &streamInfo)
 
virtual IO::IStreamerTypes::RequestMemoryAllocatorGetAssetBufferAllocator ()
 Asset Handlers have the ability to provide custom asset buffer allocators for any non-standard allocation needs.
 
virtual void GetDefaultAssetLoadPriority (AssetType type, IO::IStreamerTypes::Deadline &defaultDeadline, AZ::IO::IStreamerTypes::Priority &defaultPriority) const
 

Detailed Description

Script system component. It will manage all script contexts and provide script asset handler. You must have one of this components on you system entity (or any) to enable script support using the Hex facility. You are NOT REQUIRED to use it. You can use ScriptContext directly and manage it anyway you like, but you will be provide ScriptAsset management too.

Member Function Documentation

◆ Activate()

void AZ::ScriptSystemComponent::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.

◆ CreateAsset()

Data::AssetPtr AZ::ScriptSystemComponent::CreateAsset ( const Data::AssetId id,
const Data::AssetType type 
)
overrideprotectedvirtual

Called by the asset database to create a new asset. No loading should during this call.

Implements AZ::Data::AssetHandler.

◆ Deactivate()

void AZ::ScriptSystemComponent::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.

◆ DefaultRequireHook()

int AZ::ScriptSystemComponent::DefaultRequireHook ( lua_State *  l,
ScriptContext context,
const char *  module 
)
protected

Default require hook installed on new contexts, looks for a compiled asset in the asset system corresponding to the module path and name. If found, loads the module if not done previously, leaves it on the stack, otherwise pushes string error. Additionally connects to the script id to reload the script if the script changes

◆ DestroyAsset()

void AZ::ScriptSystemComponent::DestroyAsset ( Data::AssetPtr  ptr)
overrideprotectedvirtual

Called by the asset database when an asset should be deleted.

Implements AZ::Data::AssetHandler.

◆ GetHandledAssetTypes()

void AZ::ScriptSystemComponent::GetHandledAssetTypes ( AZStd::vector< Data::AssetType > &  assetTypes)
overrideprotectedvirtual

Return handled asset types.

Implements AZ::Data::AssetHandler.

◆ InMemoryRequireHook()

int AZ::ScriptSystemComponent::InMemoryRequireHook ( lua_State *  l,
ScriptContext context,
const char *  module 
)
protected

Custom require hook looks for a compiled asset by name of module that exists in memory only, specifically in m_inMemoryModules. Leaves the module or an error string on the stack. These modules are unloaded and deleted when RestoreDefaultRequireHook is called;

◆ LoadAssetData()

Data::AssetHandler::LoadResult AZ::ScriptSystemComponent::LoadAssetData ( const Data::Asset< Data::AssetData > &  asset,
AZStd::shared_ptr< Data::AssetDataStream stream,
const AZ::Data::AssetFilterCB assetLoadFilterCB 
)
overrideprotectedvirtual

Called by the asset database to perform actual asset load.

Implements AZ::Data::AssetHandler.


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