Photon Bolt Engine API
Networking Middleware
Static Public Member Functions | Properties | List of all members
BoltNetwork Class Reference

Holds global methods and properties for starting and stopping bolt, instantiating prefabs and other utils More...

Static Public Member Functions

static void PreLoadPrefabDatabase ()
 Async load Bolt Entity prefabs More...
 
static void SetCanReceiveEntities (bool canReceiveEntities)
 Whether the local simulation can receive entities instantiated from other connections More...
 
static void RegisterShutdownDoneCallback (Action action)
 
static UdpChannelName CreateStreamChannel (string name, UdpChannelMode mode, int priority)
 Creating a new binary streaming channel More...
 
static void UpdateSceneObjectsLookup ()
 
static BoltEntity FindEntity (NetworkId id)
 Find an entity based on unique id More...
 
static void RegisterTokenClass< T > ()
 Registers a type as a potential protocol token More...
 
static void EnableUPnP ()
 Enables UPnP support on this instance More...
 
static void DisableUPnP ()
 Disable UPnP More...
 
static void OpenPortUPnP (int port)
 Opens a port to UPnP More...
 
static void ClosePortUPnP (int port)
 Closes a port to UPnP More...
 
static void SetEventFilter (IEventFilter filter)
 Sets bolt to use a filter to accept or reject certain events based on custom filtering More...
 
static void SetPrefabPool (IPrefabPool pool)
 Sets a custom implementation for pooling prefabs More...
 
static BoltEntity Instantiate (GameObject prefab)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (GameObject prefab, IProtocolToken token)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (GameObject prefab, Vector3 position, Quaternion rotation)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (GameObject prefab, IProtocolToken token, Vector3 position, Quaternion rotation)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (PrefabId prefabId)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (PrefabId prefabId, IProtocolToken token)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (PrefabId prefabId, Vector3 position, Quaternion rotation)
 Create a new entity in the simuation from a prefab More...
 
static BoltEntity Instantiate (PrefabId prefabId, IProtocolToken token, Vector3 position, Quaternion rotation)
 Create a new entity in the simuation from a prefab More...
 
static void Destroy (GameObject gameObject)
 Remove a gameObject from the bolt simulation. More...
 
static void Destroy (GameObject gameObject, IProtocolToken token)
 Remove a gameObject from the bolt simulation. More...
 
static GameObject Attach (GameObject gameObject)
 
static GameObject Attach (GameObject gameObject, IProtocolToken token)
 
static void Detach (GameObject gameObject)
 
static void Detach (GameObject gameObject, IProtocolToken token)
 
static Vector3 PositionAtFrame (BoltHitboxBody hitboxBody, int frame)
 Perform a hitbox rewind to get transform position at a given frame. More...
 
static BoltPhysicsHits RaycastAll (Ray ray)
 Perform a raycast against Bolt hitboxes More...
 
static BoltPhysicsHits RaycastAll (Ray ray, int frame)
 Perform a raycast against Bolt hitboxes More...
 
static BoltPhysicsHits OverlapSphereAll (Vector3 origin, float radius)
 Perform a sphere overlap against Bolt hiboxes More...
 
static BoltPhysicsHits OverlapSphereAll (Vector3 origin, float radius, int frame)
 Perform a sphere overlap against Bolt hiboxes More...
 
static void Accept (UdpEndPoint endpoint)
 Signal bolt to accept an incoming client connection request More...
 
static void Accept (UdpEndPoint endpoint, IProtocolToken acceptToken)
 Signal bolt to accept an incoming client connection request More...
 
static void Refuse (UdpEndPoint endpoint)
 Signal bolt to refuse an incoming connection request More...
 
static void Refuse (UdpEndPoint endpoint, IProtocolToken token)
 Signal bolt to refuse an incoming connection request More...
 
static void AddGlobalEventListener (MonoBehaviour mb)
 Manually add a global event listener More...
 
static void AddGlobalEventCallback< T > (Action< T > callback)
 Manually add a global event callback More...
 
static void RemoveGlobalEventListener (MonoBehaviour mb)
 Manually remove a global event listener More...
 
static void RemoveGlobalEventCallback< T > (Action< T > callback)
 Manually remove a global event callback More...
 
static void LoadScene (string scene)
 Load a scene based on name, only possible on the Server More...
 
static void LoadScene (string scene, IProtocolToken token)
 Load a scene based on name, only possible on the Server More...
 
static void Connect (UdpEndPoint endpoint)
 Connect to a server More...
 
static void Connect (UdpSession session)
 
static void Connect (UdpSession session, IProtocolToken token)
 
static void Connect (UdpEndPoint endpoint, IProtocolToken token)
 Connect to a server More...
 
static void SetHostInfo (string serverName, IProtocolToken token)
 Set session data for LAN Broadcast/Master Server listing More...
 
static void SetDedicatedServerInfo (string serverName, IProtocolToken token)
 
static void DisableLanBroadcast ()
 Disable LAN broadcasting More...
 
static void EnableLanBroadcast ()
 Enable LAN broadcasting More...
 
static void EnableLanBroadcast (ushort port)
 Enable LAN broadcasting More...
 
static void UpdateSessionList (Map< Guid, UdpSession > sessions)
 

Properties

static IEnumerable< BoltEntitySceneObjects [get]
 A list of all BoltEntities in the server simulation More...
 
static int frame [get]
 The current local simulation frame number More...
 
static int maxConnections [get]
 The max number of client connections to the server More...
 
static UdpSocket UdpSocket [get]
 
static IEnumerable< BoltEntityentities [get]
 The current server simulation frame number More...
 
static int serverFrame [get]
 On the server this returns the local frame, on a client this returns the currently estimated frame of all server objects we have received More...
 
static float serverTime [get]
 The current server simulation time More...
 
static float time [get]
 The local time, same as Time.time More...
 
static float frameDeltaTime [get]
 The fixed frame delta, same as Time.fixedDeltaTime More...
 
static float frameBeginTime [get]
 The time the last fixed update begain, same as Time.fixedTime More...
 
static float frameAlpha [get]
 Normalized value of how much time have passed since the last FixedUpdate More...
 
static IEnumerable< BoltConnectionconnections [get]
 All the connections connected to this host More...
 
static IEnumerable< BoltConnectionclients [get]
 All clients connected to this host More...
 
static BoltConnection server [get]
 The server connection More...
 
static int framesPerSecond [get]
 How many FixedUpdate frames per second bolt is configured to run More...
 
static bool isServer [get]
 Returns true if this host is a server More...
 
static bool isServerOrNotRunning [get]
 
static bool isConnected [get]
 Returns true if this instance is a server or a client with at least one valid connection. More...
 
static bool isClient [get]
 Returns true if this host is a client More...
 
static bool isRunning [get]
 If bolt is running More...
 
static bool isDebugMode [get]
 Returns true if Bolt was compiled in debug mode More...
 
static ScopeMode scopeMode [get]
 The scoping mode active More...
 
static GameObject globalObject [get]
 The global object that all global behaviours will be attached to More...
 
static IEnumerable< INatDeviceNatDevicesUPnP [get]
 A list of available devices that provide UPnP support More...
 
static bool IsSinglePlayer [get]
 
static Map< Guid, UdpSession > SessionList [get]
 

Detailed Description

Holds global methods and properties for starting and stopping bolt, instantiating prefabs and other utils

Example: How to load a map on the server and instantiate a server controlled player.

1 void LoadMap(string mapName) {
2  BoltNetwork.LoadScene(mapName);
3  var serverPlayer = BoltNetwork.Instantiate(BoltPrefabs.Player) as GameObject;
4  Configure(serverPlayer);
5 }

Example: How to connect to a server with known IP and port number.

1 void ConnectToServer(string host, int port) {
2  UdpEndPoint serverAddr = UdpEndPoint(UdpIPv4Address.Parse(host), (ushort)port);
3  BoltNetwork.Connect(server);
4 }

Example: How to use the BoltNetwork frame property in an Update loop. Here we recalculate the player path 3 times per second.

1 void Update() {
2  if(BoltNetwork.frame % 20) == 0) {
3  playerMotor.Repath(targetPos);
4  }
5 }

Member Function Documentation

static void BoltNetwork.Accept ( UdpEndPoint  endpoint)
inlinestatic

Signal bolt to accept an incoming client connection request

Parameters
endpointThe UDP address of incoming client connection

Example: Accepting an incoming connection.

1 public override void ConnectRequest(UdpEndPoint endpoint) {
2  BoltNetwork.Accept(endPoint);
3 }
static void BoltNetwork.Accept ( UdpEndPoint  endpoint,
IProtocolToken  acceptToken 
)
inlinestatic

Signal bolt to accept an incoming client connection request

Parameters
endpointThe UDP address of incoming client connection
acceptTokenA data token from the server

Example: Accepting an incoming connection and passing a data token to tell the client the preferred reconnect timeout.

1 public override void ConnectRequest(BoltConnection connection) {
2  ConnectionToken token = new ConnectionToken();
3  connectionToken.retryTimeout = 30f;
4 
5  BoltNetwork.Accept(connection.remoteEndPoint, token);
6 }
static void BoltNetwork.AddGlobalEventCallback< T > ( Action< T >  callback)
inlinestatic

Manually add a global event callback

Type Constraints
T :Bolt.Event 
static void BoltNetwork.AddGlobalEventListener ( MonoBehaviour  mb)
inlinestatic

Manually add a global event listener

Parameters
mbThe monobehaviour to invoke events on
static GameObject BoltNetwork.Attach ( GameObject  gameObject)
inlinestatic
static GameObject BoltNetwork.Attach ( GameObject  gameObject,
IProtocolToken  token 
)
inlinestatic
static void BoltNetwork.ClosePortUPnP ( int  port)
inlinestatic

Closes a port to UPnP

Parameters
portThe port number
static void BoltNetwork.Connect ( UdpEndPoint  endpoint)
inlinestatic

Connect to a server

Parameters
endpointServer end point to connect to

Example: A method to connect to a known server address as a client.

1 void Connect(string host, int port) {
2  UdpEndPoint serverAddr = new UdpEndPoint(UdpIPv4Address.Parse(host), (ushort)port);
3 
4  BoltNetwork.Connect(serverAddr);
5 }
static void BoltNetwork.Connect ( UdpSession  session)
inlinestatic
static void BoltNetwork.Connect ( UdpSession  session,
IProtocolToken  token 
)
inlinestatic
static void BoltNetwork.Connect ( UdpEndPoint  endpoint,
IProtocolToken  token 
)
inlinestatic

Connect to a server

Parameters
endpointServer end point to connect to

Example: A method to connect to any server ip and port as a client.

1 void Connect(string host, int port) {
2  UdpEndPoint serverAddr = new UdpEndPoint(UdpIPv4Address.Parse(host), (ushort)port);
3 
4  Credentials cred = new Credentials("DevUser01", "DevPassword");
5 
6  BoltNetwork.Connect(serverAddr, cred);
7 }
static UdpChannelName BoltNetwork.CreateStreamChannel ( string  name,
UdpChannelMode  mode,
int  priority 
)
inlinestatic

Creating a new binary streaming channel

Parameters
nameChannel name
modeReliability mode
priorityBandwidth priority
Returns
Channel name struct

Example: Creating an unreliable stream channel for voice and a reliable stream channel for sending custom player icons.

1 public static UdpKit.UdpChannelName Voice;
2 public static UdpKit.UdpChannelName CustomPlayerIcon;
3 
4 public override void BoltStartBegin() {
5  Voice = BoltNetwork.CreateStreamChannel("Voice", UdpKit.UdpChannelMode.Unreliable, 1});
6  CustomPlayerIcon = BoltNetwork.CreateStreamChannel("CustomPlayerIcon", UdpKit.UdpChannelMode.Reliable, 4});
7 }
static void BoltNetwork.Destroy ( GameObject  gameObject)
inlinestatic

Remove a gameObject from the bolt simulation.

Parameters
gameObjectThe gameObject to remove

Example: Destroying all player entities using a foreach loop over BoltNetwork.SceneObjects.

1 void DestroyAllPlayers() {
2  foreach(var entity in BoltNetwork.SceneObjects) {
3  if(entity.StateIs<IPlayerState>()) {
4  BoltNetwork.Destroy(entity.gameObject);
5  }
6  }
7 }
static void BoltNetwork.Destroy ( GameObject  gameObject,
IProtocolToken  token 
)
inlinestatic

Remove a gameObject from the bolt simulation.

Parameters
gameObjectThe gameObject to remove

Example: Destroying all player entities using a foreach loop over BoltNetwork.SceneObjects and sending a death recap message as a protocol token.

1 void DestroyAllPlayers() {
2  foreach(var entity in BoltNetwork.SceneObjects) {
3  if(entity.StateIs<IPlayerState>()) {
4  DeathRecap recap = new DeathRecap("Destroyed By Server");
5  BoltNetwork.Destroy(entity.gameObject, recap);
6  }
7  }
8 }
static void BoltNetwork.Detach ( GameObject  gameObject)
inlinestatic
static void BoltNetwork.Detach ( GameObject  gameObject,
IProtocolToken  token 
)
inlinestatic
static void BoltNetwork.DisableLanBroadcast ( )
inlinestatic

Disable LAN broadcasting

Example: Disabling LAN broadcasting at the end of a game.

1 void GameOver() {
2  foreach(var client in BoltNetwork.clients) {
3  client.Disconnect();
4  }
5  BoltNetwork.DisableLanBroadcast();
6 }
static void BoltNetwork.DisableUPnP ( )
inlinestatic

Disable UPnP

static void BoltNetwork.EnableLanBroadcast ( )
inlinestatic

Enable LAN broadcasting

Example: Enabling LAN broadcast after starting a new server.

1 void StartServer(int port, string map) {
2  BoltLauncher.StartServer(new UdpEndPoint(UdpIPv4Address.Any, (ushort)serverPort));
3  BoltNetwork.LoadScene(map);
4  BoltNetwork.EnableLanBroadcast();
5 }
static void BoltNetwork.EnableLanBroadcast ( ushort  port)
inlinestatic

Enable LAN broadcasting

Parameters
portThe port to use for LAN broadcast

Example: Enabling LAN broadcast after starting a new server using a specified port.

1 void StartServer(int port, string map) {
2  BoltLauncher.StartServer(serverAddr);
3  BoltNetwork.EnableLanBroadcast(port);
4  BoltNetwork.LoadScene(map);
5 }
static void BoltNetwork.EnableUPnP ( )
inlinestatic

Enables UPnP support on this instance

static BoltEntity BoltNetwork.FindEntity ( NetworkId  id)
inlinestatic

Find an entity based on unique id

Parameters
idThe id to look up
Returns
The entity if one was found, otherwise null

Example: Locating an entity within the scene using an id provided by the input command.

1 public override void ExecuteCommand(Bolt.Command cmd, bool resetState) {
2  AttackCommand atkCmd = (AttackCommand)cmd;
3  vNetworkId targetId = atkCmd.Input.targetId;
4 
5  BoltEntity target = BoltNetwork.FindEntity(targetId);
6  activeWeapon.Fire(entity, target);
7 }
static BoltEntity BoltNetwork.Instantiate ( GameObject  prefab)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabThe prefab to clone into the simulation
Returns
A reference to the new bolt entity

Example: How to instantiate and configure a player entity inside a Bolt.GlobalEventListener on the server using a public editor variable playerPrefab as the player prefab object.

1 public GameObject playerPrefab;
2 
3 public override void SceneLoadRemoteDone(BoltConnection connection) {
4  var player = BoltNetwork.Instantiate(playerPrefab);
5  player.transform.position = spawnPoint.transform.position;
6 
7  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
8  Configure(player, initData);
9 
10  player.AssignControl(connection);
11 }
static BoltEntity BoltNetwork.Instantiate ( GameObject  prefab,
IProtocolToken  token 
)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabThe prefab to clone into the simulation
tokenA data token of max size 512 bytes
Returns
A reference to the new bolt entity

Example: How to instantiate a player entity and allow to to configure itself with some initial data.

1 public GameObject playerPrefab;
2 
3 public override void SceneLoadRemoteDone(BoltConnection connection) {
4  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
5  var player = BoltNetwork.Instantiate(playerPrefab, initData);
6  player.AssignControl(connection);
7 }
static BoltEntity BoltNetwork.Instantiate ( GameObject  prefab,
Vector3  position,
Quaternion  rotation 
)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabThe prefab to clone into the simulation
positionA position vector
rotationA rotation quaternion
Returns
A reference to the new bolt entity

Example: How to instantiate and configure a player entity with the position and rotation set to match that of the spawnPoint transform reference.

1 public GameObject playerPrefab;
2 
3 public override void SceneLoadRemoteDone(BoltConnection connection) {
4  var player = BoltNetwork.Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
5 
6  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
7  Configure(player, initData);
8 
9  player.AssignControl(connection);
10 }
static BoltEntity BoltNetwork.Instantiate ( GameObject  prefab,
IProtocolToken  token,
Vector3  position,
Quaternion  rotation 
)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabThe prefab to clone into the simulation
tokenA data token of max size 512 bytes
positionA position vector
rotationA rotation quaternion
Returns
A reference to the new bolt entity

Example: How to instantiate and configure a player entity with both an initial data token and a given position / rotation.

1 public GameObject playerPrefab;
2 
3 public override void SceneLoadRemoteDone(BoltConnection connection) {
4  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
5  var player = BoltNetwork.Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
6 
7  player.AssignControl(connection);
8 }
static BoltEntity BoltNetwork.Instantiate ( PrefabId  prefabId)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabIdThe prefab to clone into the simulation
Returns
A reference to the new bolt entity

Example: How to instantiate a player entity using the static BoltPrefabs class as a shortcut to the player prefab object.

1 public override void SceneLoadRemoteDone(BoltConnection connection) {
2  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
3  var player = BoltNetwork.Instantiate(BoltPrefabs.Player, initData);
4  player.AssignControl(connection);
5 }
static BoltEntity BoltNetwork.Instantiate ( PrefabId  prefabId,
IProtocolToken  token 
)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabIdThe prefab to clone into the simulation
tokenA data token of max size 512 bytes
Returns
A reference to the new bolt entity

Example: How to instantiate a player entity and allow to to configure itself with some initial data using static BoltPrefabs class as a shortcut to the player prefab object.

1 public override void SceneLoadRemoteDone(BoltConnection connection) {
2  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
3  var player = BoltNetwork.Instantiate(BoltPrefabs.Player, initData);
4  player.AssignControl(connection);
5 }
static BoltEntity BoltNetwork.Instantiate ( PrefabId  prefabId,
Vector3  position,
Quaternion  rotation 
)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabIdThe prefab to clone into the simulation
positionA position vector
rotationA rotation quaternion
Returns
A reference to the new bolt entity

Example: How to instantiate a player entity from the static BoltPrefabs class with a given position and rotation.

1 public override void SceneLoadRemoteDone(BoltConnection connection) {
2  var player = BoltNetwork.Instantiate(BoltPrefabs.Player, spawnPoint.position, spawnPoint.rotation);
3 
4  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
5  Configure(player, initData);
6 
7  player.AssignControl(connection);
8 }
static BoltEntity BoltNetwork.Instantiate ( PrefabId  prefabId,
IProtocolToken  token,
Vector3  position,
Quaternion  rotation 
)
inlinestatic

Create a new entity in the simuation from a prefab

Parameters
prefabIdThe prefab to clone into the simulation
tokenA data token of max size 512 bytes
positionA position vector
rotationA rotation quaternion
Returns
A reference to the new bolt entity

Example: How to instantiate and configure a player entity inside a Bolt.GlobalEventListener on the server using initial data and the static BoltPrefabs class as a shortcut to the player prefab id.

1 public override void SceneLoadRemoteDone(BoltConnection connection) {
2  var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
3  var player = BoltNetwork.Instantiate(BoltPrefabs.Player, spawnPoint.position, spawnPoint.rotation);
4 
5  player.AssignControl(connection);
6 }
static void BoltNetwork.LoadScene ( string  scene)
inlinestatic

Load a scene based on name, only possible on the Server

Parameters
sceneThe scene to load

Example: A utility function to start a server and initialize the first map.

1 public void StartServer(UdpEndPoint addr, string map) {
2  BoltLauncher.StartServer(addr);
3  BoltNetwork.LoadScene(map);
4 }
static void BoltNetwork.LoadScene ( string  scene,
IProtocolToken  token 
)
inlinestatic

Load a scene based on name, only possible on the Server

Parameters
sceneThe scene to load
tokenA data token from the server

Example: Passing a random tip to display to each client while the new map is loading.

1 public void ChangeMap(string map) {
2  ServerMessage message = new ServerMessage("Loading Map ...", GameTips.GetNext());
3  BoltNetwork.LoadScene(map, message);
4 }
static void BoltNetwork.OpenPortUPnP ( int  port)
inlinestatic

Opens a port to UPnP

Parameters
portThe port number
static BoltPhysicsHits BoltNetwork.OverlapSphereAll ( Vector3  origin,
float  radius 
)
inlinestatic

Perform a sphere overlap against Bolt hiboxes

Parameters
originThe origin of the sphere
radiusThe radius of the sphere
Returns
The hitboxes that overlapped with the sphere

Example: Calculating the blast radius of a grenade.

1 void GrenadeOwner(PlayerCommand cmd, BoltEntity entity, IThrownWeapon grenade) {
2  if(entity.isOwner) {
3  using(var hits = BoltNetwork.OverlapSphereAll(cmd.targetPos, grenade.explosionRadius)) {
4  for(int i = 0; i < hits.count; i++) {
5  var hit = hits.GetHit(i);
6  var targetEntity = hit.body.GetComponent<BoltEntity>();
7 
8  if(targetEntity != entity && targetEntity.StateIs<ILivingEntity>()) {
9  targetEntity.GetState<ILivingEntity>().Modify().HP -= grenade.damage;
10  }
11  }
12  }
13  }
14 }
static BoltPhysicsHits BoltNetwork.OverlapSphereAll ( Vector3  origin,
float  radius,
int  frame 
)
inlinestatic

Perform a sphere overlap against Bolt hiboxes

Parameters
originThe origin of the sphere
radiusThe radius of the sphere
frameThe frame to rollback to for calculation
Returns
The hitboxes that overlapped with the sphere

Example: Calculating the blast radius of a grenade.

1 void GrenadeOwner(PlayerCommand cmd, BoltEntity entity, IThrownWeapon grenade) {
2  if(entity.isOwner) {
3  using(var hits = BoltNetwork.OverlapSphereAll(cmd.targetPos, grenade.explosionRadius, cmd.ServerFrame)) {
4  for(int i = 0; i < hits.count; i++) {
5  var hit = hits.GetHit(i);
6  var targetEntity = hit.body.GetComponent<BoltEntity>();
7 
8  if(targetEntity != entity && targetEntity.StateIs<ILivingEntity>()) {
9  targetEntity.GetState<ILivingEntity>().Modify().HP -= grenade.damage;
10  }
11  }
12  }
13  }
14 }
static Vector3 BoltNetwork.PositionAtFrame ( BoltHitboxBody  hitboxBody,
int  frame 
)
inlinestatic

Perform a hitbox rewind to get transform position at a given frame.

Parameters
hitboxBodyThe BoltHitboxBody to rewind
frameThe frame (aka BoltNetwork.frame) to rewind to
Returns
The transform position of the hitbox on a given BoltNetwork.frame

Example: Using PositionAtFrame to perform a dist check between a caster and target entity, but some frames back in time.

1 Vector3 RewindDistCheck(BoltEntity caster, BoltEntity target, int framesToRewind) {
2  casterHitbox = caster.GetComponent<BoltHitboxBody>();
3  targetHitbox = caster.GetComponent<BoltHitboxBody>();
4  casterRewindPos = BoltNetwork.PositionAtFrame(casterHitbox, BoltNetwork.frame - framesToRewind);
5  targetRewindPos = BoltNetwork.PositionAtFrame(targetHitbox, BoltNetwork.frame - framesToRewind);
6  return Vector3.Distance(casterRewindPos, targetRewindPos);
7 }
static void BoltNetwork.PreLoadPrefabDatabase ( )
inlinestatic

Async load Bolt Entity prefabs

Example: Preloading assets in the background before Bolt starts.

1 void loadInBackground() {
2  BoltNetwork.PreLoadPrefabDatabase();
3  Resources.LoadAsync<myTerrain>("Terrain");
4 }
static BoltPhysicsHits BoltNetwork.RaycastAll ( Ray  ray)
inlinestatic

Perform a raycast against Bolt hitboxes

Parameters
ray<The ray to/param>
Returns
The hitboxes that intersected the ray

Example: Using RaycastAll to detect a hit event and apply damage in a player weapon firing method.

1 void FireWeaponOwner(PlayerCommand cmd, BoltEntity entity) {
2  if(entity.isOwner) {
3  using(var hits = BoltNetwork.RaycastAll(new Ray(entity.transform.position, cmd.Input.targetPos)) {
4  var hit = hits.GetHit(0);
5  var targetEntity = hit.body.GetComponent<BoltEntity>();
6 
7  if(targetEntity.StateIs<ILivingEntity>()) {
8  targetEntity.GetState<ILivingEntity>().Modify().HP -= activeWeapon.damage;
9  }
10  }
11  }
12 }
static BoltPhysicsHits BoltNetwork.RaycastAll ( Ray  ray,
int  frame 
)
inlinestatic

Perform a raycast against Bolt hitboxes

Parameters
ray<The ray to/param>
Parameters
frameThe frame to roll back to when performing this raycast
Returns
The hitboxes that intersected the ray

Example: Using RaycastAll to detect a hit event on a specific previous frame and then apply damage in a player weapon firing method.

1 void FireWeaponOwner(PlayerCommand cmd, BoltEntity entity) {
2  if(entity.isOwner) {
3  using(var hits = BoltNetwork.RaycastAll(new Ray(entity.transform.position, cmd.Input.targetPos),
4  cmd.ServerFrame)) {
5  var hit = hits.GetHit(0);
6  var targetEntity = hit.body.GetComponent<BoltEntity>();
7 
8  if(targetEntity.StateIs<ILivingEntity>()) {
9  targetEntity.GetState<ILivingEntity>().Modify().HP -= activeWeapon.damage;
10  }
11  }
12  }
13 }
static void BoltNetwork.Refuse ( UdpEndPoint  endpoint)
inlinestatic

Signal bolt to refuse an incoming connection request

Parameters
endpointThe UDP address of incoming client connection

Example: Refusing an incoming connection.

1 public override void ConnectRequest(BoltConnection connection) {
2  BoltNetwork.Refuse(connection.remoteEndPoint);
3 }
static void BoltNetwork.Refuse ( UdpEndPoint  endpoint,
IProtocolToken  token 
)
inlinestatic

Signal bolt to refuse an incoming connection request

Parameters
endpointThe UDP address of incoming client connection
tokenA data token from the server

Example: Refusing an incoming connection and sending back an error message.

1 public override void ConnectRequest(BoltConnection connection) {
2  ErrorMessage errorMessage = new ErrorMessage("Connection Refused", "Server Is Full");
3 
4  BoltNetwork.Refuse(connection.remoteEndPoint, errorMessage);
5 }
static void BoltNetwork.RegisterShutdownDoneCallback ( Action  action)
inlinestatic
static void BoltNetwork.RegisterTokenClass< T > ( )
inlinestatic

Registers a type as a potential protocol token

Template Parameters
TThe type to register

Example Registering two token types on startup.

1 public override void BoltStartDone() {
2  BoltNetwork.RegisterTokenClass<UserToken>();
3  BoltNetwork.RegisterTokenClass<ServerMessage>();
4 }
Type Constraints
T :class 
T :IProtocolToken 
T :new() 
static void BoltNetwork.RemoveGlobalEventCallback< T > ( Action< T >  callback)
inlinestatic

Manually remove a global event callback

Type Constraints
T :Bolt.Event 
static void BoltNetwork.RemoveGlobalEventListener ( MonoBehaviour  mb)
inlinestatic

Manually remove a global event listener

Parameters
mbThe monobehaviour to be removed
static void BoltNetwork.SetCanReceiveEntities ( bool  canReceiveEntities)
inlinestatic

Whether the local simulation can receive entities instantiated from other connections

Parameters
canReceiveEntitiesWTrue/False

Example: Configuring the server to allow receiving entities and open a LAN game.

1 void ConfigureServer() {
2  BoltNetwork.SetCanReceiveEntities(true);
3  BoltNetwork.EnableLanBroadcast();
4 }
static void BoltNetwork.SetDedicatedServerInfo ( string  serverName,
IProtocolToken  token 
)
inlinestatic
static void BoltNetwork.SetEventFilter ( IEventFilter  filter)
inlinestatic

Sets bolt to use a filter to accept or reject certain events based on custom filtering

Parameters
filterYour custom implementation of the IEventFilter interface

Example: A custom event filter implementation which does nothing.

1 public class NullEventFilter : IEventFilter {
2  public bool EventReceived(Event ev) {
3  return true;
4  }
5 }

Example: Setting the NullEventFilter on startup.

1 public override void BoltStartDone() {
2  SetEventFilter(new NullEventFilter());
3 }
static void BoltNetwork.SetHostInfo ( string  serverName,
IProtocolToken  token 
)
inlinestatic

Set session data for LAN Broadcast/Master Server listing

Parameters
serverNameName of the server
userDataUser definable data

Example: Setting the host info to contain the max number of connections allowed by this server.

1 void SetSessionData(string serverName, string description, int maxPlayers) {
2  SessionData sessionData = new SessionData(description, BoltNetwork.maxConnections);
3 
4  BoltNetwork.SetHostInfo(serverName, sessionData);
5 }
static void BoltNetwork.SetPrefabPool ( IPrefabPool  pool)
inlinestatic

Sets a custom implementation for pooling prefabs

Parameters
poolThe custom pooling implementation

Example: Setting bolt to use a custom prefab pooling implementation.

1 public override void BoltStartDone() {
2  SetPrefabPool(new YourPrefabPool());
3 }
static void BoltNetwork.UpdateSceneObjectsLookup ( )
inlinestatic
static void BoltNetwork.UpdateSessionList ( Map< Guid, UdpSession >  sessions)
inlinestatic

Property Documentation

IEnumerable<BoltConnection> BoltNetwork.clients
staticget

All clients connected to this host

Example: Disconnecting all current clients.

1 void DisconnectAllClients() {
2  foreach(var client in BoltNetwork.clients) {
3  client.Disconnect();
4  }
5 }
IEnumerable<BoltConnection> BoltNetwork.connections
staticget

All the connections connected to this host

Example: Terminating all connections.

1 void DisconnectAll() {
2  foreach(var connection in BoltNetwork.connections) {
3  connection.Disconnect();
4  }
5 }
IEnumerable<BoltEntity> BoltNetwork.entities
staticget

The current server simulation frame number

Example: A post-game method to destroy all minions/npcs in the server simulation.

1 void PostGameCleanup() {
2  foreach(var entity in BoltNetwork.entities) {
3  if(entity.isOwner && entity.StateIs<MinionState>) {
4  BoltNetwork.Destroy(entity);
5  }
6  }
7 }
int BoltNetwork.frame
staticget

The current local simulation frame number

Example: Using the BoltNetwork frame in a loop to recalculate the player path once every 20 frames.

1 void FixedUpdate() {
2  if(BoltNetwork.frame % 20) == 0) {
3  playerMotor.Repath(targetPos);
4  }
5 }
float BoltNetwork.frameAlpha
staticget

Normalized value of how much time have passed since the last FixedUpdate

float BoltNetwork.frameBeginTime
staticget

The time the last fixed update begain, same as Time.fixedTime

float BoltNetwork.frameDeltaTime
staticget

The fixed frame delta, same as Time.fixedDeltaTime

Example: How to use frameDeltaTime to translate a player's per-second health regeneration rate into a per-frame value.

1 protected override void SimulateOwner() {
2  float hpRegen = BoltNetwork.frameDeltaTime * state.HealthRegen;
3  state.Modify().HP = Mathf.Clamp(state.HP + hpRegen, 0, 100);
4 }
int BoltNetwork.framesPerSecond
staticget

How many FixedUpdate frames per second bolt is configured to run

Example: Calculating the number of frames between footsteps from a time interval.

1 int FootstepFrameInterval(float stepTimeInterval) {
2  return Mathf.Round(stepTimeInterval / BoltNetwork.framesPerSecond);
3 }
GameObject BoltNetwork.globalObject
staticget

The global object that all global behaviours will be attached to

Example: The globalObject can be used as a root for attaching new scripts such as GlobalEventListener callbacks.

1 protected override void SceneLoadLocalDone(string map) {
2  if(map.Equals("GameScene")) {
3  BoltNetwork.globalObject.AddComponent<ClientGameCallbacks>();
4  }
5 }
bool BoltNetwork.isClient
staticget

Returns true if this host is a client

Example: Implementing a client-side score sheet display to show the scores at the end of a game.

1 void GameOver(string winTeam) {
2  if(BoltNetwork.isClient) {
3  DisplayScoreSheet("Game Over", winTeam + " Team Wins!";
4  }
5 }
bool BoltNetwork.isConnected
staticget

Returns true if this instance is a server or a client with at least one valid connection.

Example: Using the isConnected property to do an automatic reconnect loop.

1 void Update() {
2  if(!BoltNetwork.connected && BoltNetwork.time - lastReconnectTime > 30f) {
3  BoltNetwork.Connect(serverAddr);
4  lastReconnectTime = BoltNetwork.time;
5  }
6 }
bool BoltNetwork.isDebugMode
staticget

Returns true if Bolt was compiled in debug mode

Example: Showing an FPS and ping counter when in debug mode.

1 public override void BoltStartDone() {
2  if(BoltNetwork.isDebugMode) {
3  PingView.instance.Show();
4  FPSCounter.instance.Show();
5  }
6 }
bool BoltNetwork.isRunning
staticget

If bolt is running

Example: How to use the isRunning property to detect a downtime and restart the server.

1 void Update() {
2  if(!BoltNetwork.isRunning && BoltNetwork.time > lastRestart + 30f) {
3  RestartServer();
4  lastRestart = BoltNetwork.time;
5  }
6 }
bool BoltNetwork.isServer
staticget

Returns true if this host is a server

Example: Using the isServer property to implement server specific logic such as spawning NPCs after a new map has been generated.

1 public override void SceneLoadLocalDone(string map) {
2  GenerateMap();
3 
4  if(BoltNetwork.isServer) {
5  SpawnNPCs();
6  }
7 }
bool BoltNetwork.isServerOrNotRunning
staticget
bool BoltNetwork.IsSinglePlayer
staticget
int BoltNetwork.maxConnections
staticget

The max number of client connections to the server

Example: Using the max connections value to enforce server connection limits on an incoming client connection.

1 public override void ConnectRequest(UdpEndPoint clientAddr)
2 {
3  if(BoltNetwork.connections.Count == BoltNetwork.maxConnections)
4  {
5  BoltNetwork.Refuse(clientAddr);
6  return;
7  }
8 }
IEnumerable<INatDevice> BoltNetwork.NatDevicesUPnP
staticget

A list of available devices that provide UPnP support

IEnumerable<BoltEntity> BoltNetwork.SceneObjects
staticget

A list of all BoltEntities in the server simulation

Example: Destroying all player entities using a foreach loop over BoltNetwork.SceneObjects and finding the players with StateIs().

1 void DestroyAllPlayers()
2 {
3  foreach(var entity in BoltNetwork.SceneObjects)
4  {
5  if(entity.StateIs<IPlayerState>())
6  {
7  BoltNetwork.Destroy(entity.gameObject);
8  }
9  }
10 }
ScopeMode BoltNetwork.scopeMode
staticget

The scoping mode active

BoltConnection BoltNetwork.server
staticget

The server connection

Example: Displaying the current server IP address and port to the client.

1 void ShowServerEndpoint() {
2  UdpEndPoint serverEndPoint = BoltNetwork.server.remoteEndPoint;
3  Message.Show("Current Server", string.Format("({0}:{1}", serverEndPoint.Address, serverEndPoint.Port);
4 }
int BoltNetwork.serverFrame
staticget

On the server this returns the local frame, on a client this returns the currently estimated frame of all server objects we have received

Example: Predicting the next possible fire frame on the client using the estimated serverFrame.

1 void ClientFireWeapon(PlayerCommand cmd) {
2  if(weapon.nextFireFrame <= BoltNEtwork.serverFrame) {
3  state.Modify().FireTrigger();
4  weapon.nextFireFrame = BoltNetwork.serverFrame + weapon.refireRate;
5  }
6 }
float BoltNetwork.serverTime
staticget

The current server simulation time

Example: Using the serverTime property to display a message when the max game time has expired.

1 void Update() {
2  if((BoltNetwork.serverTime - gameStartTime >= MAX_GAME_TIME) {
3  Message.Show("Game Over", "Time Has Expired!");
4  }
5 }
Map<Guid, UdpSession> BoltNetwork.SessionList
staticget
float BoltNetwork.time
staticget

The local time, same as Time.time

Example: Using the time property to periodically play footstep sounds on the client.

1 void Footsteps() {
2  if(BoltNetwork.time >= lastFootstep + footstepInterval) {
3  audio.PlayOneShot(footstepSound);
4  lastFootstep = BoltNetwork.time;
5  }
6 }
UdpSocket BoltNetwork.UdpSocket
staticget