Menu
Lumberyard
C++ API Reference (Version 1.10)

AZ::BehaviorContext::EBusReflection< Bus > Struct Template Reference

This structure is built up while you call EBusReflection functions to reflect an EBus's information to the behavior context. More...

Inherits AZ::Internal::GenericAttributes< EBusReflection< Bus > >.

Public Member Functions

template<class Function , class = AZStd::enable_if_t<AZStd::function_traits<Function>::num_args != 0>>
EBusReflectionEvent (const char *name, Function handler, AZStd::array< AZStd::string, AZStd::function_traits< Function >::num_args > argNames)
 Reflects a request bus event with arguments. More...
 
template<class Function >
EBusReflectionEvent (const char *name, Function handler)
 Reflects a request bus event. More...
 
template<typename HandlerCreator , typename HandlerDestructor >
EBusReflectionHandler (HandlerCreator creator, HandlerDestructor destructor)
 Specifies a handler class that receives and forwards notification events to behavior context handlers in cases where you want to provide a custom creator and destructor for the handler. More...
 
template<class H >
EBusReflectionHandler ()
 Specifies a handler class that receives and forwards notification events to handlers created by the behavior context. More...
 
EBusReflectionVirtualProperty (const char *name, const char *getterEvent, const char *setterEvent)
 Enables you to specify the getter and setter EBus events for a value. More...
 

Public Attributes

BehaviorEBus * m_ebus
 A pointer to all the information that describes a reflected EBus. More...
 

Detailed Description

template<typename Bus>
struct AZ::BehaviorContext::EBusReflection< Bus >

This structure is built up while you call EBusReflection functions to reflect an EBus's information to the behavior context.

The end result of this reflection is a BehaviorEBus instance that is stored in the behavior context.

Member Function Documentation

◆ Event() [1/2]

template<typename Bus >
template<class Function , class = AZStd::enable_if_t<AZStd::function_traits<Function>::num_args != 0>>
EBusReflection* AZ::BehaviorContext::EBusReflection< Bus >::Event ( const char *  name,
Function  handler,
AZStd::array< AZStd::string, AZStd::function_traits< Function >::num_args >  argNames 
)

Reflects a request bus event with arguments.

The following is an example of how to call this function.

behaviorContext->EBus<MyComponentRequestBus>("MyComponentRequestBus")
->Event("GetValue", &MyComponentRequestBus::Events::GetValue, {"MyArg1","MyArg2"});
Parameters
nameThe name of the event.
handlerThe event handler that handles the request.
argNamesAn array of argument names for the handler.
Returns
A pointer to the structure that contains reflection information for the EBus that is currently being reflected to the behavior context.

◆ Event() [2/2]

template<typename Bus >
template<class Function >
EBusReflection* AZ::BehaviorContext::EBusReflection< Bus >::Event ( const char *  name,
Function  handler 
)

Reflects a request bus event.

The following is an example of how to call this function.

behaviorContext->EBus<MyComponentRequestBus>("MyComponentRequestBus")
->Event("GetValue", &MyComponentRequestBus::Events::GetValue);
Parameters
nameThe name of the event.
handlerThe event handler that handles the request.
Returns
A pointer to the structure that contains reflection information for the EBus that is currently being reflected to the behavior context.

◆ Handler() [1/2]

template<typename Bus >
template<typename HandlerCreator , typename HandlerDestructor >
EBusReflection* AZ::BehaviorContext::EBusReflection< Bus >::Handler ( HandlerCreator  creator,
HandlerDestructor  destructor 
)

Specifies a handler class that receives and forwards notification events to behavior context handlers in cases where you want to provide a custom creator and destructor for the handler.

Note
This version is rarely used. In most cases, use the Handler() function.

In this version of Handler(), you can provide a custom function to create and destroy the handler. You typically use this in cases where aznew and azdestroy are not applicable or you have a better pooling schema than Lumberyard's memory allocators.

Parameters
creatorA function that creates a handler. Must return a BehaviorEBusHandler* object.
destructorA function that destroys a handler. Must have an argument that can handle BehaviorEBusHandler.
Returns
A pointer to the structure that contains reflection information for the EBus that is currently being reflected to the behavior context.

◆ Handler() [2/2]

template<typename Bus >
template<class H >
EBusReflection* AZ::BehaviorContext::EBusReflection< Bus >::Handler ( )

Specifies a handler class that receives and forwards notification events to handlers created by the behavior context.

You must specify the class as a template argument.

The following is an example of how to call this function.

behaviorContext->EBus<MyComponentNotificationBus>("MyComponentNotificationBus")
->Handler<MyComponentNotificationBusHandler>();

The following is an example of the handler class that you write to forward notification events to handlers that are created by the behavior context. The AZ_EBUS_BEHAVIOR_BINDER helper macro sets up the class. You follow the macro with handler functions that use a Call() or CallResult() function to forward the events to handlers that are created by the behavior context.

class MyComponentNotificationBusHandler : public MyComponentNotificationBus::Handler, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(MyComponentNotificationBusHandler,
"{UUID_OF_THE_HANDLER_CLASS}",
AZ::SystemAllocator,
OnEvent1,
OnEvent2);
// Handler for an event with no argument or return value.
void OnEvent1() override
{
Call(FN_OnEvent1); // Forward the event to the behavior context handler.
}
// Handler for an event with an input argument and a return value.
int OnEvent2(int value) override
{
int result = 0; // Set the default value for the result.
CallResult(result, FN_OnEvent2, value); // Forward the event to the behavior context handler.
return result; // Return the result as with any EBus event.
}
// Handler for an event with a container as an input argument and a return value.
int OnEvent3(const AZStd::vector<int>& values) override
{
int result = 0; // Set the default value for the result.
CallResult(result, FN_OnEvent3, values); // Forward the event to the behavior context handler.
return result; // Return the result as with any EBus event.
}
};
Template Parameters
HThe handler class.
Returns
A pointer to the structure that contains reflection information for the EBus that is currently being reflected to the behavior context.

◆ VirtualProperty()

template<typename Bus >
EBusReflection* AZ::BehaviorContext::EBusReflection< Bus >::VirtualProperty ( const char *  name,
const char *  getterEvent,
const char *  setterEvent 
)

Enables you to specify the getter and setter EBus events for a value.

Request buses often have EBus events that represent a getter and a setter for a value. To enable tools to take advantage of these, you can reflect a virtual property to indicate which event is the getter and which is the setter.

Make sure that you call this function after you have reflected the getter and setter events because it will report an error if it can't find the events.

The following is an example of how to call this function.

behaviorContext->EBus<MyComponentRequestBus>("MyComponentRequestBus")
->Event("GetValue", &MyComponentRequestBus::Events::GetValue)
->Event("SetValue", &MyComponentRequestBus::Events::SetValue)
->VirtualProperty("MyValue", "GetValue", "SetValue");
Parameters
nameA name for the virtual property.
getterEventThe name of the getter event. This event must have been reflected previously. It must also have no arguments and must return a result.
setterEventThe name of the setter event. This event must have been reflected previously. It must have one argument only and not return a result.
Returns
A pointer to the structure that contains reflection information for the EBus that is currently being reflected to the behavior context.

Member Data Documentation

◆ m_ebus

template<typename Bus >
BehaviorEBus* AZ::BehaviorContext::EBusReflection< Bus >::m_ebus

A pointer to all the information that describes a reflected EBus.


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