- Home /
ChangeEvent callback called twice
Hey folks, sorry for my crappy english. I will try to do my best to explain my problem.
Im making a custom inspector using the new Unity UI api. I have a very simple working progress UXML:
<?xml version="1.0" encoding="utf-8"?>
<engine:UXML
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:engine="UnityEngine.UIElements"
xmlns:editor="UnityEditor.UIElements"
xsi:noNamespaceSchemaLocation="../../../../../../../UIElementsSchema/UIElements.xsd"
>
<engine:VisualElement name="EmptyActionList">
<engine:Label text="Add an Action..."/>
</engine:VisualElement>
<engine:VisualElement name="NotEmptyActionList">
<engine:Foldout text="Action List"/>
</engine:VisualElement>
<engine:VisualElement name="newActionForm">
<engine:VisualElement name="actionTypesContainer"/>
</engine:VisualElement>
</engine:UXML>
And Im trying to add a Popup field to actionTypesContainer VisualElement and register a callback for the ChangeEvent event. Here the important snippet of code:
List<string> types = new List<string> { "Navigate To", "Show Message" };
PopupField<string> actionTypesPopup = new PopupField<string>("Types", types, 0);
actionTypesPopup.RegisterCallback<ChangeEvent<string>>((evt) =>
{
Debug.Log($"From {evt.previousValue} to Selected: {evt.newValue}");
});
VisualElement typesContainer = template.Q<VisualElement>("actionTypesContainer");
typesContainer.Add(actionTypesPopup);
The problem is this callback is called twice when I select some option from the popup field and I cant figure out why.
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613031943im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there any way to create folders in the heirarchy to group objects? 1 Answer
How can I use a GUIStyle in a Custom Editor which is set within that Custom Editor? 1 Answer
In search of a gradient editor tool.. 0 Answers
Scene view controls locking up > trying to make scene view generic menu on right click 0 Answers
Editor Scripting: best way to change variables of a custom editor? 2 Answers