-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ComponentPool ISortable.Sort - Wrong if- / else-if conditions #156
Comments
Hello, thanks for reporting this. You are totally right it seems I completely mixed up the indices :/ I will add a test to show the problem and fix it as soon as I can! |
Perfect, that would be great. I wrote up a minimal example, so you are able to reproduce the issue. World world = new World();
Entity entity1 = world.CreateEntity();
Entity entity2 = world.CreateEntity();
Entity entity3 = world.CreateEntity();
entity3.Set("Something else");
entity2.Set("Hi there!");
entity1.SetSameAs<string>(entity2);
Debug.Print(entity1 + ": " + entity1.Get<string>());
Debug.Print(entity2 + ": " + entity2.Get<string>());
Debug.Print(entity3 + ": " + entity3.Get<string>());
Debug.Print("--------");
world.Optimize();
Debug.Print(entity1 + ": " + entity1.Get<string>());
Debug.Print(entity2 + ": " + entity2.Get<string>());
Debug.Print(entity3 + ": " + entity3.Get<string>()); Which produces the output:
|
Thank you very much for fixing this issue! Do you have any recommendation in getting this version into our project? Will there be a new NuGet release in the near future or should we include the source code as a separate project directly into our solution? |
I should create a new version soon, I just want to do some documentation update before to close a couple more issues (no promise but hopefully tonight or tomorrow). |
Ah perfect, thanks for pointing out the CI version. I didn't knew that, that's great :) |
Hi Doraku,
I noticed a problem in our game where entities with components assigned with
SetSameAs<T>()
suddenly took the wrong component after running world.Optimize().After some debugging, I think I found the cause of this. In the ComponentPool class there is a function ISortable.Sort which contains the following code in lines 334 - 353:
The else branch is correct, so sorting components without additional references is handled correctly. However, if there are multiple references, you are iterating over the entire mapping table. There you want to update the outdated references into the component array. The if and else-if clause for this is wrong. I think the corrected code should read:
I hope you can have a look at it. Thanks a lot for your ECS system, we really enjoy working with it. Keep up the good work!
The text was updated successfully, but these errors were encountered: