Fastest way to draw thousands Circles each frame

Hello,

I have a game where i have objects changing position on each frame. I have their positions stored in an array and i want to draw a circle or a point or something at their last 200 positions for example giving an idea of their movement.

If i use the LineRenderer to connect these positions it’s very fast and works ok. But i now want it to be points and not a single line.

I tried to use Primitive.Sphere and Primitive.Cylinder but they are making my game very slow. And i do not instantiate them and destroy them at every frame.

I create them at the Start() function and then in Update() i just change their positions.

I tried two ways to check performance. Built in arrays where i change the position of every point at each frame Update. And LinkedLists where i have the points and i just change the position of the Last Node to the current one and i then remove it and Add it in the front.

Both ways are extremely slow and i would like an option to draw these points at each frame. I want around 2000-5000 points ( might want last 50-200 for each object ).

Start()

function initializeSpheres2(){

spheresList = new LinkedList.<GameObject>();



for( i=0; i<lengthOfLineRenderer; i++ ){

	var sphere = newSphere();

	spheresList.AddFirst( sphere );

}

}

Update

function updateSpheres2(){

var moveObj : moveObject = gameObject.GetComponent(moveObject);

var pos : Vector3;

var i : int;

var cNode : LinkedListNode.<GameObject>;



for( var sph : GameObject in spheresList ){

	sph.renderer.enabled = false;

}



// change the positon of the last sphere to the current one

pos = moveObj.waypoints[ moveObj.currentWaypoint ];

pos.y = -1F;

cNode = spheresList.Last;

spheresList.RemoveLast();

cNode.Value.transform.position = pos;

spheresList.AddFirst( cNode );



// enable only the necessary spheres

cNode = spheresList.First;

for( i=0; cNode != null; cNode=cNode.Next ){

	//if( i % distancePerPoint == 0 )

		cNode.Value.renderer.enabled = true;

	i++;

}

}

the function newSphere justs creates a sphere or a cylinder and sets its initial positions.

function newSphere(){

var sphere = GameObject.CreatePrimitive( PrimitiveType.Cylinder );

sphere.collider.isTrigger = true;

sphere.transform.position =  gameObject.transform.position;

sphere.transform.rotation =  gameObject.transform.rotation;

sphere.transform.position.y -= 1.0F;

sphere.transform.localScale.y = 0.025;

sphere.transform.localScale.x = 0.05;

sphere.transform.localScale.z = 0.05;

sphere.renderer.material.color = Color.red;

sphere.renderer.castShadows = false;

sphere.renderer.enabled = false;

sphere.transform.parent = gameObject.transform;

return sphere;

}

It’ll be the colliders that are killing your processor. Even when set to be triggers, every time you reposition one it will test against the physics scene to see what it is touching. Remove the collider component from your spheres and it’ll probably work fine.

Also, if you want thousands of small points, use cubes - far less polys and near-identical when very small onscreen.