Problem with InvokeRepeating()

Hello everybody.

I’m jamming right know. I work on a SpriteManager and I’m having a problem with InvokeRepeating(). Here’s my code :

void Start()
	{
		// setup mat
		gameObject.renderer.material = new Material(Shader.Find("Unlit/Transparent Cutout"));
		
		_mat = gameObject.renderer.material;
		_mat.SetTexture("_MainTex", m_spriteSheet);
		_mat.SetTextureOffset("_MainTex", m_currentAnim);
		_mat.SetTextureScale("_MainTex", new Vector2(SpriteW, SpriteH));
		_mat = gameObject.renderer.material;
		
		InvokeRepeating("_updateSprite", 0f, m_delay);
	}

The _updateSprite() method update sprite display. Technically, the code works but there is a little problem : the sprite does not update on regular interval.

Does anyone know how to solve that problem ?

Waiting for your answers. Cheers to other jammers ! :slight_smile:

How large/small is m_delay? InvokeRepeating is having trouble if the value is too small (<<1). In that case, try using a coroutine instead, where you can wait a certain number of frames or use WaitForSeconds. Or use Update, and work with frame times, or time deltas using Time.time.

@Etic5h5 : Nope, I double-checked :confused:

@Wolfram : It works just fine when animation play slowly (delay >= 0.5f) but no matter what I try, I can’t seem to get it work faster :confused: