Question by
NekrosArts · Jun 04, 2020 at 12:51 PM ·
scripting problemscriptableobjectscriptable objectcomparison
IComparable for different scriptable objects
Hi, I load all scriptable objects into a list. Each SO has a "float fitness". The SO-Class, ("NeuralNetworkTemplate") implements the IComparable. My goal is to compare and sort them by their fitness. In my manager, I call the List of SO: networks.Sort();
Here is the CampareTo-function from "NeuralNetworkTemplate"
public int CompareTo(NeuralNetworkTemplate other)
{
if (other == null) return 1;
if (this.fitness > other.fitness)
{
return 1;
}
else if (this.fitness < other.fitness)
{
return -1;
}
else
{
return 0;
}
}
When I print them into the console, I can see that they are not sorted. Before I tried the same thing without scriptable objects. There was just a class NeuralNetwork and the sorting is working as expected. Has anyone an idea? Thanks in advance!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613000101im_/https://answers.unity.com/themes/thub/images/avi.jpg)