All objects spawned in a Unity scene are Behaviour
s. For local games we work with MonoBehaviour
s and for networking games Unity provides us NetworkBehaviour
s. Aside from those there aren't many abstractions where Unity supports us. I came to the conclusion that great gameplay support should be a feature that ships with the engine, finding myself abandoning projects because it doesn't.
I've worked with Unreal's Gameplay Framework which I really like and therefore want to improve Unity's gameplay layer by adding some of the things I have learned from UE4 (Unreal Engine 4). However, the existing Behaviour
code base cannot be removed as it lies at the heart of the Unity Engine.
Terminology | Description |
---|---|
Player | A player is a real human. Note that AIs (Bots) are not players. |
Participant | Players and AIs can become participants when they request to join a game. Participants are taking part in the game and can interact with the world. They can have a huge imapact on the outcome of the game. A player spectator that is not able to interact with the world is not a participant for example. |
Authority | The authority can either be a local client, a remote client (Host) or a server. A networking game has many actions that require to be authorized before they can happen. Win/Loose conditions are usually evaluated by the authority to prevent cheating for example. |
The Gameplay Framework consist of a few classes that help to structure gameplay logic.
The Game
class is a Singleton that provides general interaction with the game. Controller
s join the Game
to become participants for example.
The GameMode
only exists on the authority. The authority's Game
instance contains the only GameMode
across all participants. The GameMode
constantly evaluates the GameState
for new events that require authorization. It checks win/loose conditions as a common example.
All Game
s across all participants contain a single GameState
that is synchronized over the network. As the name suggests, this class contains the state of the game. However, not all information about the game must be stored in this class. Only data that must be autorized is required to be available in the GameState
.
The GameState
contains a collection of ParticipantState
s. They contain the information of a participant that requires to be authorized. All participants have a ParticipantState
.
A Controller
represents the will of a player or an AI. It can possess a single pawn at the time and/or become a participant by requesting a join.
A PlayerController
is a controller that represents the will of a player.
An AIController
is a controller that represent artificial intelligence.
An IPawn
is an entity that can become possessed by a single Controller
at a time. When possessed, a pawn follows the instructions of its Controller
.
MonoPawn
s are IPawn
s that are used for local play. They inherit from MonoBehaviour
.
NetworkPawn
s are IPawn
s that are used for network play. They inherit from NetworkBehaviour
and are currently not implemented due to a focus on local play for a first version of the Gameplay Framework.
PlayerManager
s are associated by PlayerController
s and handle the interaction between the game and the players. AIController
s do not require PlayerManager
s because an AI doesn't require visual feedback.
A PlayerInputManager
reads the input from the input devices of its player and prepares the information for its PlayerController
. It does not interpret the input but is allowed to make device specific corrections such as applying a deadzone to an analogue stick.
PlayerCameraManager
s are the cameramen in a game. Their main job is to position and rotate the camera correctly as well as performing any post-processing on the rendered image.
A PlayerHUDManager
is responsible to display a player's HUD (Heads Up Display).