#I use LocalizedString bindings and I
1 messages · Page 1 of 1 (latest)
Hey do you mind sharing some more details about this? Clearing and rebinding works fine for me, maybe im missing something?
I'm screwing around in an empty project and I can't replicate the issue.
Testing in the full project again there's certainly something going wrong... it's not an easy one to track down though, I've been debugging for an hour already 😓
If I change the code that calls SetBinding to .ExecuteLater(100); then it works. But that's not acceptable.
I have no idea why that would matter too! The element never leaves the hierarchy, it's just disabled and Display None. I can't replicate it in a simple project with similar states, and I'm not faimilar enough with the internal logic around bindings to debug it fully
The element is moved and I think it's TransferBindingRequests which has a bug
Hooray, bug found! Only took me like 2.5hrs 😫
<ui:UXML xmlns:ui="UnityEngine.UIElements" editor-extension-mode="False">
<ui:VisualElement name="Container">
<ui:Button name="TestButton" text="Button" />
</ui:VisualElement>
<ui:VisualElement name="TargetContainer" />
</ui:UXML>
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.UIElements;
public class Test : MonoBehaviour
{
[SerializeField] private UIDocument _document;
[SerializeField] private LocalizedString _localizedString1;
[SerializeField] private LocalizedString _localizedString2;
[SerializeField] private bool _moveToTargetContainer = true;
private static readonly BindingId s_textBinding = nameof(Button.text);
private async void Awake()
{
VisualElement root = _document.rootVisualElement;
VisualElement container = root.Q("Container");
VisualElement targetContainer = root.Q("TargetContainer");
var button = container.Q<Button>("TestButton");
button.SetBinding(s_textBinding, _localizedString1);
await Awaitable.WaitForSecondsAsync(1);
button.SetBinding(s_textBinding, _localizedString2);
if (_moveToTargetContainer)
{
targetContainer.Add(button);
button.style.backgroundColor = Color.red;
}
else
{
button.style.backgroundColor = Color.green;
}
}
}
If Move To Target Container is not true then the element is correctly bound to Localized String 2.
If it is true then it'll break and remain bound to Localized String 1.
IN-97312