Getting a variable works in a Start function, but not in another one.

Sorry if the title isn’t that clear.

I’m making a multiplayer shooter game, and now that the game is mostly playable (though not fun in the current state), I’m updating my code to introduce modularity. As I want the players to be able to choose a character with different stats, I made a class that adapts those stats in function of the user’s choice, then I get these values in the scripts that needs them, so I can add more characters over time without having to modify the controls/health/etc scripts each time.

The class that contains the characters uses variables like this :

public int Health { get; set; }

And a function set these variables according to user’s choice.

Then, in the game scene, I get these variables using a GetComponent from the script where I need them. For my Player Controller script, it works perfectly, I tried several choices and it worked every time.

I proceed like this :

//variables
int movementSpeed;

void Start() {
    movementSpeed = GetComponent<VariablesScript>().movementSpeed;
}
//then I use movementSpeed in the script, and it works

I did the exact same thing in my Player Health script, getting the max health the same way I do with movement speed, but for unknown reasons, the get isn’t working, my variable is equal to null.
I tried to get the variable in the update function, and it’s working, but of course, I don’t want the get to occur every single frame, it’s just for initialization…

I don’t understand why the exact same thing works in a script and not in another… Any clues about why a get would work in a place and not in another ? Thanks in advance !

Thanks for your replies guys, but as I thought, that was a stupid error that I did completely out of the script…

My game is a multiplayer game, and I’m using UNet to handle the network. Of course, instantiating multiple instances of the same prefab with the same scripts would lead to problems like controlling all players because the script is enabled for all objects on all clients. To avoid that, I just have a script to enable the scripts for the local player only. Control and health scripts are in this list. But I forgot something for the health script… They need to be disabled at start, and then enable them with the script. And I forgot to uncheck the enabled case in the editor for the health script… A single click that changes everything… Now all is working. Sigh… Tired of doing newbie mistakes. Thanks for the execution order link though, I still have a lot of things to do, this link could be useful in the future. Thanks again !