This is a thread for the load balancer I have released on the asset store (Unity Asset Store - The Best Assets for Game Making). I hope you find it well structured and documented and that the code is intuitive. If not feel free to tell me. I really appreciate constructive feedback.
Sorry for the delay, some reason my mail box filtered this threads alerts.
What kind of examples do you want to have?
A web player demo will be coming.
I have only tested this on PC. I will make a demo and if any one can test this and make a short video showing that it will work or explain why it doesn’t I will pay he money back(If you bought the asset and only once per person) to the first person per platform.
I have had an tremendous workload on my job, so i have not been able produce the tutorial more than 50 % through. I have the rest in my head finished though… :). Hopfully I will be done in about a week or two.
I think to have a few examples of how to use the threads would be more interesting for me.
If you have a very 1 or 2 very basic example then we can see how it works. Then 1 or 2 intermediate and then 1 or 2 more advanced. You don’t have to do all of the examples right away. The basic examples can come first, then add others later. Just my 2 cents.
I have followed your suggestion and made 3 demos in increasing difficulty. They are not super complex but focuses on different approaches and important things to keep in mind when threading. Thank you for the idea!
Will go over the code and make sure every thing is commented enough and then upload it on the asset store. So about a week till the videos are up and the stuff is on the asset store.
Manuscript and code done. Have pushed a first version to the asset store for review. Will however update it after the video is done with some minor bug fixes.
Purchased, tested but got an error when it’s integrated in my own project.
This error only occurs when using AddThreadedWork method. Do you have any idea on what is going on with this error?
Many thanks
My code is like this:
void Update () {
if (bD == BoundaryDynamics.Static) {
} else
if (bD == BoundaryDynamics.Dynamic) {
if (thisTransform.hasChanged)
LoadBalancerInterface.instance.AddThreadedWork
(GenerateOccupiedWorldCells,null,1f,false,ref o,false);
} else
if (bD == BoundaryDynamics.Deformable) {
}
}
void GenerateOccupiedWorldCells(object o){
OccupiedWorldCells.Clear();
boundInt4 = FFE_Grid.Instance.WorldBoundInt4(poly.bounds);
for (int x = boundInt4.minX;x<=boundInt4.maxX;x++){
for (int y = boundInt4.minY;y<=boundInt4.maxY;y++){
Vector2 pos = FFE_Grid.Instance.GetWorldPositionFromWorldIndex(x,y);
//transform the world pt into polygon's local space. because poly.poins is in local space
Vector3 pos2 = thisTransform.InverseTransformPoint(pos);
bool isInPoly = FFE_Math.PointInPolygon(pos2,polyPoints);
if (isInPoly){
OccupiedWorldCells.Add(new int2 (x,y));
}
}
}
}
Thanks, I found the reason, basically most of the Unity API cannot be used in another thread, besides “!=null”, I also used transform.InverseTransformPoint. After remove unity api calls, It works perfect with the LoadBalancer.
Nice plugin anyway!