Network Helper
To make a multiplayer game you need to take care of a few things. There's a special component that helps with those things, called NetworkHelper. This is a simple component that fits a lot of situations, but can be used as an example to code your own network component.
To make a multiplayer game you need to take care of a few things. There's a special component that helps with those things, called NetworkHelper. This is a simple component that fits a lot of situations, but can be used as an example to code your own network component.

Creating a server
If the StartServer property is enabled, a server will automatically be created when the scene is loaded. That is unless the network system is already active (because you're joining a server using this scene).
Player Spawning
When a player enters a server you need to create an object for them to control. If it's a racing game, you'd spawn them a car to control. If it's a shooter game, you'd spawn them a player.
Generally this is done using a prefab. You define your player gameobject and create a prefab, then you can drag the prefab object into the PlayerPrefab property on the component.
You can also define a list spawnpoint GameObject's. The player will spawn randomly on one of them. If you don't define any spawn points, they will spawn at the location of the NetworkHelper object.
Player Object
Your player object will usually contain a component with a function like this, which controls the GameObject if it isn't a Proxy.
protected override void OnUpdate()
{
// If we're a proxy then don't do any controls
// because this client isn't controlling us!
if ( IsProxy )
return;
// direction keys are pressed
if ( !Input.AnalogMove.IsNearZeroLength )
{
WorldPosition += Input.AnalogMove.Normal * Time.Delta * 100.0f;
}
// position the camera
var camera = Scene.GetAllComponents<CameraComponent>().FirstOrDefault();
camera.WorldRotation = new Angles( 45, 0, 0 );
camera.WorldPosition = WorldPosition + camera.WorldRotation.Backward * 1500;
}
Under The Hood
NetworkHelper works by implementing Component.INetworkListener. This interface contains a method that is called when a connection becomes active on the server.
In this method we create an instance of the PlayerPrefab and set the new client as its owner. The client receives the information about this new object, and the fact that they're the owner, and takes over from there.
Referenced API
Canonical API pages mentioned in this guide.
Euler angles. Unlike a Rotation, Euler angles can represent multiple revolutions (rotations) around an axis, but suffer from issues like gimbal lock and lack of a defined "up" vector. Use Rotation for most cases.
The backwards direction of this rotation.
No summary available.
A named input of a node. Inputs can connect to outputs of other nodes, or have a constant value. Use `!:SetLink(LinkSource)` to set which output this input links to, or `!:SetLinks(LinkSource[])` if this input can accept an array of values.
Gets and Sets a value from somewhere.
Every scene should have at least one Camera.
Access to the currently pressed path information
Allows querying of player button presses and other inputs.