C# public static struct ? Keep track of gameobject properties in a list<> by reference

Hi everyone,

I’d like to have a public class with a struct List goProps contains info about a lot different game objects.

  public class GOInfoProps
    {
        public struct GoProp
        {
            public double percent;
            public Transform TrackSideGO;
            public ushort evtType;
            public short evtOP1;
            public short evtOP2;
            public short evtOP3;
            public string evtName;
        }

        // predefine for 1000 Go's
        public List<GoProp> goProps= new List<GoProp>(1000);
    }

Game object should sign to the List goProps and add its values.

public class GO : MonoBehaviour {

    private EventSamples.GoProp goProp = new EventSamples.GoProp;
    private EventSamples.goProps probList = new EventSamples.goProps;

    void Start(){
      goProp.percent = 0.6;
      probList.add(goProp);
   }
}
}

In the end I want access List from anywhere for statistic purposes in real time.
But declaring:

private EventSamples.GoProp goProp = new EventSamples.GoProp;
private EventSamples.goProps probList = new EventSamples.goProps;

this way does not work.
How do I get a reference to goProps in the game object GO or from anywhere?

so let me recap, you want a GameMaster that has a List, each gameObject has the GoProp.

And then you want to access the GoProp from somewhere else in the game.
Is this correct?

1 Like

This should create Null reference errors. let say you only have 30 objects in the list, if you try read from object 31 or higher, you’ll get an Null error

1 Like

Yes. And I have to use static in this case. Unfortunately there are other tricky things to solve. If a GO has add his properties to the list already, and the GO.properties change. How to find the corresponding GO.Properties in the List, etc.

public static class GOInfoProps
    {
        public struct GoProp
        {
            public static double percent;
            public Transform TrackSideGO;
            public ushort evtType;
            public short evtOP1;
            public short evtOP2;
            public short evtOP3;
            public string evtName;
        }
        // predefine for 1000 Go's
        public static List<GoProp> goProps= new List<GoProp>(1000);
    }

Thanks for your help @johne5