public VariableField(Guid id) { guid = id; fieldName = $"worldvar-value-field-{worldVars.GetName(guid)}"; AddToClassList(USS_CLASS_NAME); label = new Label(worldVars.GetName(guid)); Add(label); // Create the type changer dropdown typeChoice = new EnumField(worldVars.GetType(guid)); typeChoice.AddToClassList("worldvar-type-dropdown"); Add(typeChoice); // Register type update callback on dropdown value change typeChoice.RegisterCallback <ChangeEvent <Enum> >(UpdateWorldvarType); // Add a type-specific class based on the current type AddToClassList(TYPE_CLASS_NAME_TEMPLATE + typeChoice.text.ToLower()); // Create a simple container to hold the value field fieldContainer = new VisualElement(); fieldContainer.AddToClassList("worldvar-value-container"); Add(fieldContainer); DrawValueField(); // Create a button at the end to remove the variable var button = new Button() { text = "-", name = $"remove-{worldVars.GetName(guid)}" }; button.AddToClassList("worldvar-remove-button"); // Method to actually remove it is the Remove() method so link that button.clickable.clicked += Remove; Add(button); // Register to collection change events worldVars.VariableRemoved += (guid) => { if (guid == id) { RemoveFromHierarchy(); } }; worldVars.GetVariable(guid).ValueChanged += SetFieldValue; worldVars.GetVariable(guid).NameChanged += SetLabelText; worldVars.GetVariable(guid).TypeChanged += OnTypeChange; }