Home > Net >  'VolumeProfile' does not contain a definition for 'TryGetSettings'"
'VolumeProfile' does not contain a definition for 'TryGetSettings'"

Time:08-04

I'm trying to change the DepthOfField.focusDistance. I've tried looking at a tutorial doing the same as me, but that didn't work either (https://www.youtube.com/watch?v=7od2j4s85ww).

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

public class CamControll : MonoBehaviour
{
    public LayerMask rayMask;
    public Transform camTransform;

    public Volume postProcess;
    DepthOfField depthOfField;

    void Start()
    {
        VolumeProfile profile = postProcess.sharedProfile;
        postProcess.profile.TryGetSettings(out depthOfField);
    }
    void Update()
    {
        RaycastHit hit;
        if (Physics.Raycast(camTransform.transform.position, camTransform.transform.forward, out hit, rayRange, ~rayMask))
        {
            //VolumeProfile.Depth;
            Debug.Log(hit.transform.name);
        }

CodePudding user response:

Try using the generic version TryGet<T>(out T property).

if (profile.TryGet<DepthOfField>(out depthOfField))
{
    Debug.Log($"TryGet<DepthOfField>() Success!");
}
  • Related