Predicted Modules

Non-mono bound predicted code for maximum flexibility

The PredictedModule system allows you to encapsulate specific game logic and state into reusable, self-contained units. Instead of writing a PredictedIdentity that handles singular logic like timers, inventory, health, and such all in one script, you can break these features down into individual modules.

Why use Modules?

  • Encapsulation: Keep logic and state (e.g., a Timer or Health system) isolated from other systems.

  • Reusability: Write a module once (like a ProjectileMovementModule) and drop it into any PredictedIdentity.

  • Network Efficiency: Modules have their own delta compression. If only one module changes, only that module's data is sent over the network.

  • Automatic History & Rollbacks: Modules automatically participate in the prediction rollback system, saving you from manually managing history buffers for every variable.


Predicted Modules

The PredictedModule system allows you to encapsulate specific game logic and state into reusable, self-contained units. Instead of writing a monolithic PredictedIdentity that handles movement, health, inventory, and abilities all in one script, you can break these features down into individual modules.

Why use Modules?

  • Encapsulation: Keep logic and state (e.g., a Timer or Health system) isolated from other systems.

  • Reusability: Write a module once (like a ProjectileMovementModule) and drop it into any PredictedIdentity.

  • Automatic History & Rollbacks: Modules automatically participate in the prediction rollback system, saving you from manually managing history buffers for every variable.

Performance note: A predicted module acts similar to a predicted identity. This means that it's another state, and another simulation to handle. Pros of this is that it adds flexibility and modularity easily. The con being that now your identity is handling multiple simulations and multiple states which can be heavier for performance on both CPU and bandwidth. It's about weighing re-usability and flexibility vs performance. However, this is not heavier than having multiple predicted identities.


Implementation Guide

Creating a module involves two steps: defining the state and creating the module logic.

1. Define the State

Create a struct that implements IPredictedData<T>. This holds the data you want to sync and predict.

2. Create the Module

Inherit from PredictedModule<TState>. You typically override Simulate for logic and UpdateView for visuals.


Using a Module

To use a module, instantiate it within your PredictedIdentity. It will automatically register itself with the identity's prediction lifecycle.


Key Overrides

Method

Description

Simulate

Main Logic. Executed every tick. Modify state here to advance simulation.

UpdateView

Visuals. Executed every frame. Use viewState (interpolated) for smooth rendering.

Initialize

Setup. Called when the module is created. Use this instead of Awake/Start.

Interpolate

Smoothing. (Optional) Custom logic for blending states between ticks. Defaults to standard linear interpolation.

Last updated