Friends sample
Before continuing, download and install the Unity Hub and a supported version of the Unity Editor. The Friends service supports the following Unity Editor versions:
- Version 2021 or later
- Supports UI Toolkit and Unity GUI
- Version 2020.3 or later
- Supports Unity GUI
Download the sample project
Download the Friends sample project from GitHub and open it in a supported version of the Unity Editor. You’ll want to have the sample project open while you enable the Friends service.
Enable the Friends service
- Log into the Unity Cloud Dashboard. If you don’t already have an account, refer to Get started with Unity Gaming Services (UGS).
- Go to Products > Friends.
- Select Launch.
- If you haven’t already added your payment information, the Unity Cloud Dashboard might prompt you to add your payment information. Friends is a pay as you go service with a free tier.
- Continue onto the Setup Guide, which walks you through setting up your Friends project.
Link your Friends project with the Unity Editor
Note: You can skip this step if you've already linked your project through the Unity Engine. You can also link your project after enabling the Friends service.
- Follow the instructions at Link your project in the Unity Editor.
- Select Next in the Setup guide.
Install the Friends package
- You can use Unity Editor version 2021 or later or version 2020.3 or later. Select the version you want to use in the Setup guide on the Unity Cloud Dashboard, then follow the instructions.
- When you’re finished, select Next in the Setup guide.
Turn Friends on
- Activate Friends by toggling the button in the Setup guide to On. Once activated, players can send friend requests to other players and build a friends list.
- Select Finish.
Note: If you meet any conflicts with other services, deactivate the Friends service. You can turn Friends on or off at any time.
Running the sample in-Editor
Use the following instructions to set the sample up locally:
- Launch the Unity Hub.
- Select Open > Add project from disk.
- Select the sample project location on your local disk, then select Add Project.
- The sample project will appear listed in the Unity Hub with the correct Editor version. Double-click the project to open it. You might have to wait several minutes for Unity to launch the project.
Drag and dropping the assets into your project
This sample works as a plug-in to your project. It gets you up and running with Friends in no time at all!
Get the assets
Either drag the entire Assets/FriendsSample/
folder from the sample project into your project, or export the folder as a .unitypackage
.
Resolving dependencies
This project depends on two non-standard Unity package dependencies:
- Friends Service SDK
- Get this by going to the Package Manager (Window > Package manager)
- Hit the little + Icon in the top left corner of the window and select Add package from Git URL or Add package by name.
- Type in : com.unity.services.friends
- TextMesh Pro Essential Resources
- Get this by going to Window > Textmesh Pro > Import TMP Essential Resources
Using the sample assets
For 2020.3, the sample supports Canvas-Style UI and for 2021.1+, the sample supports UIToolkit style UI. Study the sample scenes to view the Hierarchy and general setup. You can also drag the RelationshipsManager into any scene and the UI will display it and work.
Play with the sample project
At this point, you have the sample project open in the Unity Editor. It’s time to interact with the sample.
Note: If you haven’t already, log into the Unity Editor and link your Unity project before continuing.
The sample project consists of a simple user interface that allows you to interact with the Friends service and perform actions such as:
- Send a friend request
- Accept a friend request
- Ignore a friend request
- Block a player
- View your friends list
- View your block list
- Unblock a player
- Remove a friend
- Set your presence status
Use the following table as a reference for the meaning of buttons and user interface elements.
Button name | Description |
Decline(×) | Decline a friend request |
Accept (✔) | Accept a friend request |
Block (-) | Block a player |
Unblock | Remove a player from your Block list |
Remove | Remove a player from your Friend list |
Friends list | A list of all the players you’re friends with |
Block list | A list of all the players you’ve blocked |
Friend Request List | A list of incoming friend requests |
Start the project
You must start the sample Scene before you can interact with the sample user interface.
- From the Project tab, select Assets > Scenes.
- Double-click the FriendsSampleUGUI scene or the FriendsSampleUIToolkit scene.
- Start the scene by entering the Play mode in the Unity Editor.
After the scene launches, the sample Friends user interface will display.
Testing the project
To test this project alone, you must have the Unity Editor open and a build of the project open.
- Open the Build Settings (File > Build Settings).
- Select a build to the platform of your choice. (Tested on Windows and macOS.)
- Make sure one of the sample Scenes is the top scene included.
- When complete, run the Build and Editor at the same time.
Send a friend request
You can send a friend request to another player using the player’s ID and the Add Friend button.
- Copy the Player ID from the project.
- Switch to a build of the project.
- Select the Add Friend button.
- Paste the ID of Project Player into the ID field, then select Add.
- Go back to the Unity Editor.
- Select the Friend Request List button.
- Accept or Ignore the friend request from Build Player.
Block a player
If a player has blocked you, they will appear as offline to you. If you block a player, they will appear in your block list.
There are two ways to block another player: from your friends list and from your friend request inbox.
Block a player from your friends list:
- Select the Friends list button.
- Select the Block (-) button next to the name of the player you want to block.
Block a player who sent you a friend request:
- Select the Friend Request list button.
- Select the Block (-) button next to the name of the player you want to block.
You can view and unblock blocked players in your block list.
Unblock a player
You can unblock a player by viewing your block list, then selecting the Unblock button next to the player’s name.
Remove a friend
You can remove a friend from your friends list by selecting the Remove friend button next to the player’s name in your friends list.
- Select the Friends list button.
- Select the Remove friend button.
Set your presence status
You can set your presence status by selecting the down arrow next to your current status, then selecting the new status. For example, to change your status from ONLINE to BUSY:
INVISIBLE is a special status, that makes you appear offline to all your friends.
- Select the down arrow next to ONLINE.
- Select BUSY.
Set your Activity status
You can set your activity status by selecting the text to the right of the Presence dropdown. For example, you can set custom statuses based on the player's activity in the game they're currently playing.
- Select the In Friends Menu text. This is the default activity status
- Type a new message, then press the Enter key. After pressing the Enter key, users on your friend list can see the updated activity status.
Note: The Friends service doesn't automatically save presence or activity when the user goes offline. To support persisting the same presence or activity when logging back on, save the presence or activity locally or via a data storage service like Cloud Save.
View your friends list
You can view your friends list by selecting the Friends List button.
View your request list
You can view your friend request list by selecting the Request list button.
View your block list
You can view your block list by selecting the Block list button.