by Pivec Labs
Getting Started Setup guide

Getting Started

Walk from a fresh Unity project to a running NetCrafter schema that generates working multiplayer network code.

1

Install the asset

Import the NetCrafter .unitypackage into your project via Assets → Import Package → Custom Package. After import the following structure will appear under Assets/PivecLabs/NetCrafter/:

Directory
Documentation/      — these docs
Editor/             — editor window and code-generation tools
Examples/           — example schemas
Plugins/x86_64/     — NetCrafterNative.dll (Windows only)
Scripts/            — ScriptableObject definitions
Templates/          — built-in code templates
2

Open the NetCrafter editor window

Unity Menu
Unity menu → Tools → Pivec Labs → NetCrafter Pro

The window opens with four top-level sections in the toolbar: Definition, Code, Scenes, and Settings. Resize it to at least 1100 × 650 if controls appear clipped.

3

Create a schema (Definition)

A Definition is a named collection of messages, events, models, and server actions. Each definition generates its own isolated set of C# files.

  1. In the schema bar at the very top of the window, click Create Definition.
  2. Name it (e.g. MyGame). A folder is created at Assets/PivecLabs/NetCrafter/Definitions/MyGame/.

You can switch between definitions using the dropdown in the schema bar.

4

Configure SmartFox settings

Click Settings in the top toolbar, then SmartFox Settings in the sidebar.

FieldValue to set
HostYour server IP or localhost for local testing
TCP Port9977 (SFS3 default)
Zone NameThe zone name defined in your SFS3 zones.xml

Leave all other fields at their defaults for now. Click Save Settings.

5

Define a model (Data Definition)

Models are plain data classes that can be nested inside messages and events. Create a PlayerState model:

  1. Click Definition in the top toolbar, then Data Definitions in the sidebar.
  2. Click Create Data Definition. Name it PlayerState.
  3. Add fields:
NameType
positionVector3
healthint
usernamestring
isAlivebool
6

Define a message (ClientToServer)

Messages sent from the client to the server generate a {Name}Request class with a Send() method.

  1. Click Definition → Messages in the sidebar.
  2. Click Create Gameplay Message. Name it PlayerMove.
  3. Set Direction to ClientToServer.
  4. Set Server Handler Name to HandlePlayerMove (this must match a Server Action you add next).
  5. Add fields:
NameType
playerIdPlayerId
positionVector3
speedfloat

Add a matching Server Action

  1. Click Server Actions in the sidebar.
  2. Click Create Server Action. Set Handler Name to HandlePlayerMove.
7

Define an event (ServerToClient)

Events sent from the server to the client generate a {Name}Event class with a static FromSFSObject() factory.

  1. Click Messages in the sidebar. Click Create Gameplay Message.
  2. Name it PlayerStateUpdate. Set Direction to ServerToClient.
  3. Set Server Handler Name to HandlePlayerStateUpdate.
  4. Add a field: name state, type string.

To use a nested model type such as PlayerState as a field type, open the generated .asset file in a text editor and set type: PlayerState directly. The editor field-type dropdown currently shows only primitive types.

Add a matching Server Action with handler name HandlePlayerStateUpdate.

8

Run Generate All Files

  1. Click Code in the top toolbar, then Build Code in the sidebar.
  2. Click Validate Definition first to confirm there are no errors.
  3. Click Generate All Files.

Generated files appear in:

Path
Assets/PivecLabs/NetCrafter/Definitions/MyGame/Generated/Client/
9

What was generated

For the schema above, the generator produces:

FileDescription
PlayerMoveRequest.csSend a PlayerMove message to the server
PlayerStateUpdateEvent.csReceive a PlayerStateUpdate event from the server
PlayerState.csSerialisable data model
SmartFoxConnectionManager.csMonoBehaviour that manages the SFS3 connection
10

Set up your scene

The Scene Assistant automates the boilerplate of wiring a multiplayer scene.

Create the ConnectionManager prefab

  1. Click Scenes in the top toolbar, then Prefab Generator in the sidebar.
  2. Click Create ConnectionManager Prefab.

The generator finds the SmartFoxConnectionManager.cs in your Generated/Client/ folder, wraps it in a prefab, and saves it to Generated/Prefabs/ConnectionManager.prefab. If the script is not found, generate client code first (step 8).

Create the scene

  1. Click Scene Assistant in the sidebar.
  2. Confirm the green banner shows that the prefab was found.
  3. Optionally enable Add Event Dispatcher — this adds a NetCrafterEventDispatcher GameObject that lets any script subscribe to server events without touching the generated file (see step 13).
  4. Click Create Multiplayer Scene.

The assistant creates a new scene containing:

  • A Main Camera
  • A ConnectionManager GameObject (instantiated from the prefab)
  • An EventDispatcher GameObject (if the toggle was enabled)
  • A NetworkManager empty GameObject (reserved for future use)

The scene is saved to Definitions/{Name}/GameScene.unity and opened in the editor. You can rename it using the Scene Name field before clicking Create.

Add to an existing scene

If you already have a scene open, click Add to Existing Scene instead. This adds only the ConnectionManager (and EventDispatcher) — it does not add a camera or NetworkManager. If a ConnectionManager is already present, a confirmation dialog appears before a second one is added.

11

Add the ConnectionManager to a scene manually

If you prefer not to use the Scene Assistant:

  1. Create an empty GameObject in your scene. Name it ConnectionManager.
  2. Attach the generated SmartFoxConnectionManager component to it.
  3. Verify the Host, Port, and Zone Inspector fields match your server.

The ConnectionManager is a singleton with DontDestroyOnLoad. It calls sfs.ProcessEvents() each frame and sends a guest login on successful connection. Call Connect() from a script when the game starts:

C#
void Start()
{
    SmartFoxConnectionManager.Instance.Connect();
}
12

Send a request

Populate the generated request class and call Send():

C#
using PivecLabs.MyGame.Generated;
using Sfs3.Client;

public class PlayerController : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            var request = new PlayerMoveRequest
            {
                playerId = SmartFoxConnectionManager.Instance.Sfs.MySelf.Id,
                position = transform.position,
                speed    = 5.0f
            };
            request.Send(SmartFoxConnectionManager.Instance.Sfs);
        }
    }
}
13

Handle an event

Option A — Fill in the generated stub. Open SmartFoxConnectionManager.cs and complete the stub method:

C# — Option A
private void OnPlayerStateUpdate(PlayerStateUpdateEvent ev)
{
    // ev.state is a deserialized PlayerState object
    Debug.Log($"Player at {ev.state.position}, health {ev.state.health}");
}

Option B — Subscribe via EventDispatcher. From any MonoBehaviour in the scene, subscribe to the event by command name. This approach does not require editing the generated file:

C# — Option B
private void OnEnable()
{
    NetCrafterEventDispatcher.Instance.Subscribe("PlayerStateUpdate", OnPlayerState);
}

private void OnDisable()
{
    NetCrafterEventDispatcher.Instance.Unsubscribe("PlayerStateUpdate", OnPlayerState);
}

private void OnPlayerState(object payload)
{
    var ev = (PlayerStateUpdateEvent)payload;
    Debug.Log($"Player at {ev.state.position}, health {ev.state.health}");
}

Both options can be used simultaneously — the dispatcher fires first, then the stub. See the API Reference for full EventDispatcher details.

Next

Next steps

  • See the Manual for a complete reference of every tab and setting.
  • See the API Reference for the full generated class API.