Problem to create initialize class fields

I want to write like Bergerac.Name = “Bergerac” but it didn’t allows me and I don’t want to initialize it when running becaus it’ll take memory.

the class

using System.Collections;

[System.Serializable]
public class TeamClass{

    public string Name;
    public byte games;
    public byte wins;
    public byte looses;
    public byte points;
    public byte level;
}

where I want to initialize Bergerac:

using System.Collections;

public class Teams {
    public TeamClass Bergerac;
    public TeamClass Chartres;
    public TeamClass Chateaubriant_Voltigeurs;
    public TeamClass Cholet;
    public TeamClass Fontenay;
    public TeamClass Granville;
    public TeamClass Lorient_B;
    public TeamClass Mantes;
    public TeamClass Nantes_B;
    public TeamClass Paris_SG_B;
    public TeamClass Plabennec;
    public TeamClass Rennes_B;
    public TeamClass Romorantin;
    public TeamClass Saint_Malo;
    public TeamClass Trélissac;
    public TeamClass Vitré;
}

TY

The name of that variable will always take memory, no matter when you initialize it. There’s no difference in memory cost depending on where you set it.

I’m not talking about hard memory I’m talking about RAM, I only want to have the variable in the data of my game and use it when it’s necesary, not to re create it every time that I launch the game.

That was what I was talking about!

If you want the data to not be loaded into memory unless you need it, you shouldn’t hard-code the teams like that. Instead, store them in assets of some sort, and load them as you need them. Either by turning TeamClass* into a ScriptableObject, and store/load it from Resources, or store it as JSON or something equivalent and load it from StreamingAssets.

  • Class names really don’t need to end in “class”. We already know it’s a class!
1 Like

I added something before TeamClass :

static