Welcome to Friends
Explore the Friends service for managing player relationships and connections.
Read time 2 minutesLast updated 7 months ago
The Friends service allows you to boost player engagement by providing players with a social system that works well with other Unity services. With Friends, your players can:
- Send and receive friend requests.
- Build and manage friend lists.
- Block and unblock other players.
- The user sends a message to a friend.
Environments are logical partitions of Unity Game Services that contain data associated with your project. You can set the target environment in the Unity Dashboard and your initialization scripts.
The Friends API uses JSON Web Token (JWT) authentication. The Authentication SDK supports Anonymous authentication and Platform-specific authentication.
Understanding Friends
The Friends service manages relationships of different types. In general, most user relationships don’t change often; however, there are updates users often want to know about as soon as possible. To increase efficiency, the Friends SDK fetches all a user’s relationships one time at startup, then keeps the list up-to-date using push notifications.
The SDK sends change notifications as soon as the changes occur. User relationship changes that trigger a push notification include:
- A friend updates their presence status.
- Updates to the presence state for an individual user.
- The user adds a new relationship. A user creates a relationship.
FRIEND_REQUEST - The user removes a relationship, or a relationship is otherwise deleted.
FRIEND
The Friends service treats all relationships the same. You can use the various properties of each relationship to decide how to treat that relationship. Each relationship has one or more members (players), each of which might have extra properties that identify that member’s role in the relationship. For example, a relationship always has two members:
FRIEND_REQUEST- A member with a role (the sender).
SOURCE - A member with a role (the receiver).
TARGET
However, the member's role changes to when a relationship changes to a relationship.
NONEFRIEND_REQUESTFRIENDThe SDK provides some wrapper APIs for specific operations to increase the service’s usability.
For example, when you call the method, it calls the API and creates a new relationship with the target user.
SendFriendRequestAsyncCreateRelationshipFRIEND_REQUESTIf there’s already a relationship from the target user, it creates a new relationship. Depending on the state, can result in a or a new relationship.
FRIEND_REQUESTFRIENDSendFriendRequestAsyncFRIEND_REQUESTFRIEND