#Understanding how to access components + variable types

1 messages · Page 1 of 1 (latest)

hardy cradle
#

I want to enable/disable "Analog Glitch Volume" and "Digital Glitch Volume" and modify their values (intensity, horizontal shake etc) via script. See screenshot below. I can't figure out how to get access to them. But beyond this specific case I'd like to learn how to get access to all values. Is there a trick? I THINK I need to use

[SerializeField] VolumeProfile volumeProfile;

I'm not sure if "Analog Glitch Volume" is a components. I'm not clear how to get their name nor their object variable type? For example I found someone use for depth of field :

DepthOfField dof;
if (volumeProfile.TryGet<DepthOfField>(out dof)) { depthOfFieldValue = dof; }

But I just don't understand how people know the names/variable types to use. If I can't get them from the inspector is there a list all of them available or something. I would appreciate any help.

viscid prism
#

The component name is usually this

#

And to find out how to get a specific profile from that you can check the documentation for Volume to see. The Volume component has a profile, and that profile has modules in it, so you'd use the component to get the profile to get the depth of field

hardy cradle
#

@viscid prism : Thank you for explaining. So I assume it is my choice if I add assign the volume or the volume profile to my script. If I add the volume I just have to get the volume profile as an extra step. Can I just ask for clarification on how to get the name of the component. Is it just the name I see without spaces?

hardy cradle
#

Here is the code I'm trying to get working. I'm still stuck on the same thing. I'm probably doing something really stupid but I don't understand how everyone figures the names/variable types out).

#
public class LoadingScript : MonoBehaviour
{
    public Volume volume;
    private XXXXX analogGlitch;
    private XXXXX digitalGlitch;

    private void Awake()
    {
        analogGlitch = volume.profile.GetComponent<AnalogGlitchVolume>();
        digitalGlitch = volume.profile.GetComponent<DigitalGlitchVolume>();
    }

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        StartCoroutine(AnimationSequence());
    }

    private IEnumerator AnimationSequence()
    {
        yield return StartCoroutine(StaticStart());
    }
    
    private IEnumerator StaticStart()
    {
        analogGlitch.intensity = 0.5f;
    }
}
#

A different approach...same issue

    private IEnumerator StaticStart()
    {
        XXXX analogGlitch;
        volume.profile.TryGet<AnalogGlitchVolume>(out analogGlitch);
        analogGlitch.intensity = 0.5f;
    }
gilded arch
#

It really is just reading the documentation. The docs for Volume show that there's a profile property and it is of type VolumeProfile. Opening the docs for VolumeProfile show that it has the components as a list in a field called components that's of type VolumeComponent. And again the docs for VolumeComponent show what you can do with those.

Volume volume = GetComponent<Volume>();

foreach (VolumeComponent component in volume.profile.components)
{
    Debug.Log(component.displayName);
}
#

And if you can't find the type name anywhere else you can print it with GetType().Name:

foreach (VolumeComponent component in volume.profile.components)
{
    Debug.Log($"{component.displayName}: {component.GetType().Name}");
}