Heya,
I had been trying for the longest time to Query the child objects of different PropertyFields but was always end up with an empty result. I can query down to the actual property parent element itself, but no children. If I attempt to get a list of all descendants of a particular type such as ObjectField, I will get all of them, minus the ones that are child of a PropertyField.
You could clearly see that the elements exist in the hierarchy in the debugger, but at the time of Query (if you attempt to do it within CreateInspectorGUI(), that is), they are not found. This leads me to believe that they are not found because they simply have not been added to the hierarchy yet and are not added until after the CreateInspectorGUI() has completed?
What furthers the theory is that I found that delaying the query actually returns the expected results.
An example of this seen here:
VisualElement root;
public override VisualElement CreateInspectorGUI()
{
root = new VisualElement();
// -- This yields no results ----------------------------
root.Query("PropertyField:myPropertyField").Descendents<ObjectField>().ForEach(x => x.AddToClassList("WITHOUT_DEFER"));
// -- This works fine -----------------------------------
root.schedule.Execute(ExecuteDeferredTask).StartingIn(0);
return root;
}
private void ExecuteDeferredTask()
{
root.Query("PropertyField:myPropertyField").Descendents<ObjectField>().ForEach(x => x.AddToClassList("WITH_DEFER"));
}
The end result would be, all child ObjectField elements of the myPropertyField property would have the âWITH_DEFERâ class applied to them, but not the âWITHOUT_DEFERâ.
Is this intended?
A side effect of having to resort to this workaround, at least in one particular instance I have encountered, resulted in what would best be described as âelement poppingâ due to the action I was trying perform, not being able to be performed until after the tree was actually built.
Thanks,
-MH