Inconsistent member variable between public functions and Update()

This is a weird problem I started to have today. I have a member variable that I set when a public function is called by an external script. But on the next cycle the Update() function this variable is not updated. Next time the public function is called the variable has the new value.

It seems almost like there are two instances of the same class. One that is called by the external script and one that is updated every frame. Did you guys ever seen anything like this? Any suggestions on how to solve the issue?

Here is piece of my code for you to check:

	public void StartFlashing(float flashDuration) {
		lightState = LightState.LIGHT_FLASHING;
	}
	
	// Update is called once per frame
	void Update () {
		if (lightState == LightState.LIGHT_OFF) {
			return;
		}
                //Code never get to this point.
	        ...
	}
	
	LightState lightState = LightState.LIGHT_OFF;

The function that calls StartFlashing is another script in the same game object. I tried to use both getcomponent<>() and also exposing a script reference to the editor. Both gives the same result.

What do you guys think?

I found the solution to this issue. Iā€™m posting it here for other people that may run in the same problem.

I had one of the relationship between scripts/object done at prefab level instead of instance level. This causes the code to call some kind of non-existing instance of the class instead of the instance used in game.

The tricky part was that the incorrect relationship was not the one to my FlashingScript above but one earlier.

enemyScript ā†’ player.Damage() ā†’ FlashScript.StartFlashing()

The enemyScript to Player reference was done at prefab level and create the whole issue.