Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

GraphicsSettings.TrySetCurrentRenderPipelineGlobalSettings

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 Boolean TrySetCurrentRenderPipelineGlobalSettings(UnityEngine.Rendering.RenderPipelineGlobalSettings asset);

Parameters

Parameter Description
asset The RenderPipelineGlobalSettings asset to activate for the project.

Returns

Boolean Returns true if the asset was not null and Unity successfully applied the settings.

Description

Attempts to set the active RenderPipelineGlobalSettings at runtime.

This method lets you assign the RenderPipelineGlobalSettings asset at runtime. Use this method when you need to activate a RenderPipelineAsset but its corresponding RenderPipelineGlobalSettings wasn't active when the project was built. This can occur if the project was built with no Scriptable Render Pipeline active, or if it was built with settings for a different pipeline.

For example, if you load a Universal Render Pipeline (URP) RenderPipelineAsset and its RenderPipelineGlobalSettings from an AssetBundle at runtime, you must first call this method to activate the URP global settings. You must do this before assigning the URP asset to QualitySettings.renderPipeline. Attempting to assign the asset without its compatible global settings active will result in an InvalidOperationException.

Note: This method only works at runtime. You can't use it in the Unity Editor. Calling it from the Editor results in an error log message and the method immediately returns false.

At build time, Unity inspects the RenderPipelineGlobalSettings and RenderPipelineAsset assigned in Quality settings to ensure the right resources are built. If you use this API, you must also ensure that the right resources are built.

using UnityEngine;
using UnityEngine.Rendering;

public class RuntimePipelineActivator : MonoBehaviour { // In a real scenario, Render Pipeline Global Settings and Render Pipeline Asset would likely be loaded from an AssetBundle. // For this example, assign them in the Inspector manually. public RenderPipelineGlobalSettings newGlobalSettings; public RenderPipelineAsset newPipelineAsset;

void Start() { if (newGlobalSettings == null || newPipelineAsset == null) { Debug.LogError("The new Render Pipeline Global Settings or Render Pipeline Asset has not been assigned."); return; }

// To activate a dynamically loaded pipeline, you must first set its corresponding global settings. // This call will fail if run in the Editor. bool settingsSet = GraphicsSettings.TrySetCurrentRenderPipelineGlobalSettings(newGlobalSettings);

if (settingsSet) { Debug.Log("Successfully applied new Render Pipeline Global Settings.");

// Now that the correct global settings are active, it is safe to assign // the new render pipeline asset. QualitySettings.renderPipeline = newPipelineAsset; Debug.Log($"Activated Render Pipeline: {QualitySettings.renderPipeline.name}"); } else { Debug.LogError("Failed to set Render Pipeline Global Settings. This may be because you are running in the Editor, or the asset was null."); } } }

Additional resources: QualitySettings.

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