Unity examples

This document gives access to a series of examples for the Unity platform. Following the tutorials linked below you will learn how to develop multiplayer games for the Overcast clustered environment.

The tutorials

Each tutorial examines a single example, describing its objectives and offering an insight into the SmartFoxServer features it wants to highlight, with a focus on the challenges posed by the clustered environment. Code excerpts are often provided, in order to better explain the approach that was followed to implement a specific feature.

The tutorials have an increasing complexity, from basic server connection to a full realtime game with authoritative server Extension, so we strongly recommend to read them in order.

  • Connector
    Learn how to deal with two connections, to the Lobby and to the Game Node, in a simplified user interface.
  • Lobby Mockup
    Lay the foundations for games running in a cluster environment, with multiple scenes sharing the connections to cluster nodes.
  • Tic-Tac-Toe
    Create a full multiplayer turn-based game implementing the well-known tic-tac-toe in the cluster environment.
  • SpaceWar2
    Recreate one of the earliest computer games in history, making it a full multiplayer realtime game for the cluster environment.

How to run the examples

The examples' clients can be run on your desktop computer, but they need an existing cluster running in the Overcast environment to connect to.

The cluster can be as simple as possible: the Lobby Node and a single Game Node. Detailed instructions on how to launch a cluster in Overcast are available in this document. Let's briefly recap how you should proceed:

  1. Access your Overcast account.
  2. Create a new application to host your cluster.
  3. Launch a server of type SmartFoxCluster Game and, when prompted, specify that it should not join the cluster.
  4. Take a snapshot of the newly created server, which will be used by the Lobby to launch the Game Node automatically.
  5. Launch a server of type SmartFoxCluster Lobby. When prompted, selected the previously created snapshot as Game Server Snapshot and set the Initial # of Game Servers field to 1.
  6. Run the client in the Unity Editor following the Setup & run chapter of each tutorial.

When needed, the tutorials will instruct you to deploy a server-side Extension on the running Game Node. This approach is taken for sake of simplicity and to let you test all the examples more easily, but the correct way to operate would be to deploy the Extensions on the server before taking its snapshot (step 4 above).
The reason is that, in a production environment, you want all Game Nodes launched by the automated Orchestration process to run your Extension, which of course can't be deployed manually on each node.

Before getting started

Before opening the examples' source projects and code, you should check the following general requirements and notes.


Unless otherwise noted inside the tutorials:

  • client side of the examples is provided as a Unity project: just open its folder with Unity (when opening for the first time, it will take a few seconds to Unity to regenerate the required libraries for the project);
  • all examples have been developed with Unity 2021.3, but the relevant multiplayer code is compatible with all versions of Unity starting form Unity 4 (NOTE: depending on the Unity version in which examples are imported, the DLL assignment to different platforms may get lost: if multiple errors CS0433 are displayed in the Unity Editor console, please follow the instructions above to re-assign the DLLs);
  • the server side Extensions of those examples which require one have been developed using Eclipse, but you should be able to use any Java IDE of your choice, provided you use Java 8 or later.

Unity build targets

All examples run seamlessly and are interoperable on all Unity build targets. For sake of simplicity, the examples have been developed for desktop usage (standalone or in a web browser), so they may have issues running on devices (i.e. lack of controls in games).

Please note that due to the different requirements of the Unity build targets, the SmartFoxServer C# API contained in the examples is made of two separate DLLs: a DLL specific for WebGL builds and a DLL for all other Unity target platforms (including the Unity Editor itself).
The examples use both DLLs, located in separate subfolders under the Plugins folder. Each DLL is assigned to its target by clicking on it and selecting one or more platforms in the Inspector panel as follows:

  • /Plugins/Unity/SmartFox2X.dll → all platforms excluding WebGL
  • /Plugins/Unity_WebGL/SmartFox2X_WebGL.dll and SFSWebSockets.js → WebGL only

Check this link for more information on the API setup.