Serialized variables not sharing

Hi, I have a script that has a lot of variables and I really wanted to group them and collapse them to help organize them.

so I did a bit of research and apparently I use this [System.Serializable]
after moving those variables into that public class, its having trouble accessing those variables in my monoscript (the script cannot find them)

error CS0103: The name `Stat_healthCurrent’ does not exist in the current context

for some reason its not passing it on, maybe I’m doing something wrong.

You need to use the [System.Serializable] tag for each class, not once at the top. Basically it means “do this for the next item”.

…was my first reaction. However, your compiler problem is caused by you not updating the code to reference the new variables as members of the class you’ve made. All instances of Stat_healthCurrent need to read group2. Stat_healthCurrent now (except the one in the new class, obviously)


Even though you were being a d*** to me, I’m still going to answer your question:

Learn how classes work

You can’t go:

public class Vars {
    public int i = 5;

public class lol : MonoBehaviour {
    public Vars vars;
    public void Awake() {

What would i be? It’s not defined anywhere in the lol class is it?
If you have something in a class you need to access it either through the class itself (static) or through an instance of the class, like so:

public class lol : MonoBehaviour {
    public void Awake() {

Next Time you ask a question, simply copy and paste the error message because just that would have come up with this answer in probably less than 10 seconds. This is the importance of asking questions properly :slight_smile:

Hope this helps,