I am trying to access a ValueTree strored in an object belonging to my MainContentComponent, from a component (InterfaceComponent) nested inside it.
Within the MainContentComponent I have an instance of a class (say MyClass) which contains a ValueTree,
I've declared a pointer in the InterfaceComponent as:
In the InterfaceComponent constructor I've defined:
main = static_cast<MainContentComponent*>(getTopLevelComponent());
However, if I try and access the ValueTree using the pointer
ValueTree valueTree = main->myClass.valueTree; log->writeToLog("numChildren:"+String(valueTree.getNumChildren()));
It seems to not be initialised, even though it passes the isValid() function - getNumChildren() returns a large random value (e.g. 27888).
I've just rearranged some code and it looks like the InterfaceComponent constructor is called before the MainContentComponent one, so that the object I am trying to share has not been initialised when the nested Component is trying to access it. I would expect the ValueTree to not be valid in this case.
Perhaps I am going about this a strange way, basically just want a way of sharing data across components.