Question by
etienneggallas · Dec 21, 2020 at 10:03 AM ·
c#robot
How to get Better Performance?
Hi, So I'm running a robot simulation in unity and have 300 robots shooting out 36 rays each every 0.02s (its a swarm simulation and i really need each robot to be truly independent), the rays are cast by the RayCastCommand and so are done in parallel, so this is causing no performance issues, however once I get the raycast results I need loop through them for to get the robots to avoid each other and communicate, the avoidance is again done in a parallel for loop so this is causing no issues. The problem comes from communication:
for(int i =0; i < Dirrs.Length -1; i++)
{
if (Dirrs[i].transform.tag == "Robot" && Dirrs[i].distance <= radius && !listID.Contains(Dirrs[i].transform.GetComponent<RobotControl>().ID))
{
listID.Add(Dirrs[i].transform.GetComponent<RobotControl>().ID);
Debug.DrawRay(origin + (0.55f* Directions[i]), Directions[i] * Dirrs[i].distance , new Color(Directions[i].x, Directions[i].y, Directions[i].z, 1));
}
}
This part of the cant be done in parallel since its accessing a transform to get the tag. Any ideas how it could be made more efficient? Thanks!
Comment