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 | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
AZ::ScriptSystemComponent Class Reference

#include <ScriptSystemComponent.h>

Inherits AZ::Component, Handler, Handler, AZ::Data::AssetHandler, Handler, and 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 OnAssetPreReload (Data::Asset< Data::AssetData > asset) override
 Called before an asset reload has started.
 
ContextContainerGetContextContainer (ScriptContextId id)
 
int DefaultRequireHook (lua_State *l, ScriptContext *context, const char *module)
 
int InMemoryRequireHook (lua_State *l, ScriptContext *context, const char *module)
 
void OnAssetReloaded (Data::Asset< Data::AssetData > asset) override
 
- 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 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
 
bool m_isReloadQueued = false
 
AZStd::unordered_set< Data::AssetIdm_queuedReloads
 
- 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  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_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
 
- Public Member Functions inherited from AZ::Data::AssetHandler
 AZ_RTTI (AssetHandler, "{58BD1FDF-E668-42E5-9091-16F46022F551}")
 
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 bool CanHandleAsset (const AssetId &) const
 
virtual void GetCustomAssetStreamInfoForLoad ([[maybe_unused]] 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 ([[maybe_unused]] AssetType type, AZStd::chrono::milliseconds &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.

◆ 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

◆ 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;


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