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.
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!