Please enable JavaScript.
Coggle requires JavaScript to display documents.
FUSION - Coggle Diagram
FUSION
API
NetworkRunner
-
Properties
All NetworkBehaviours can access the current NetworkRunner via the Runner property, and the Runner itself exposes some important system properties.
-
-
Callbacks
The NetworkRunner hook into important network related events by INetworkRunnerCallbacks interface and registering the script with the runner by calling NetworkRunner.AddCallbacks().
automatically register any SimulationBehaviour implementing the INetworkRunnerCallbacks interface located on the same object as the NetworkRunner a callback target.
-
GameMode
The GameMode defines how the local peer will behave. The GameMode is passed as a parameter to NetworkRunner.StartGame() method.
client:
runs as client, creates a local player, to connect to a client host (cloud-shared) or dedicated (server-based)
host:
runs as server, creates a local player (Server + Client)
server
: runs as dedicated server, no player
shared:
runs as client, creates a local player, to connect to the Fusion Plugin Server
single
: runs as "server", creates a local player, no connections allowed (Singleplayer)
NetworkTransform
simple kinematic object by interpolating between the objects actual local Transform and its simulated state.
-
-
-
Move()
Performs a movement query, uses its result to compute new Velocity and then applies penetration corrections + velocity integration into the transform position. It does not change Rotation.
direction
: Intended movement direction, subject to movement query + acceleration.
-
layerMask
: Optional layermask. If not passed, the default one from Config will be used.
-
-
-
-
RPC
-
Types
Instance RPC
parameter which respects the type constraints outlined in Network Object > NetworkBehaviour > Networked State > Constraints entry.
-
Define
-
Add the [Rpc] attribute in front of the method declaration; and,
Configure the RpcSources and RpcTargets parameters to control where the RPC may be called from and where it gets executed.
-
Targeted Rpc
The [RpcTarget] attribute used within the method the declaration is DIFFERENT from the RpcTargets parameter inside the [Rpc] attribute placed in front of the method declaration.
specific player's machine,
RPCs and Static RPCs can be turned into targeted RPCs by adding a PlayerRef parameter prefaced by the [RpcTarget] attribute
Attribute Parameters
Sources And Targets.
-
Proxies
: can be sent / is executed by a peer who does not have either Input Authority or State Authority over the object.
-
-
-
-
-
-
-
Network Input
Input Struct
-
-
-
Buttons
There is a special NetworkButtons type which provides a convenient wrapper for saving button presses in a INetworkInput struct.
-
-
The NetworkButtons type stateles, does not hold any meta data about the previous state of the buttons.
-
-
In order to be able to use the next set of methods offered by NetworkButtons, it is necessary to keep track of the previous state of the buttons; this is easily done by creating a [Networked] version of the previous state for each player.
-
Poll Input
Fusion collects input by polling the local client and populating a previously defined input struct. The Fusion Runner only ever keeps track of a single input struct, it is therefore strongly advised to implement the input polling in a single place to avoid any unexpected behaviour.
The Fusion Runner polls input by calling the INetworkRunnerCallbacks.OnInput() method. The implementation of OnInput() can populate any struct inheriting from INetworkInput with the chosen data. The populated struct is passed back to Fusion by calling Set() on the provided NetworkInput.
-
SimulationBehaviour
Fusion automatically calls OnInput() on all SimulationBehaviour and NetworkBehaviour components implementing the INetworkRunnerCallbacks interface and over which the client has Input Authority - hence the name.
-
Read Input
modify the existing networked state from its current state to the new one based on the previously polled input.
Contrary to polling input, reading input can be done at as many different places as necessary.
-
GetInput()
GetInput(out T input) in the FixedUpdateNetwork() of on any NetworkBehaviour which has Input Authority
-
-
-
Fusion synchronizes the input struct across the network and makes it available during simulation on the client who has Input Authority and the one who has State Authority (the host).
Authority
guarantee full simulation authority,
For instance, the following split would be used for firing a bullet:
-
-
-
-
-
NetWork Runner
Spawning
-
Runner.Spawn
Parameters
-
-
-
-
-
-
Only the prefab is a mandatory parameter, all others are optional.
Network topology.
On the server, in hosted or client/server
ownership server, and the object is created and returned immediately.
-
On a client in hosted or client/server mode,
-
In shared mode,
State Authority is always assigned to the caller and, again, the instance is returned immediately.
-
Spawn should be called from FixedUpdateNetwork and it is ok to call during both Forward and Re-simulation stages. Fusion will correctly return the same object during re-simulation of predicted local spawns (assuming the prediction key matches), while authoritative spawns only happen in shared mode or on the Host, neither of which does re-simulation.
-
Input Authority
-
If the object does not require input or no client has input authority over it, null can be passed instead.
OnBeforeSpawned
The NetworkRunner.OnBeforeSpawned parameter can take a method or lambda expression matching the delegate signature.
-
-
Despawn
Remove a network object, the peer with State Authority over the object may call Runner.Despawn().
Despawned
-
All NetworkBehaviours imlement IDespawned, whereas SimulationBehaviours have to add it explicitly.
Spawn Prediction
-
-
-
-
-
Spawned, Update, Render
The three first methods match the Spawned(), FixedUpdateNetwork() and Render() methods found in functional SimulationBehaviour and NetworkBehaviour components. They are called under the same conditions as those methods with the difference that these are exclusively and explicitly called when the object is in its "predicted" state.
In fact, one possible implementation of those methods is to simply call Spawned(), FixedUpdateNetwork() and Render(), respectively, though the application needs to consider that network properties are not available. One solution to that is to wrap the networked properties with a check for predictive spawning and maintain two sets of variables, like this:
-
-
-
-
-
-