Debugging - Start() treats refrence differently

I’m working on a fairly large-scale project, where multiple “gameHandler” scrips work in tandem at once. Just as the finishing touches came together, I ran into an issue about various classes holding and using a variable. I’ve never encountered this type of problem in all my OOP experience, and internet searches prove fruitless.

I am developing for Android with Unity 2019.3.0f6 Personal

In need to define what my code does to explain the error. This is a problem between two main classes I have running. I instantiated some prefabs from an assetBundle and load them into my project. Each of them has a class called “Unit” full of instance variables relevant to each of them. In this case, I’m looking at Unit’s (instance) int value of health. The starting value of “health” for this prefab is set in the inspector when I attach it to the prefab. Though I’ve tried with getters/setters as well, for ease of understanding just assume they’re all public. My code does something like this:

Public class A : MonoBehavior {
Public static Unit[] unitArray;

Void Start()

Public static void nextFunction()
Unit placeholder = unitArray[0]; = 10;

In a different file

Public class B : MonoBehavior {
Public static Unit characterCopy;

Public static void setCharacter(Unit setTo)
characterCopy = setTo;

From here on, class B passes it’s info of characterCopy to another class, which controls a button. On press, the button recalls the function in class A (which does things to health other than set it to a value of 10). The process then is repeated in a loop (up to user input, not an infinite loop).

My problem is the value of health. These classes’ interpretations of it make absolutely no sense. After calling for Debug.Log (either in an update function, in the body of the current functions, or in a touch-triggered function separate), the value of health for this Unit reference is different. As I said, in the inspector I set the default value of health on the prefab to be 0. The only time Class A believes the health is 0 is in the nextFunction() and any references it makes. The nextFunction believes that placeHolder has a health of 10. It also beleves that unitArray[0] has a health of 10. If I have nextFunction make a different call to a different function, that function will also believe either statements (assuming placeholder is passed). After that, not anymore.

Once the call A’s Start() function makes to nextFunction() terminates, this is thrown out the window. Not only does this unit’s health stop being 10, it isn’t the default value I set it to be in the prefab’s inspector either. Instead, Unity and Debug.Log() continue to interpret it as the INTEGER default value of 0. Asking about unityArray[0].health in a separate function in A claims it’s 0, asking about in any B function claims it’s 0, even asking about A.unitArray[0].health INSIDE of B (either through a setter or making in public) returns a value of 0.

The crazy part is, modifying it (from a function inside anywhere, including nextFunction() when it is not called from Start() ) after this completely corrects all instances of the Variable to this new value. Modifying it in this way, too, assumes it has a default value of 0.

Please help. I’ve poured days into this project and it’s killing me to see it fall apart for a reason completely beyond my understanding.

I’ve gotten some good advice, but I should clarify that the two classes claim different answers for the same scenario.

For example, in A I have an update function that gives the value of


and in B, I have an update function that gives the value of


Despite these being not only the exact same object, but the exact same reference to that object, one gives me 10 and the other 0.