Unable to get parameter max value

Hi, I’m trying to access a parameter max value to use it in my code.
I found this topic looking through the forums, wich was really helpful: Read out parameter Min and Max value?.
I follow what I understand is the logical way to achive my goal, but I can not make it work.

I’m sharing my code:

    public void SetLevelParameter(int value, int maxValue)
    {
        int parameterMaxValue;
        PARAMETER_DESCRIPTION parameterDescription = default;

        musicInstance.getDescription(out EventDescription description);

        if (description.isValid())
            description.getParameterDescriptionByName(levelPN, out parameterDescription);
        else
            Debug.LogWarning("There is no description for music event");

        parameterMaxValue = (int)parameterDescription.maximum;

        float levelsPerTrack = maxValue / parameterMaxValue;
        int fixValue = Mathf.FloorToInt(value / levelsPerTrack);

        musicInstance.setParameterByName(levelPN, fixValue);
    }

I always get: “There is no description for music event” or an error saying that I can not divide by zero (this line: float levelsPerTrack = maxValue / parameterMaxValue;)

Any help on how to properly access parameter’s max value would be great!
Thanks.

In case anyone is looking to do the same, the code above works fine. I just needed to restart unity for some reason.

You first have to get Event Description of the event that contains the parameter you need:

EventInstance eventInstance;
EventDescription eventDescription;

eventInstance.getDescription(out eventDescription)

Get Parameter Description from Event Desctiption:

string parameterName = "Your parameter name";
PARAMETER_DESCRIPTION parameterDescription;

eventDescription.getParameterDescriptionByName(parameterName, out parameterDescription);

And then you can access parameter max and min values:

parameterDescription.maximum;
parameterDescription.minimum;
1 Like

Thank you for sharing your solution here!