I am making a custom element and noticed that there was some kind of auto generated code that seems to give it some default values. I’m not sure what it does exactly but I’ve had some initialization issues with it.
I got it to refresh by deleting the Library folder but is there a faster/simpler way?
Well, I have made a kind of dropdown field adapted for gamepad, so just a label with 2 buttons left and right. I’ve had issues with the choices field because when I started I hardcoded them in the custom element, something like:
private List<string> m_Choices = new List<string>() {"one", "two", "three" };
Then even after I deleted this initialization it kept using it, and the Debug Console message was mentioning a Generator file which I didn’t find anywhere. Unfortunately I can’t remember the exact details.
Now I have an issue with SetValueWithoutNotify() triggering a ChangeEvent:
public override void SetValueWithoutNotify(string newValue)
{
Debug.Log("setting value without notify");
base.SetValueWithoutNotify(newValue);
m_Index = getChoiceIndex(newValue);
m_Selection.text = newValue;
}
The thing is before I used index vs m_Index and that could be the reason for the bug:
[UxmlAttribute]
public int index
{
get
{
return m_Index;
}
set
{
Debug.Log($"setting index {value}");
if (value != m_Index)
{
m_Index = value;
if (m_Index >= 0 && m_Index < choices.Count)
{
Debug.Log("assign value");
this.value = getChoice(m_Index);
}
else
{
Debug.Log("assign value");
this.value = string.Empty;
}
}
}
}
But now I have fixed that and the error persists so I wanted to know how to delete the generator file. It seems that it was not in Library I can’t remember how I fixed it the first time.
You should not need to delete the generator file, it gets updated when your code changes.
The new system will take this as the default value private List<string> m_Choices = List<string>() {"one", "two", "three" };
If it’s still using it after you deleted it then that’s a bug, so please file a bug report so we can get it fixed.
Thanks, but I have fixed that one, the actual issue is with SetValueWithoutNotify, and since I’m in the dark concerning this generator file I can’t make a side project to send as bug report.
My file is not in Assets/Scripts but in Assets/PackageName/Scripts if that may help debugging on your side.
I’m not sure that my actual issue is related to the generator, this is what I wanted to check. Anyway I have deleted Library, obj and the cache folders in AppData and the issue persists so it’s probably unrelated even though it makes no sense that the ChangeEvent is triggered like that.
For the previous issue that is fixed, it was with a previous version of Unity I’m not even sure that it is still an issue and I can’t remember the exact steps on how to reproduce it. All I remember is that I had an error at the initialization and it was mentioning a generator file that I could not find anywhere. I probably should have sent a bug report at that time though.
Label implements INotifyValueChanged<string> explicitly.
So you need to do ((INotifyValueChanged<string>) m_Selection).SetValueWithoutNotify(newValue);