2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】SRPとBuilt-in Render Pipelineをランタイムで切り替える

Posted at

はじめに

以前,Scriptable Render Pipelineを自作する記事を書きました.
【Unity】SRPを自作して独自の描画フローを構築する

この記事を書いている際に,Bilt-in Render Pipeline(以降Built-in)で作られている既存のプロジェクトの一部(インゲーム部分とか)にのみ自作SRPを適用することができれば便利だと思い方法を調べました.

方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class RuntimePipelineSwitcher : MonoBehaviour
{
    [SerializeField]
    private RenderPipelineAsset pipelineAsset;

    private RenderPipelineAsset renderPipelineAsset;

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.S))
        {
            if (renderPipelineAsset == null)
            {
                renderPipelineAsset = pipelineAsset;
            }
            else
            {
                renderPipelineAsset = null;
            }

            GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
        }
    }
}

結論, UnityEngine.Rendering 名前空間の GraphicsSettings.renderPipelineAsset を変更することで実現できます.
RenderPipelineAsset を継承した自作のPipelineAssetをセットします.また,nullを代入するとBuilt-in Render Pipelineに切り替わります.

// 独自のSRPに変更する
GraphicsSettings.renderPipelineAsset = renderPipelineAsset;

// Built-in に戻す
GraphicsSettings.renderPipelineAsset = null;

最後に

短くなりましたが以上です.簡単に描画フローを切り替えられるので,使い方によってはすごく便利かと思います.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?