Unity 2020.3 URP - Loading PostProcessing Volume Profile at Runtime
Hi,
I am trying to switch global post-processing settings for my scene by loading PostProcessingVolumeProfiles into my PostProcessingVolume. Currently I have two Profiles - Test.asset and MegaBloom.asset. Switching the Profile in Unity Editor works flawlessly. In Script it does not work:
public class PostController : MonoBehaviour
{
[SerializeField] private Button _profileButton;
private Volume volume;
private void Start()
{
volume = gameObject.GetComponent<Volume>();
_profileButton.onClick.AddListener(ChangeProfile);
}
private void ChangeProfile()
{
VolumeProfile testProfile = new VolumeProfile();
testProfile = Resources.Load("Assets/Scenes/Core/MegaBloom.asset") as VolumeProfile;
testProfile.name = "MegaBloom";
volume.profile = testProfile;
Debug.Log("Post: " + volume.profile.name);
}
}
The profile has no effect (in this case changing the Bloom intensity) and trying to access the name member causes an exception: NullReferenceException: Object reference not set to an instance of an object
This seems to be a hint that the asset is not loaded as a VolumeProfile or the type of the asset should not be UnityEngine.Rendering.VolumeProfile but something different I have not found.
Thanks! Danny
Your answer
Follow this Question
Related Questions
Setting Lift-Gamma-Gain values from C# script? (URP, Post-Processing v2) 1 Answer
(URP) Problem with post-processing with overlay camera. 0 Answers
WINDOWS APP STORE crashed when building a Universal 10 app 0 Answers
Please help! Bloom doesn't work on android build with URP 1 Answer
URP graph node "Sample Sprite 2D", why it deforms my sprite? 1 Answer