text: - Tutoriels
  - Game Performance Reporting
  - Getting Started with Game Performance Reporting
  Getting Started with Game Performance Reporting
  Vérifié avec version: 5.5
  -
  Difficulté: Débutant
  Introduction
  Unity Performance Reporting is a service that automatically collects and reports data about errors (known as exceptions) in our game.
  In this tutorial we will learn how to enable Performance Reporting in our game and how to view Performance Reporting data using the Unity Services Dashboard.
  Performance Reporting is available to Unity Plus and Unity Pro subscribers.
  Why is Performance Reporting useful?
  Exceptions can have many different causes and effects. Some are obvious and noticeable to players. For example, our game might freeze when trying to load a level. Other exceptions are more subtle and might not be noticed by a player. For example, our game might fail to connect to an online service. An exception might be caused by a bug in our code, a missing asset or an updated API for an online service. The more we know about an exception, the quicker we can act to fix it.
  When Performance Reporting is enabled in our project, we can use the Unity Services Dashboard to view realtime data about exceptions that our players are experiencing.
  We can see a great deal of information about exception in our game, including how many players are affected by the errors and what platforms and devices the errors occur on. We can also drill down into the data to find log messages, stack traces and data about individual exceptions. This detailed information about the cause and effect of exceptions in our game will help us to quickly identify, prioritise and fix the problems.
  Creating a Unity Project ID
  Before we can enable Performance Reporting in our game, we must set up a Unity Project ID (UPID) using the Services Dashboard. A Unity Project ID is a unique string that identifies our Unity project and allows us to use Unity Services.
  NB: If you already have a Unity Project ID, skip this step and go to Enabling Performance Reporting.
  Open the Services Dashboard in a browser.
  In the top right corner of the screen, click on the Create New Project button.
  Enter a project name, choose the organization the project will belong to, then click Create.
  Enabling Performance Reporting
  Now we need to enable Performance Reporting for our project in the Services Dashboard.
  Open the Services Dashboard in a browser.
  From the column of options on the left of the screen, choose Projects.
  Click on the name of the project to which you want to add Performance Reporting.
  Click on Enable Game Performance.
  Integrating Performance Reporting
  Now we need to integrate Performance Reporting into our Unity project. For projects made with Unity 5.4 and above, this is quick and easy. For projects made with Unity 5.3 and below, there are a few more steps.
  Integrating Performance Reporting (Unity 5.4 and above)
  To integrate Performance Reporting with a Unity project in Unity 5.4 or above, we simply need to link our Unity project to our Unity Project ID.
  In Unity, use the top menu bar to open the Services window (Window > Services).
  Choose I already have a Unity Project ID.
  Select the appropriate UPID from the list and click Link.
  The Unity project will now be linked to the UPID. Performance Reporting will be enabled.
  Integrating Performance Reporting (Unity 5.3 and older)
  To integrate Performance Reporting into a Unity project made with Unity 5.3 or older, we need to use the Performance Reporting package. Please note that this package will work only with Unity 5.3 and older.
  The first step is to download the Performance Reporting package.
  Download the Performance Reporting package here.
  Note the location of the downloaded file, as you will need to import it into your Unity project.
  Now we need to import the package.
  Open your project in Unity.
  Using the menu bar at the top of the screen, choose Assets > Import Package > Custom Package.
  Find and select the downloaded Performance Reporting package.
  Adding the Performance Reporting code
  The Performance Reporting project contains an example script. This script shows the two lines of code that are needed to enable Performance Reporting in our project.
  The first thing we need to do is find the UPID for our project. We can find the UPID in the Services Dashboard.
  Open the Unity Services Dashboard in a browser.
  From the column of options on the left of the screen, choose Projects.
  Click on the name of the current project.
  At the top of the screen, underneath the project name, you will find the UPID. Make a note of the UPID, or copy it to your clipboard using Ctrl+C (Cmd+C on MacOS).
  Next, we need to add the UPID to our example script.
  In Unity, use the Project window to navigate to Assets/Plugins/UnityPerf.
  Double click the script ThrowMeAnException.cs to open it.
  On line 11 of the script, select the text UPID goes here and press Ctrl+V (Cmd+V on MacOS) to replace it with your UPID. Your UPID should appear between the quotation marks.
  Save the changes to the script.
  We now have a working example of how to integrate Performance Reporting into our project.
  We can copy code from this example into our project’s existing scripts.
  The two lines of code that we need to copy are the using statement that allows us to use the CrashLog namespace, and the CrashReporting.Init() line that we just edited.
  In your project, find or create a C# script that runs on startup.
  Open ThrowMeAnException.cs.
  Copy line 3 of ThrowMeAnException.cs (using UnityEngine.CrashLog;) to your clipboard using Ctrl+C (or Cmd+C on MacOS).
  Paste the line into the top of your script, where the other using statements are by pressing Ctrl+V (Cmd+V on MacOS).
  Copy line 11 of ThrowMeAnException.cs (the call to CrashReporting.Init() that we just edited) to your clipboard using Ctrl+C (or Cmd+C on MacOS).
  In a function that runs on startup (such as Start() or Awake()), paste the line by pressing Ctrl+V (Cmd+V on MacOS).
  Save the script
  Performance Reporting is now integrated into our project, and every error will be logged.
  Viewing Performance Reporting data
  We can view Performance Reporting data in the Services Dashboard.
  To test this, we need to cause a run time exception to occur when testing our game in the Unity Editor.
  In your project, find a C# script and function where you would like the test error to occur. A good example would be a function that runs once the first screen has loaded.
  Add the following line to the function: throw new Exception("Test");
  Save the script.
  Enter Play Mode.
  An exception will appear in your Console.
  Open the Unity Services Dashboard in a browser.
  From the column of options on the left of the screen, choose Projects.
  Click on the name of the current project.
  Click on Performance Reporting.
  You will see information about the exception in the Services Dashboard.
  - Click on the exception message to expand the data.
  Listed is the stack trace, a timeline, and a list of versions, devices, and OSs that have hit the exception. By exploring this information, we can learn about the exception.
  Tutoriels apparentés
  - Variables and Functions (Cours)