Skip to main content

Component Based Logic Layer Framework

LGameInstance and Script Context

Play the game in the Editor (PIE) or play it standalone, component framework will automatically generate LGameInstance, each LGameInstance will create a script context. Script context is used for managing and isolating global objects, script paths and coroutines among multiple game instances and Editors. The project can inherit LGameInstance from the Engine and override LGameInstance:: PostInitScriptContext method, global variables can be set within this method. After loading the project DLL, the Editor can set which type of LGameInstance to use in the Game Instance Class setting under the Project Settings (If not set, the built-in LGameInstance will be used by default).

image-20221012165017454

LGameSubsystem

LGameSubsystem is a type of subsystem whose lifetime is as long as LGameInstance. Project can inherit from LGameSubsystem, and the component framework will create and destroy the LGameSubsystem inherited by the project when appropriate.

my_game_sub_system.cpp

#ifndef _MY_GAME_SUB_SYSTEM_H
#define _MY_GAME_SUB_SYSTEM_H

#include "fx_component/subsystem/game_subsystem.h"

class MyGameSubSystem : public LGameSubsystem
{
DECLARE_LCLASS(MyGameSubSystem, LGameSubsystem, COMPILED_IN_FLAGS(0))

public:
virtual void Update(float seconds) override;
virtual bool CanUpdate() const override { return true; }
virtual bool CanUpdateInEditor() const override { return true; }
};
#endif//_MY_GAME_SUB_SYSTEM_H

my_game_sub_system.cpp

#include "my_game_sub_system.h"
#include "flexi/object/class.h"
#include "flexi/public/module.h"

IMPLEMENT_LCLASS(MyGameSubSystem)

DECLARE_ENTITY("", MyGameSubSystem, LGameSubsystem)

void MyGameSubSystem::Update(float seconds)
{

}

LScene

LScene is not only the container of LLevel, but also the carrier of global effect and network synchronization mechanism. There will be a default LLevel object in the LScene, but more LLevels can be loaded using the streaming level mechanism.

LSceneSubsystem

LSceneSubsystem is a type of subsystem whose lifetime is as long as LScene. Project can inherit from LSceneSubsystem, and the component framework will create and destroy the LSceneSubsystem inherited by the project when appropriate.

LLevel

The LLevel object manages numerous LGameObjects and is responsible for driving LGameObjects and updating LComponent objects.

LGameObject

LGameObject is a set of LComponents that can aggregate multiple LComponents to perform different features.

LComponent

LComponent is the most basic carrier for functional reuse and combination.

Some commonly used components:

NameDescription
LTransformComponentTransform Component
LModelComponentStatic Model Component
LSkeletalMeshComponentSkeletal Mesh Animation Component
LSkinComponentSkin Component
LParticleComponentParticle Component
LTerrainComponentTerrain Component
LBrushComponentBrush Component
LBillboardComponentBillboard Component
LArrowComponentArrow Component
LDirectLightComponentDirect Light Component
LDrawFrustumComponentDraw Frustum Component
LSpringArmComponentSpring Arm Component
LMovememtComponentMovement Component
LVoxelTerrainComponentVoxel Terrain Component
LScriptComponentScript Component

LPawn

LPawn is a basic operable object type that offers basic object manipulation methods, AI, behavior trees, etc. The object or its derived object can be created in the project for operations such as moving around.

LCharacter

LCharacter is a basic character object type, which by default provides a capsule, a character movement component, a skeletal mesh component, and an arrow component. Projects can create this object or its derived objects to control as game characters.

LController

LController is a controller type which used to control characters and operatable objects.

LGameMode

LGameMode object sets the basic rules of the game, there is one LGameMode for each Level. It forms different game rules by setting different GameState, PlayerController, PlayerState, DefaultPawn, Spectator. You can customize LGameMode by reloading the LGameMode base type or using prefab. Set different GameMode for each Level by modifying the GameModeOverride property under LSceneSettings.

The settings in the Editor are shown as below:

image-20221012165041643

LPlayer

LPlayer is a player type, which is used to create game player in the project, the player controller can be obtained from the player object to control the character.

LPlayerStart

LPlayerStart is a player start object type, which is used to set the player's start mark.