A Delay In Reponse

Hi there,
Is there anyway a List, gathering, and removing items, no more than 50 at a time (of renderers), would cause any type of choke, a performance choke?

The reason I ask, is, I have a system which gathers a list of renderers when triggered (takeDamage()). This system works fine, but with each successive hit, the removal of the list items, (rednerer.enabled = false), delays. So, first hit, fine. Second hit, slight delay, third hit a greater delay and so on.

Can some one look at this code and see if they can notice anything?

Thanks

	public void handleDamage(float damageGiven){
		print("////////////////////" + Time.time);
		print("TIME A " + Time.time);
		///gather damage taken
		energyUsedTotal += damageGiven;
		//apply it to 100% ratio
		energyUsedRatio = energyUsedTotal/energyLimit;
		//determine the nodes of energy bar to remain enabled and disabled (renderer)
		if(energyUsedRatio >= 1f){
			///if here, brain has died. 
			killPlayer();
		}
		for(int i = 0; i < energyNodesLength; i++){
			if((float)i / (energyNodesLength - 1) > energyUsedRatio){
				energyNodes[i].enabled = true;
			}
			else{
				//add this node to a list.
				healthBarAnimList.Add(energyNodes[i]);
				print("//////healthBarAnimList.Count " + healthBarAnimList.Count + " " + Time.time);
			}
		}
		//now animate the healthBarAnimList down.
		print("///INVOKGING ANIM HEALTH BAR " + Time.time);
		InvokeRepeating("animateHealthBarAnimListDown", 0,0.1f);
	}
	
	void animateHealthBarAnimListDown(){
		print("\\\\\\\\\\\\\\\\" + Time.time);
		print("TIME B " + Time.time);
		print("\\healthBarAnimList.Count" + healthBarAnimList.Count + " " + Time.time);
		print("\\");
		if(healthBarAnimList.Count == 0){
			print("\\Count AT 0... Cancel ANIM");
			CancelInvoke("animateHealthBarAnimListDown");
			return;
		}
		energyNode = healthBarAnimList[0];
		healthBarAnimList.RemoveAt(0);
		energyNode.enabled = false;
	}
  1. prints are a big bottleneck. Does the logging amount increase on each run?
  2. you should consider removing the InvokeRepeating and use an Invoke as required…
void HandleDamage()
{
   //do stuff

  AnimateHealthBar();
}

void AnimateHealthBar(){
  if(healthBarAnimList.Count > 0) 
  {
     healthBarAnimList.RemoveAt(0);
     
    Invoke("AnimateHealthBar",0.1f);
  }

}

In tests, the List.count is the same size, so no log total should be more than another. The delay happened before logs were placed. I would use an alternate to invokeRepeating but, it must be time lapsed. So, I gather a list of items. I then, remove the 0 item from the list and turn its renderer off. Then, there must be a small delay before the next item, now, list item 0 is run thru the same process.

It is very odd since, as I say, the first hit, no delay, second hit, slight delay, third hit larger delay… And so on.

Well if thats the case, I suggest its probably code elsewhere.

I showed you a way of doing it without using InvokeRepeating…

The only reason I suggest doing it without the use of InvokeRepeating, is to prevent the chance of handleDamage triggering a new InvokeRepeating call before the previous iteration completed.

At least put a CancelInvoke before you call InvokeRepeating again to ensure this double up doesnt occur.

Yes,
I put a cancel invoke before, with no effect. It is puzzling. I might be able to use invoke, but would have to invoke, with in the invoke…
Anyhow, thanks.