Custom game states

RED4ext offers the possibility to attach custom game states to the game. These can be used to initialize or do some things before or after the game system are available, such as scripting system.

State functions

Every state has the following functions:

OnEnter

Called immediately after the state is activated. This function is called once by the game, so be careful what you want to do here. A good example is to initalize some memory that is needed later.

Return

  • The return value is not taken in consideration. It is recommended to always return true for future proofing.

OnUpdate

Called every frame. This function can contain more complex code.

Return

  • false - if the state did not finish executing.

  • true - if the state finished executing.

If the game / custom state returns true it will not be called next frame. For example:

  • InitializationState::OnUpdate - returns false

  • CustomInitState::OnUpdate - returns true

Next frame only InitializationState::OnUpdate will be called. Same for the reverse.

The only exception from this rule is the RunningState where only the returned value by the game's state is taken into consideration. For example:

  • RunningState::OnUpdate - returns true

  • CustomRunningState::OnUpdate - returns false

Then the frame, RunningState::OnExit will be called.

OnExit

Called when the state is ending. This function is called once by the game, so be careful what you want to do here.

Return

  • The return value is not taken in consideration. It is recommended to always return true for future proofing.

Game's Life Cycle

Example

Last updated