ModularGameplayActors

Modular Gameplay Plugin Overview

A Modular Gameplay Plugin is a plugin whose base classes implement the Modular Gameplay pattern, which allows your project to inject components into actors at runtime.

This pattern gives the game support for GameFeature Plugins.

The ModularGameplayActors Plugin is a specific implementation of Modular Gameplay, distributed in GCC.

You can either actually base your classes on the ModularGameplayActors classes, or you can implement the same patterns in your own existing base classes.

Game Framework Component Manager

UGameFrameworkComponentManager « UGameInstanceSubsystem

This Game Instance Subsystem is what allows GCC to inject components into Actors at runtime.

Actors must explicitly opt-in to this behavior. Epic publishes the ModularGameplayActors plugin with LyraStarterGame and ValleyOfTheAncientdemo as an easy set of base classes to automate this opt-in process, but you don’t necessarily have to base your classes on those. You can duplicate the procedure in your own classes if you prefer.

Debugging Tip

Execute Log LogModularGameplay Verbose in the console to see verbose logging for this module.

Execute ModularGameplay.DumpGameFrameworkComponentManagers in the console to dump debugging info to help understand which components are being injected into which actors.

Game Framework Init State Interface

IGameFrameworkInitStateInterface must be implemented by any Component that needs to initialize based on dependencies that themselves are other Components with their own dependent initialization steps.

TLDR every component in the Game Framework spams Init() until everything has successfully initialized or has finally failed initialization.

Implementation in Pawn Extension

To implement the Modular Gameplay Plugin, take a look at GCCPawnExtensionComponent as an example.

  • Defines the UGCCPawnExtensionComponent that drives IGameFrameworkInitStateInterface

    • Adds this component to every Character in the game (via base class AGCCModularCharacter)

  • Implements IGameFrameworkInitStateInterface in other components as needed

Pawn Extension Component

UGCCPawnExtensionComponent is the implementation of the ModularGameplay Plugin’s IGameFrameworkInitStateInterface functionality on a Pawn.

Giving this component to an Actor allows the other components on that actor to share Init State updates with each other to satisfy runtime dependencies. The components can hook into Actor Init State Changed events broadcast by this component if/when they have runtime dependencies to satisfy.

Note that, though this is a component, there are some deep integrations in AGCCModularCharacter for things like, for example, calling UGCCPawnExtensionComponent🡒HandleControllerChanged from AGCCModularCharacter🡒PossessedBy. If you want a deep understanding of what this component is doing, make sure you read through AGCCModularCharacter as well.

OnRegister

  • Register self with ModularGameplay plugin’s UGameFrameworkComponentManager

    • Pawn Extension Component implements feature name PawnExtension

BeginPlay

  • Bind Actor Init State Changed event to UGCCPawnExtensionComponent🡒OnActorInitStateChanged

Pawn Extension Component 🡒 OnActorInitStateChanged

  • Every time a feature (NOT including the PawnExtension feature itself) changes state:

    • If new state == DataAvailable:

      • Run CheckDefaultInitialization() on all feature components

Pawn Extension Component :: CheckDefaultInitialization

This tells every component on the owner Actor that supports the IGameFrameworkInitStateInterface to try to initialize.

This gets spammed A LOT during initialization. This is a trigger that keeps getting executed until all components have initialized successfully or finally fail to initialize.

Make sure to setup your default game instance to GCCGameInstance in Edit->ProjectSettings->Maps And Modes -> Game Instance-> Game Instance Class

GCCModularCharacter

Minimal class that supports extension by game feature plugins

This class is intended to be used by Player-Controlled actors with AbilitySystemComponent living in the PlayerState

AbilitySystemComponent and ReplicationMode

Type: EGameplayEffectReplicationMode

Enabled: Mixed

How gameplay effects will be replicated to clients

GCCModularPawn

Minimal class that supports extension by game feature plugins

This class is intended to be used by AI-Controlled actors with AbilitySystemComponent living in this class

AbilitySystemComponent and ReplicationMode

Type: EGameplayEffectReplicationMode

Enabled: Minimal

How gameplay effects will be replicated to clients

GCCModularPlayerController

Minimal class that supports extension by game feature plugins

This class is meant to be use with UGCCModularCharacter

GCCModularAIController

Minimal class that supports extension by game feature plugins

This class is intended to use with UGCCModularPawn class to build AI-Controlled characters

GCCModularGameplayActor

Actor class that implement lazy loading for actor type like World Actor

Introduction

The Ability System Component (ASC) can be a bit resource-intensive, especially when dealing with World Actors that require it, like Damageables. If our world is populated with such Actors, their memory footprint can become noticeable.

Taking a cue from Epic and the insights shared by Tranek in the excellent GASDocumentation, Fortnite adopts a smart approach. They lazily load their ASCs in their World Actors just when they’re needed, dodging the memory hit until it’s absolutely necessary. This memory optimization is a significant boost for scalability; since ASC World Actors won’t carry that footprint unless explicitly interacted with.

Think of it like this: buildings, trees, and damageable props on standby with a lower cost, only racking up the memory bill when they step into the gameplay spotlight.

(Vorixo Lazy Loading Blog)

AbilitySystemComponent and ReplicationMode

Type: EGameplayEffectReplicationMode

Enabled: Minimal

How gameplay effects will be replicated to clients

Class Default Objects (CDO)

  • AbilitySystemComponent class - AbilitySystemComponent to be use by this actor

  • AbilitySystemComponent Creation Policy - Defines how a the Ability System is loaded

  • Attribute Sets - Attribute Set to be use by this actor

GCCModularPlayerState

Minimal class that supports extension by game feature plugins

This class is meant to be use with UGCCModularCharacter with ASC living in PlayerState

AbilitySystemComponent and ReplicationMode

Type: EGameplayEffectReplicationMode

Enabled : Mixed

How gameplay effects will be replicated to clients

Last updated