Open 3D Engine AzCore API Reference  22.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Classes | Static Public Member Functions | List of all members
AZ::Interface< T > Class Template Referencefinal

#include <Interface.h>

Inherited by AZ::Internal::IdHandler< Interface, Traits, ContainerType >, AZ::Internal::MultiHandler< Interface, Traits, ContainerType >, and AZ::Internal::NonIdHandler< Interface, Traits, ContainerType >.


class  Registrar

Static Public Member Functions

static void Register (T *type)
static void Unregister (T *type)
static T * Get ()

Detailed Description

template<typename T>
class AZ::Interface< T >

Interface class for accessing registered singletons across module boundaries. The raw interface pointer is handed to you; the assumption is that the registered system will outlive cached references. A system must register itself with the interface at initialization time by calling Register(); and unregister at shutdown by calling Unregister(). The provided Registrar class will do this for you automatically. Registration will only succeed after the AZ::Environment has been attached and is ready.

Example Usage:

class ISystem
virtual ~ISystem();
virtual void DoSomething() = 0;
class System
: public AZ::Interface<ISystem>::Registrar
void DoSomething() override;
// In client code.
// Check that the pointer is valid before use.
if (ISystem* system = AZ::Interface<ISystem>::Get())

Member Function Documentation

◆ Get()

template<typename T >
T * AZ::Interface< T >::Get

Returns the registered interface pointer, if it exists. This method is thread-safe in that you can call Get from multiple threads. Likewise, calls to Register / Unregister are guarded, but it is highly recommended to restrict Register / Unregister to a dedicated serial code path.

◆ Register()

template<typename T >
void AZ::Interface< T >::Register ( T *  type)

Registers an instance pointer to the interface. Only one instance is allowed to register at a time.

◆ Unregister()

template<typename T >
void AZ::Interface< T >::Unregister ( T *  type)

Unregisters from the interface. An unregister must occur in the same module as the original Register call; the pointer must match the original call to Register.

The documentation for this class was generated from the following file:
Definition: Interface.h:56