Plugin UI resets to default values on closing and Reopening plugin GUI

Hello,
Repro –
Launch the plugin
Tweak the UI parameters – sliders, combobox
close the plugin UI
Reopen the plugin – all changes values are set to default (only GUI changes are reset to default, Audio is still as edited values)

Trying to fix this issue, seen in PT, Ableton .
I followed this link, but couldn’t get much

All the parameters are added to the APVTS using AudioProcessorValueTreeState state { *this, nullptr }; method.

any help/suggestion is appreciated.
TIA!

When you write the logic to update the parameter yourself, it is your responsibility to read the value in the constructor and set it.
Because it is easy to make mistakes here, it is better to use the ParameterAttachment classes that juce provides. For the most common components like Slider, Button or ComboBox, there are specialised subclasses available, like SliderParameterAttachment etc.

The same classes exist for AudioProcessorValueTreeState, in case you use that one.

@daniel I’m using parameter attachments, and state(*this, nullptr, Identifier("ABC"), parameterLayout()) to add the parameters in APVTS.
Also when closing and reopening GUI, only the GUI is reset to default values, Audio still sounds like updated parameters.

This is strange, and should usually work.
What Components expose that issue?

One caveat is, if you add a ComboBoxAttachment to a ComboBox, before you added the options. The comboBox has no chance to set the value correctly, as the comboBox Item doesn’t exist yet.
Or when you use a Slider, don’t set the range etc. It is propagated automatically by the Attachment. If you set things manually, it could reverse the settings…

@daniel Thanks for pointing it out, yeah some of UI parameters were overwriting the ranges manually, that was fixed.
I have a following question regarding Combobox attachment, when we add it to the APVTS using

apvts.add(...., "parameterID", "Name", minVal, MaxVal, defaultVal) 

on Combobox then it sets the selected ID as minVal from this list, what if it shouldn’t select any?

If I understand the question right, you should add an option “undefined” to the list. The parameter has to have a value. But you can define one with that special meaning.

@daniel
ok, so setTextWhenNothingSelected() would not work in this case?

No, because the parameter will not allow the ComboBox to be unselected.
Like I said before, the parameter has to have a distinct value. You can define one as “unselected”, but it has to be still a valid selection