Unity
Last updated
Last updated
Follow these steps to quickly set up and start using Planetary Processing with your Unity game. For more detailed information on both the SDK and the server-side API, please visit our documentation.
We recommend using Unity’s most recent LTS release version. If you are using an older version, we recommend a minimum of 2022.3.23f1 for a successful integration.
Navigate to the games section of our web panel
Click Create Game in the top right
Provide the details of your game. Upon its creation, you will be taken to your Game Dashboard.
For this quick start, we will be using Anonymous Auth, which allows players to connect without a username and password. To enable this, navigate to the settings section of your Game Dashboard and enable Anonymous Auth as the Player Authentication Type within Game Settings.
Clone the git repository as listed in your game dashboard - this is your Planetary Processing backend code.
Create a new Unity project, from the Unity Hub.
Select the ‘Package Manager’ from the ‘Window’ tab in the topbar.
In the Package Manager, add the Planetary Processing package using the ‘Add package from git URL…’ option.
Input the following link, to install the Planetary Processing Unity SDK:
The Unity SDK provides two new components which can be added to GameObjects. These are PPMaster and PPEntity. These can be accessed in the 'Add Component' menu of any GameObject under the PP heading.
Create an empty GameObject. This will control which game server you connect to and sync the entities with the server.
Add the PPMaster component to this GameObject.
The PPMaster component will need to know three things: which object is the player, which prefabs represent the other players/entities, and the Game ID of the server.
Create a 3D GameObject to act as the player, such as a cube.
Add the PPEntity component to this GameObject.
The PPEntity component identifies entities in the game world. The main player character is the only entity which uses the PPEntity component but does not use a specific Entity Type.
Every Entity has a ‘Type’. These Entity Types are defined in the backend code downloaded from your game repository.
Navigate back to your cloned game repository.
Locate the ‘entity’ folder.
Make note of the names of the .lua files inside the ‘entity’ folder. These are your Entity Types.
For the demo game repository, the Entity Types: cat, tree, and player are used. But remember, the ‘player’ type is for representing other players in the game, not for the main player character.
Entities in Unity are formed from prefabs with the PPEntity component and a Type parameter. To make an Entity, download or create a prefab, then edit it to have the PPEntity component and a Type matching a Lua file.
To quickly make a prefab from scratch:
Create a 3D GameObject, such as a sphere.
Add the PPEntity component and input its Type. Entering ‘cat’ will sync this prefab with the ‘cat.lua’ entity in the server-side code.
Select this GameObject in the hierarchy window, then drag and drop it into the assets window to automatically convert it into a prefab.
Delete any instances of the prefab from your scene.
Create a prefab for every Lua file in your game repo’s entity folder.
Return to the empty GameObject you created first, with the PP Master component, and start filling in its parameters.
Connect your player GameObject (eg. a cube) into the ‘Player’ input.
Connect each of your prefabs to separate elements in the ‘Prefabs’ input list.
Enter the Game ID of your game. This is a number which can be found on your game dashboard, next to your game’s name and repo link.
Your server connection object now has all the info it needs to pass to the server. Now we just need a script to connect/login.
Add a script to your server connection object.
Use the example function below to establish a server connection on start.
You now have everything you need to establish a basic connection between Unity and the server-side demo code.
On the Planetary Processing games web panel, select your game to enter its dashboard.
Click Actions>Start Game to start the server-side simulation.
Launch your game from Unity.
In your Unity preview window, you should now be able to see the game world and all its entities. Your Planetary Processing game dashboard map should also show that a player has joined!
Basic player movement can use the regular Unity input system. However, instead of changing the position of the player GameObject, send a message to the server-side entity, telling it to update its position. Make a movement script and add to it the player GameObject, the code below can act as a guide.
Using the repo we cloned earlier you can edit the behaviour of entities by changing their Lua file within the ‘entity’ directory.
You can also change how many and what entities are spawned in the init.lua file.
We recommend experimenting here to get a sense of what you can do with Planetary Processing. When you add or change entities, make sure your server-side changes match up with your game engine client.
After configuring your game entities and logic, push your changes to the game repository:
Go back to your game dashboard in our web panel
From the actions menu in the top right, stop the game if it's running.
Select "Deploy Latest Version" - this will roll out your updated server-side code.
Start up your game again in Unity and in the web panel, to see the changes you have made!