Translate Increases Speed, with each use. Why?

Hi there,
I am wondering why, when I use Translate, where to move a transofrm from left to right. Recalling this transform from a pool, on its next use, his speed increases, and the same the next time. So, the speed at which he travels is inconsistent.

Any ideas?

///this function is called, and applied to members of a pool. Each successive time it is called, he moves faster and faster. 
	IEnumerator performAction(){	
		thisMemberInUse = true;
		while(thisMemberInUse){
			thisTransform.Translate(-Vector3.right * Time.deltaTime*Speed, Space.World);
			yield return null;
		}
	}

Is there any chance that Speed gets set to different values from other parts in your code?

I recommend to monitor the speed variable in that coroutine (e.g. by just putting in Debug.Log(Speed)) to see if that actually increases. Because from the code you posted that seems to be the only possibility.

I found the cause, but I am unsure why it has this effect.

I was calling a member to reset its run before it completed its run. So, it would start at x pos 3, moving to x pos -x and before the while() (carrying the Translate()) could be proved false, the position of th transform would jump back to x pos 3. I think this thru off the calculations of Translate somehow. Not entirely sure tho.

So I am running into this issue again.

@GlockenBeat, the speed factor remains the same. My logic above makes no sense. Can any one think why an object, using Translate, would speed up?

Here is my situation.

  1. A transform uses translate. This transform carries a child trigger. When the child hits “the end wall”, it resets the position of the parent transform to its start pos. The translate is temporarily halted for a frame, then restarted to perform the same translate at the same speed. However, the speed of the translation increases. Seemingly doubled each loop.

:?!

This is the loop of code I am using

	void runMember () {
		if(!thisMemberInUse)
		StartCoroutine(performAction());
	}
	IEnumerator performAction(){				
		thisMemberInUse = true;
		yield return new WaitForSeconds(2.0f);///just to test for pause, however this only works once on init. 
		while(thisMemberInUse){
			crntPos = thisTransform.position;
			thisTransform.position = Vector2.MoveTowards(crntPos, endNodePos,speed);
			if(!thisMemberInUse){
				print("MEMBER NOT IN USE " + Time.time);
				return false;
			}
			yield return null;
		}
	}
	void endRun(){
		thisMemberInUse = false;
		thisTransform.position = startPos;
		StopCoroutine("performAction");
		print("endRun " + Time.time);
		for(int i = 0 ; i < partSystmData.Length; i++){
			partSystmData[i].enableEmission = false;
		}
	}

I found a solution.
I switched lines 6 and 7. This insures a small pause in movement. This cures it. But I still can not figure out why that would matter.

:?

StartCoroutine puts the Coroutine in the list of running Coroutines, but it doesn’t execute immediate, so what you’re seeing is similar to a threading race condition. Simply doing something like this will solve the problem.

if(!thisMemberInUse)
{
    StartCoroutine(performAction());
    thisMemberInUse = true;
}

It is a mono feature that performAction() doesn’t execute the method like normal but instead returns an enumerator that you can execute later!

Ok. Interesting. Still dont really get it. But it is a priority thing, in that the way I discern the info, the order which I place has a major impact.
Ok. Cool. Thanks!