I can think of 2 cases here that might be causing this issue.
Case #1: OnDataReceived is some kind of asynchronous method, meaning that its result can come after some time has passed and doSomething has already executed by then which means that when doSomething executes nbwidg will be 0 since OnDataReceived hasn’t happened yet, but on FixedUpdate, which happens later, the correct value will already be set.
Case #2: At Start, that if check inside OnDataReceived evaluates to false, so nbwidg won’t be set. But then OnDataReceived is called again some time later and that if now evaluates to true so you get the expected value in FixedUpdate.
That’s what I can conclude about the code shown. If you show more, pinpointing the issue will be easier.
Edit: Also, just to clarify, nbwidg, is not a global variable. It is a private field of a class instance.
Thank you for your answer !
But the problem is that OnDataReceived is called before… Because I need OnDataReceived to create my scene in Unity. And I verified and I try “Debug.Log” => The condition ‘‘if’’ of my OnDataReceived is called before (evaluates to true).