ReferTo not updating value

Hi,

I have a label that sets it’s text value using the referTo method. This is set in the labels constructor and the initial value is correctly displayed when launching the plugin. Unfortunately the label text is not updating when the value it is referring to changes.

Here is the code:

The constructor of the Label

MyLabel::MyLabel(const String& name, State& myState): Label(name), myState(myState)
{
	getTextValue().referTo(myState.getValue());
}

The State class header

class State
{
public:

	const Value& getValue();

	void setValue(const Value& value);

private:
	
	Value myValue{ 1 };
};

and it’s .cpp

const Value& State::getValue()
{
	return myValue;
}

void State::setValue(const Value& value)
{
	myValue = Value(value);
}

In the Editor when a button is clicked the value is updated:

void AudioProcessorEditor::doSomething()
{
	auto val = myState.getValue();
	auto intVal = (int)val.getValue();
	auto newVal = ++intVal;

	myState.setValue(Value(newVal));
}

^^ I see that this correctly updates the value of myState when debugging but not the label text.

I can make the label text update by adding
label.setText(myState.getValue().toString(), NotificationType::dontSendNotification);
inside doSomething but I thought that using referTo should take care of this - it all works as expected if I connect the label to a property in the value tree in the same way.

I’m missing something here - any ideas? :slight_smile:

Ah, figured it out - I was creating a new Value object in the setValue method and changing the underlying object
:stuck_out_tongue: