Get Started
Peer to Peer scene
Variables in a P2P scene are managed by players. The server is only a relay between clients.
+ :
- The server is light/can manage a lot of instancies.
- A full P2P game does not require an update of the build. You can use a same server for many games.
- :
- More latency
- Hard to securize
Game/Scene type recommanded: PvE and non competitives games.
Create the scene
Create a component Wonderland/SimpleNet/Server
and configure it.
Configuration
Port: The TCP port; -1 to disable (for Websocket only) WPort: The Websocket port; -1 to disabled MinPlayersNumber: 0 : persistent world, 2 : party MaxPlayersNumber: max player number AutoCloseApplication: auto close if players number < MinPlayersNumber InstanceRemoveInterval: try to remove empty instance every.. Password: Unique password for your project PingShareLoopInterval: Send peers latency interval WaitForPeers: Auto kill server if player number < MinPlayersNumber after its creation; -1 = wait forever FPS: Frames per seconds limit; -1 to disable the set AutoDestroyGameObject: Replace application close with a GameObject destroy DataServerAddress: If you use a data server, you can set its address here DataServerPort: The data server port DataServerPsw: The data server password
Build your server
Create a Build profile like this example.
Host scene
A Host scene is hosted on server, with a physic simulation.
+ :
- Less latency
- You can check and validate variables to prevent cheats.
- :
- You must rebuild for each version of the game
- Servers configuration must be stronger to run scenes.
Game/Scene type recommanded: If the servers cost is not a problem, your game is competitive or you need less latency.
Create the scene / Configuration
Same as P2P.
Build
In place of the Server scene, set all Hosted scenes.
In the Server component, set this Build profile.
After, you can create a Buildable Host file to build this scene without opening it.
The buildable host can be added in a Build Profile List
Client Scene
NetManager
It is used to connect the client to a server, it can be added in all your client scene (it is automatically removed if it already exists).
NetScene
It manages GameObjects and scene instance.
NetworkedObject
In a scene, each GameObject is assiotiated to a connected client. When many players join a scene, all GameObjects are distributed to them and redistributed if a player joins or leaves.
To share a GameObject, append a NetworkedObject
behaviour to it. You can share variables, events or spawners in your own behaviours after that.
Configuration:
Associated
, this object will be cloned for each playerShared
, all variables share values of all players
Variables
Variables in your script work offline, online, in P2P or Host in the same way.
NetVar<float> _testA;
void Awake() {
_testA = this.NetVar<float>();
}
// ...
_testA.Value = true; // set value