docs.unity3d.com

    Get started with Friends

    Before using the Friends service in your project, you must link your project with the Unity Dashboard, enable the Friends service, and import the SDK.

    1) Link your project with the Unity Dashboard. 2) Enable the Friends service. 3) Import the Friends SDK.

    Link your project with the Unity Dashboard

    You must link your project with the Unity Dashboard to use the Friends service.
    1) In Unity Editor, click Edit > Project Settings... > Services.
    2) Link your project. 1) If your project doesn't have a Unity project ID: 1) Select Create a Unity Project ID > Organizations, then select an organization. 2) Select Create project ID. 3) If you have an existing Unity project ID to use: 1) Select Use an existing Unity project ID. 2) Select an organization and a project. 3) Select Link project ID.

    Your Unity Project ID now appears in Unity Editor, and the project is linked to Unity’s cloud services. You can also access your Unity Project ID in code using UnityEditor.CloudProjectSettings.projectId.

    Enable the Friends service

    You can enable the Friends service for your project from the Unity Dashboard.

    1) Sign in to the Unity Dashboard. 2) Select your project. 3) Navigate to Multiplayer > Friends. 4) You can enable Friends from the Overview page or by going through the Setup Guide.

    If you choose to go through the Setup Guide, it will walk you through linking your Unity project, installing the Friends package, and turning the Friends service on.

    Import the Friends SDK

    1) Sign in to the Unity Dashboard. 2) Select your project. 3) Select on the Project Settings. 4) Select Settings > SDK Download. 5) Select Friends from the list of available packages. Doing so also selects any package dependencies. 6) Select Generate Code Snippet. 7) Copy the code snippet that appears on the screen. 8) Paste the code snippet in your project’s Packages/manifest.json file, in the dependencies object. 9) Save the file. 10) Install the package through the Package Manager inside Unity Editor. See the Package Manager documentation. 11) Initialize the Core SDK using await UnityServices.InitializeAsync().

    Initialize the Friends service

    Once you’ve enabled the Friends service and imported the Friends SDK through the Package Manage in the Unity Editor, initialize the Core SDK using await UnityServices.InitializeAsync().

    The following code snippet shows how to initialize the Friends service along with any other Unity services in your project.

    // Import required packages
    using Unity.Services.Core;
    using Unity.Services.Authentication;
    ... 
    private async MyMethod()
    {
        // Initialize all of the used services
        await UnityServices.InitializeAsync();
    
        // Sign in anonymously or using a provider
        await AuthenticationService.Instance.SignInAnonymouslyAsync();
    
        // Start using the Friends SDK functionalities. 
        var friends = await Friends.Instance.GetFriendsAsync(new PaginationOptions());
    }
    

    Set configuration properties

    You can also initialize the Unity services in your project with configuration options. The following code snipper shows how to set configuration properties for initializing Unity services.

    ...
    using Unity.Services.Core.Environments;
    ...
    
    async void MyMethod()
    {
        // Set configuration properties
        InitializationOptions options = new InitializationOptions()
            .SetEnvironmentName("staging");
    
        // Initialize all of the used services with options
        await UnityServices.InitializeAsync(options);
    }
    
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023