Menu
Lumberyard
C++ API Reference (Version 1.10)

BehaviorContext.h File Reference

Header file for the behavior context, which contains information about classes, methods, properties, enums, constants, and EBuses to enable Lumberyard to interact with objects during run time. More...

Classes

class  AZ::BehaviorClass
 Contains all the information about a class that is reflected to the behavior context. More...
 
class  AZ::BehaviorContextEvents
 Interface for the AZ::BehaviorContextBus, which is the EBus that dispatches behavior context events. More...
 
class  AZ::BehaviorContext
 BehaviorContext is an object that contains information about classes, methods, properties, constants, enums, and EBuses to enable Lumberyard to interact with objects during run time. More...
 
struct  AZ::BehaviorContext::ClassReflection< C >
 This structure is built up while you call ClassReflection functions to reflect a class's information to the behavior context. More...
 
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. More...
 

Namespaces

 AZ
 

Macros

#define BehaviorValueGetter(valueAddress)
 Generates a function that gets a value. More...
 
#define BehaviorValueSetter(valueAddress)
 Generates a function that sets a value. More...
 
#define BehaviorValueProperty(valueAddress)
 Creates getter and setter functions for a value. More...
 
#define BehaviorConstant(value)
 Generates a function that gets a constant. More...
 
#define AZ_EBUS_BEHAVIOR_BINDER(_Handler, _Uuid, _Allocator, ...)
 Macro that helps you write the handler class that forwards EBus notification events to handlers that are created by the behavior context. More...
 

Typedefs

using AZ::BehaviorContextBus = AZ::EBus< BehaviorContextEvents >
 The EBus for behavior context notification events. More...
 

Detailed Description

Header file for the behavior context, which contains information about classes, methods, properties, enums, constants, and EBuses to enable Lumberyard to interact with objects during run time.

Macro Definition Documentation

◆ AZ_EBUS_BEHAVIOR_BINDER

#define AZ_EBUS_BEHAVIOR_BINDER (   _Handler,
  _Uuid,
  _Allocator,
  ... 
)

Macro that helps you write the handler class that forwards EBus notification events to handlers that are created by the behavior context.

This macro sets up the handler class, including adding run-time type information and functions to connect and disconnect from the bus.

You add this macro to the top of the handler class and then write handler functions. These handler functions use a Call() or CallResult() function to forward the events to handlers that are created by the behavior context.

You don't need to use this macro to write a handler class, but we highly recommend it because it helps you write less code.

The following example shows how to use this macro.

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.
}
};
Parameters
_HandlerThe name of the handler class.
_UuidA unique ID for the handler class.
_AllocatorThe memory allocator to use. This is typically AZ::SystemAllocator.
...The event names.

◆ BehaviorConstant

#define BehaviorConstant (   value)

Generates a function that gets a constant.

You must pass a constant or a literal value to this macro.

Parameters
valueA constant or a literal value.

Examples:

behaviorContext->Constant("constName", BehaviorConstant(constValue));
behaviorContext->Constant("anotherConstName", BehaviorConstant(5));

◆ BehaviorValueGetter

#define BehaviorValueGetter (   valueAddress)

Generates a function that gets a value.

The value must be passed by pointer.

Parameters
valueAddressA pointer to a global value or a reference to a member variable of a class.

Examples:

behaviorContext->Property("globalData", BehaviorValueGetter(&g_globalDataValue), nullptr);
behaviorContext->Property("classMemberData", BehaviorValueGetter(&MyClass::memberDataValue), nullptr);

◆ BehaviorValueProperty

#define BehaviorValueProperty (   valueAddress)

Creates getter and setter functions for a value.

The value must be passed by pointer.

Parameters
valueAddressA pointer to a global value or a reference to a member variable of a class.

Example:

behaviorContext->Property("globalData", BehaviorValueProperty(&g_globalDataValue));

◆ BehaviorValueSetter

#define BehaviorValueSetter (   valueAddress)

Generates a function that sets a value.

The value must be passed by pointer.

Parameters
valueAddressA pointer to a global value or a reference to a member variable of a class.

Examples:

behaviorContext->Property("globalData", nullptr, BehaviorValueSetter(&g_globalDataValue));
behaviorContext->Property("classMemberData", nullptr, BehaviorValueSetter(&MyClass::memberDataValue));