LogoLogo
  • Introduction
  • sdks
    • Feature Comparison
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Quick Start
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Server Side
    • Entities
    • Chunks
    • Dimensions
    • Events
    • Logging
    • Lua Environment
    • Git Primer
    • Physics
  • HTTP API
    • Authentication
    • Player API
  • Api Reference
    • Entity API
      • Create
      • Message
    • Client API
      • Message
    • Dimension API
      • Create
      • Delete
      • List
    • Events API
      • on_player_join
      • on_player_leave
    • Table API
      • Append
      • Remove
      • Join
    • Util API
      • Time
      • TimeMillis
    • HTTP Request API
      • Get
      • Post
      • Put
      • Delete
    • Physics API
      • NewBody
      • NewBoxShape
      • NewSphereShape
Powered by GitBook
On this page
  • Installation
  • Components
  • Master Component
  • Entity Component
  • Chunk Component
  • Server To Client Messaging
  • API
  • PPMaster
  • PPEntity
  • PPChunk
  • Custom Scripts
  1. sdks

Unity

PreviousFeature ComparisonNextGodot

Last updated 9 days ago

The Unity SDK integrates our multiplayer platform with Unity. The plugin provides components and methods to use within your game client code - these communicate changes in state from your server side simulation to the game client itself.

If you are new here, we recommend starting with the .

Installation

The Unity SDK can be installed by opening the Unity Package Manager (Window->Package Manager) and clicking the + on the top left and selecting 'Add package from git URL...'

You then enter the GitHub URL of the PP Unity SDK repository, which is: https://github.com/Planetary-Processing/unity-sdk.git

And click 'Add' to add the package.

Components

Master Component

  • Player - Your local player will be represented by a GameObject.

  • Two Dimensions - Automatically adjusts entity positions to use Unity's 2D orientation.

Entity Component

Chunk Component

Server To Client Messaging

void ServerToClient(Dictionary<string, object> message)
    {
        message.TryGetValue("key", out object value);
    }

API

Below are reference tables of the API available within Unity's C# environment.

PPMaster master = GetComponent<PPMaster>();
PPEntity entity = GetComponent<PPEntity>();
PPChunk chunk = GetComponent<PPChunk>();

To connect to the server and join with the player, for example:

PPMaster master = GetComponent<PPMaster>();
master.Init("", "");
master.Join();

PPMaster

Method
Parameters
Return Type
Description

Init(username, password)

username: string password: string

None

Connect to and authenticate with the Planetary Processing servers.

Join()

None

None

Spawn the player into the world.

Message(msg)

msg: Dictionary<string, object>

None

Send a message to the player entity on the server, to be handled by the message function on the server side API.

GetEntity(uuid)

uuid: string

Entity

Get Entity details by UUID.

GetEntities()

None

List<Entity>

Get a list of all Entities that this client can see.

PPEntity

Method
Parameters
Return Type
Description

GetServerPosition()

None

Vector3

Get the server-side position of this entity. Particularly useful if you are not using the 'Use Server Position' feature. NOTE: Planetary Processing uses 'y' for depth in 3 dimensional games, and 'z' for height, the Unity SDK automatically swaps these.

GetServerData()

None

Dictionary<string, object>

Get the server-side data of this entity.

GetUUID()

None

string

Get this entity's UUID.

PPChunk

Method
Parameters
Return Type
Description

GetServerData()

None

Dictionary<string, object>

Get the server-side data of this chunk.

Custom Scripts

Method
Parameters
Return Type
Description

ServerToClient()

message: Dictionary<string, object>

None

Receives manual messages from the server. Must be assigned to a GameObject in the PPMaster inspector.

The Unity SDK provides three new components which can be added to GameObjects. These are the , , and components. These can be accessed in the 'Add Component' menu of any GameObject under the 'PP' heading.

represents the main connection point to PP's servers and performs the heavy lifting and orchestration of the SDK. You must have a GameObject in your game which has the Master Component.

To configure the Master Component you will need to set some references to GameObjects and Prefabs, in the inspector window.

Chunk Prefab - A Prefab with the to manage Chunks.

Prefabs - Each Prefab created with the the must be added to the Entity 'Prefabs' list in the inspector.

Game ID - The ID of your game from the , for Unity to connect to.

Chunk Size - The size of chunks in your game, defined in the game settings.

Server To Client Object - A GameObject which receives manual messages from the game .

represents a server-side entity in the game world. You are required to, for every of entity you wish to display in the Unity client, create a Prefab containing the component.

By default, entities' GameObjects will be moved to their server-side position, you can disable this per entity type by un-ticking 'Use Server Position' in the entity component's inspector window. Here you also need to set the entity's , which must match the server-side type that this Prefab represents.

Please note that the player is needed only for other players, not the one connecting with this client. For the local player, you need to create a separate GameObject (not in a prefab). The local player also requires a PPEntity component, but not a specific definition in the inspector.

represents each in the game world. Each chunk has a data table, which is synced down to the client with the component. To use this, you must create a Prefab with the component on it, which will be instantiated at the corner of each chunk and will hold its data.

The component automatically receives and syncs all data from the game world.

Messages can be manually sent to a specific client using . These message can be received by a designated . This GameObject needs a custom script component, with a function named , which receives the server message as a parameter.

The , , and components expose various public methods which can be accessed within MonoBehaviour scripts by getting a reference to the component like so:

web panel
web panel
Master
Entity
Chunk
PPMaster
PPMaster
Chunk Component
Entity Component
server to the client
chunk
PPChunk
PPChunk
PPChunk
Entity
PPEntity
api.client.Message()
Server To Client Object
ServerToClient
PPMaster
PPEntity
PPChunk
Unity Quickstart Guide
PPEntity
PPEntity
type
type
type
type
Unity component
Unity Entity Component
Unity Chunk Component