I was having an interesting bug with changes not being registered. The fix was unusual. The first code works fine, while the second one - doesn't.
https://rextester.com/PIRZFJ12810
globChanged = false;
bool tmp = target.Inspect();
globChanged |= tmp;
if (globChanged) Debug.LogError("Works!");
This one doesn't work:
globChanged = false;
globChanged |= target.Inspect();
if (globChanged) Debug.LogError("Works!");
I think I have a suspicion. globChanged is a public static field. The target.Inspect(); actually returns False. But internally it sets globChanged = true when changes are made. I think the operator "|=" evaluates the value of globChanged before the Inspect(); function was called. And I actually tested this - at the end of target.Inspect(); the globChanged is True.
Also: Doesn't work:
globChanged = globChanged || pgi.Inspect();
Works:
globChanged = pgi.Inspect() || globChanged;
To clarify. Doesn't work means that It returns False when globChanged was set True. pgi.Inspect(); is executed every time and globChanged is False at the start.