Version: 2022.2
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

Declaration

public static Profiling.Sampler Get(string name);

Parameters

name Profiler 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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961