プロジェクトを新規作成するとき、URPにするか、Built-inにするか、悩んでいませんか?
Built-in | URP(SRP) |
---|---|
![]() |
![]() |
実はBuilt-inとURP(SRP)、スクリプトから結構簡単に切り替えられるんです。
Built-inのシーン上に、URPのオブジェクト(左) と、Built-inのオブジェクト(右) を置きます
下記スクリプトを空のオブジェクトにアタッチし、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
[HelpURL("https://docs.unity3d.com/ja/2021.2/Manual/srp-setting-render-pipeline-asset.html")]
public class CoreUrpChange : MonoBehaviour
{
public RenderPipelineAsset exampleAssetA;
public RenderPipelineAsset exampleAssetB;
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
GraphicsSettings.renderPipelineAsset = exampleAssetA;
Debug.Log("Default render pipeline asset is: " + GraphicsSettings.renderPipelineAsset?.name);
}
else if (Input.GetKeyDown(KeyCode.B))
{
GraphicsSettings.renderPipelineAsset = exampleAssetB;
Debug.Log("Default render pipeline asset is: " + GraphicsSettings.renderPipelineAsset?.name);
}
}
}
Aは空に、BにURPのRenderPipelineAssetをセットします。
実行し、A、Bのキーを押すとBuilt-in,URPが切り替わります。
A | B |
---|---|
![]() |
![]() |