I am looking for advice on how to aproach the following design problem in UE5 blueprints with a focus on modularity, maintainability and scalability:
The GameMovementComponent
There exists an actor component attached to the player pawn, the GameMovementComponent which inherits from a ReplicatedMovementComponent. The ReplicatedMovementComponent cannot be modified.
The ReplicatedMovementComponent exposes some events:
- BindNetworkData - Runs durig PostInitializeComponents on the owning actor
- Various other events - Run repeatedly During Gameplay
The GameMovementComponent implements its own logic for these events but other actor components on the player pawn may depend on these events too
Dependent Components
There may be none, one or multiple components which depend on the events, state and functionality of the GameMovementComponent, such as for example a WeaponComponent.
Dependency Relation
The following are the constraints for the dependency that these components may have on eachother:
- A GameMovementComponent that inherits from ReplicatedMovementComponent always exists
- The GameMovementComponent is not dependent on any other components
- Dependent components like the WeaponComponent may or may not exist
- Dependent components must always run logic on the BindNetworkData event
- Dependent components may need to run logic on any number of the Various other events
- The GameMovementComponent and Dependent components are attached to the same pawn
Design Problem
What mix of direct references, BPIs, inheritance and event dispatchers is the correct approach for this design problem.
Current approach & issues
Currently all Dependent components implement the IMovementDependent interface which exposes a RegisterAndBind function. When BindNetworkData runs on the GameMovementComponent it gets all actor components on its owner which implement this interface and calls RegisterAndBind, passing along a reference to itself as a ReplicatedMovementComponent object reference.
This is where I am stuck. I am unsure of how the Dependent components should Register themselves with GameMovementComponent and how to bind the various events they may deped on.
One idea would be to have another interface, say IDependencyComponent which exposes the Register function and then implement the interface in GameMovementComponent, as well as providing event dispatchers for every event exposed by ReplicatedMovementComponent in a base class for GameMovementComponent, allowing the Dependent Components to bind to whatever events they may depend on.
But this may be too convoluted, or there may be a better approach so any advice would be greatly appreciated!