Search Issue Tracker
By Design
Votes
0
Found in
6000.0.29f1
6000.1.0a7
7000.0.0a1
Issue ID
UUM-90703
Regression
No
TrackPropertyValue callback stops being called when modifying PropertyField
Reproduction steps:
1. Open the attached “Hopeful Dumpster Fire.zip” project
2. Open the “Assets/Scenes/SampleScene.unity” Scene
3. Select the “TestScript” GameObject in the Hierarchy window
4. Open the “DamageSettings” field in the Inspector window
5. Change the “Value” field value to 50
6. Observe "On Property modified" being logged in the Console window
7. Enable "Put Value In Label" by clicking on the checkbox
8. Change the “Value” field value to 60
9. Observe the Console window
Expected result: "On Property modified" message is logged
Actual result: No message is logged
Reproducible with: 6000.0.29f1, 6000.1.0a7
Couldn't test with: 2021.3.46f1 (Could not resolve compilation errors), 2022.3.52f1 (NullReferenceException when enabling "Put Value In Label")
Reproducible on: Windows 11
Not reproducible on: No other environment tested
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Undoing Animator Parameter name change breaks references to it
- Crash on BV4_OverlapBoxAll when moving in play mode
- Custom mesh water surface normal map fades out when Y Position increases
- Sprite renderer does not issue draw calls correctly when using SRP Batcher
- [Android] Flickering artifacts when using "ScriptableRenderer.EnqueuePass(RenderPassEvent.BeforeRenderingPostProcessing)" multiple times
Resolution Note:
Hello,
The behavior you're experiencing is intentional. When the label of a PropertyField is changed, a Rebind is necessary to ensure everything is up-to-date. This is because labels are communicated to custom property drawers through the propertyDrawer.preferredLabel property, which won't update automatically in such situations. Additionally, users might have an IPrefixLabel control preceding the actual field, or they might display the same field multiple times. To address these scenarios, we force an update by rebinding the entire element whenever the label changes. A Rebind operation first performs a full Unbind, which means it removes all existing bindings, including TrackPropertyValue.
Unfortunately, maintaining your binding in this context isn't feasible. However, there is a workaround: you can attach your binding to a different element. Here is an example that demonstrates this approach:
```
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var parent = new VisualElement();
PropertyField field = new PropertyField(property, label: GetModifiedLabel(property));
field.name = "My Custom Field";
parent.TrackPropertyValue(property, (updatedProperty) =>
{
Debug.Log("Property has been modified");
string oldLabel = field.label;
string newLabel = GetModifiedLabel(updatedProperty);
if (oldLabel != newLabel)
{
Debug.Log("Updating label");
field.label = newLabel;
}
});
parent.Add(field);
return parent;
}
```
By attaching the binding to the parent VisualElement, you can monitor changes without interfering with the rebind process. This approach ensures that the updated label is set correctly without disrupting other functionalities.