ezEngine  Release 25.03
ezGameStateBase Class Referenceabstract

ezGameStateBase is the base class for all game states. Game states are used to implement custom high level game logic. More...

#include <GameStateBase.h>

Inheritance diagram for ezGameStateBase:

Public Member Functions

virtual void OnActivation (ezWorld *pWorld, ezStringView sStartPosition, const ezTransform &startPositionOffset)=0
 A game state gets activated through this function. More...
 
virtual void OnDeactivation ()=0
 Called when the game state is being shut down. More...
 
virtual void ProcessInput ()
 Called once per game update, early in the frame. Should handle input updates here.
 
virtual void BeforeWorldUpdate ()
 Called once each frame before the worlds are updated.
 
virtual void AfterWorldUpdate ()
 Called once each frame after the worlds have been updated.
 
virtual void ConfigureMainCamera ()
 Called once each frame to configure the main camera position and rotation. More...
 
virtual void AddMainViewsToRender ()=0
 Has to call ezRenderLoop::AddMainView for all views that need to be rendered. More...
 
virtual void RequestQuit ()=0
 Call this to signal that a game state requested the application to quit. More...
 
virtual bool WasQuitRequested () const =0
 Returns whether the game state wants to quit the application.
 
virtual bool IsFallbackGameState () const
 Should be overridden by game states that are only meant as a fallback solution. More...
 
- Public Member Functions inherited from ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Additional Inherited Members

- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 

Detailed Description

ezGameStateBase is the base class for all game states. Game states are used to implement custom high level game logic.

See the online documentation for details: https://ezengine.net/pages/docs/runtime/application/game-state.html

Note that you would typically derive custom game states from ezGameState, not ezGameStateBase, since the former provides much more functionality out of the box.

Member Function Documentation

◆ AddMainViewsToRender()

virtual void ezGameStateBase::AddMainViewsToRender ( )
pure virtual

Has to call ezRenderLoop::AddMainView for all views that need to be rendered.

This will be called every frame by the editor, to ensure that only the relevant views are rendered, but during stand-alone game execution this may never be called.

Implemented in ezGameState.

◆ ConfigureMainCamera()

virtual void ezGameStateBase::ConfigureMainCamera ( )
inlinevirtual

Called once each frame to configure the main camera position and rotation.

Note that ezCameraComponent may already apply set general options like field-of-view, so don't override these values, if you want to use that component. The default ezGameState implementation searches for an ezCameraComponent in the world that is set to "Main View" and uses it's transform for the main camera.

Reimplemented in ezGameState, and ezFallbackGameState.

◆ IsFallbackGameState()

virtual bool ezGameStateBase::IsFallbackGameState ( ) const
inlinevirtual

Should be overridden by game states that are only meant as a fallback solution.

See the implementation for ezFallbackGameState for details.

Reimplemented in ezFallbackGameState.

◆ OnActivation()

virtual void ezGameStateBase::OnActivation ( ezWorld pWorld,
ezStringView  sStartPosition,
const ezTransform startPositionOffset 
)
pure virtual

A game state gets activated through this function.

Parameters
pWorldThe game state is supposed to operate on the given world. In a stand-alone application pWorld will always be nullptr and the game state is expected to create worlds itself. When run inside the editor, pWorld will already exist and the game state is expected to work on it.
sStartPositionAn optional string to identify where the player should spawn. This may, for instance, be the unique name of an object. It is up to the game state how the string is used, if at all.
pStartPositionAn optional transform for the 'player object' to start at. Usually nullptr, but may be set by the editor to relocate or create the player object at the given destination.

Implemented in ezGameState, and ezFallbackGameState.

◆ OnDeactivation()

virtual void ezGameStateBase::OnDeactivation ( )
pure virtual

Called when the game state is being shut down.

Override this to clean up or save data to disk.

Implemented in ezGameState.

◆ RequestQuit()

virtual void ezGameStateBase::RequestQuit ( )
pure virtual

Call this to signal that a game state requested the application to quit.

ezGameApplication will shut down when this happens. ezEditor will stop play-the-game mode when it is running.

Implemented in ezGameState.


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