So I was trying to make utility structures in my C# Godot project and I ended up with a weird error that occured when rebuilding with these two classes:
`
[Tool]
public partial class TimeDuration : RefCounted {
[Export] public float startTime = 0;
[Export] public float Duration {
get => Time.GetTicksMsec() - startTime;
set {;}
}
public TimeDuration() : base() {;}
public void Start(){
startTime = Time.GetTicksMsec();
}
public static implicit operator float(TimeDuration timer) => timer.Duration;
}
[Tool]
public partial class BoolData : RefCounted {
[Export] public bool currentValue = false;
[Export] public bool lastValue = false;
[Export] public TimeDuration trueTimer = new();
[Export] public TimeDuration falseTimer = new();
[Export] public bool Started {
get => currentValue && !lastValue;
private set {;}
}
[Export] public bool Stopped {
get => !currentValue && lastValue;
private set {;}
}
public BoolData() : base() {;}
public void SetVal(bool value) {
if (currentValue) falseTimer.Start();
else trueTimer.Start();
lastValue = currentValue;
currentValue = value;
}
public static implicit operator bool(BoolData data) => data.currentValue;
}
`
The error goes as follows:
modules/mono/glue/runtime_interop.cpp:1324 - System.ArgumentException: An item with the same key has already been added. Key: TimeDuration
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)
at Godot.Bridge.ScriptManagerBridge.ScriptTypeBiMap.Add(IntPtr scriptPtr, Type scriptType) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.types.cs:line 23
at Godot.Bridge.ScriptManagerBridge.AddScriptBridge(IntPtr scriptPtr, godot_string* scriptPath) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs:line 419
Note: the issue happens without any existing instances of the said classes being used in the project, these classes just existing in the project triggers the error to appear.
This also happens if I make both classes inherit from Resource instead of RefCounted and if I remove the ToolAttribute.
I'm suspecting the issue comes from BoolData containing two instances of the same TimeDuration type, but I just might be unaware of some explicit limitation of GodotObject.