Is it possible that a function that worked previously stopped working, and when I put a debug log, it starts working again?

Ok, this is quite a weird question, and I’m afraid to ask because I supposed to be an experienced developer… So I risk to look stupid and ask the question that I experienced since quite a time.

  • So there is a function that works correctly. What it does is not that important, I can’t see any logic between the cases.

  • At some point, this function stops working. By not working I mean it’s not called at all.

  • When I put a debug.log into this function to test it, it miraculously starts working again.

This happened a lot of time, and I always thought that I fixed the problem somehow. You know, when you do something and it’s working but you didn’t really expect that.

However, today I really didn’t change anything but added a debug log to the function, and it’s working again. My guess here would be something that put that function into a ‘sleeping’ state, and the debug awakes it… but not sure about it…

If you know anything about this, please tell me! I’m very frustrated: I’m seeing ghosts in the machine. :smiley:

More detail from the latest case:

  • I have a scriptable object.

  • It has a List of a Variable class.

  • in the OnEnable method, I call the Variable.Reset() method to reset the value to default value.

Since serialized object retains the values of their serialized variables between game sessions, I know that the Variable.Reset() wasn’t called. I assume from this that the OnEnable method wasn’t fired as well.

I added a Debug.Log in the OnEnable, before the reset, to check if this method is called or not. Some magic happens: the debug message shows up in the console, and the variables reset!

The answer is simple: No, that’s not possible. However the question is how do you know it’s not called at all if you don’t have a debug.log in it? Have you tried actual debugging and setting breakpoints? Have you tried the deep profiler?

You said what the function does is not important, however it’s the most important thing to know to actually tell if the function runs or not. Also you haven’t given a single clue where and when the function is called. Maybe you have some spooky conditions?

Since you refuse to give actual information that is relevant to your problem we can’t help you any further. All your assumptions don’t seem to be related to any sort of programming. functions do not have or represent state. Functions are just sequencial instructions. Note that coroutines are not functions but state machine objects, though if you actually talked about coroutines you would have mentioned it, right?

So unless you drastically improve your question by adding actual details about your issue we will close this question as not reproducible / off-topic / too unspecific.