Version: 2019.3
LanguageEnglish
  • C#

Sampler.Get

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static Profiling.Sampler Get(string name);

Parameters

nameProfiler Sampler name.

Returns

Sampler Sampler object which represents specific profiler label.

Description

Returns Sampler object for the specific CPU Profiler label.

You can use this function to get a Sampler associated with a built-in or custom label. The name parameter is the same you can see in Hierarchy view of the Profiler Window. If label with the specified name parameter does not exist or not available in the Player, an invalid Sampler object will be returned. You can use Sampler.isValid to verify if Sampler is valid.

using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour { Sampler sampler; void Start() { sampler = Sampler.Get("BehaviourUpdate"); } }

Get can be used to obtain any existing Sampler including custom Sampler. Return value is always Sampler type and can not be casted to CustomSampler.

Note: At the moment all built-in counters are available only in the Editor and Development Players. Get in non-Development Players returns invalid Sampler.

See Also: Sampler, Sampler.isValid, CPU Usage Profiler.