InvokeRepeating gets cancelled on scene change?

I use MonoBehaviour.InvokeRepeating to call a function every few seconds.

If I load the next scene, will the Invocation get cancelled automatically or I have to cancel it manually using MonoBehaviour.CancelInvoke?

(I haven’t called Object.DontDestroyOnLoad on any object of the initial scene, I’m just wandering if invocations are going on in the background in the new scene, thus needlessly consuming resources)

What happens if you try it?

I tried it (I put a Debug.Log line inside the invoked method) and it seems to get cancelled after a new scene is loaded.

Hi, sry I' confused, can you clear this up: your comment is opposite from initial Question: > I want the texture to not move along the line. vs > I want the trail to be a line with my texture (Like in the Trail Renderer). Also *.gifs that you attach are not trail render thing. They are emission through distance.

1 Answer

1

If you look at the documentation of MonoBehaviour.InvokeRepeating you can see that InvokeRepeating is a member function of MonoBehaviour. Like coroutines (StartCoroutine()) those things run on the MonoBehaviour instance they has been started from. When the Object gets destroyed all coroutines or “InvokeRepeatings” are canceled immediately.

Thanks for making it so easy to understand.

This is when most people would use hacky Unity techniques like GameObject.DontDestroyOnLoad(this.gameObject) to keep that GO alive across scenes. It's things like this that makes Unity a pain to work with.

File 2 is just TrailRenderer. I replaced the smoke texture with an abstract wavy line texture to make my question clearer. With the TrailRenderer and other tools I've tried, the texture trails behind the object like a tail. I want the object to kind of leave the texture as a trace behind it (Like a trace from a tire ).