problem with setting values of newly instantiated object

I worked 2 days to make me feel well with this script and now it’s making problems. When I instantiate a new GameObject with this script attached to it, I somehow can’t set any values in objects that need to be created in Start().

void Start () {
    actions = new Actions(this);
    connections = new Connections(this);
}

for example Actions has a boolean called “randomEnabled”.

If i instantiate my GameObject and then try to change this property in the same method, it won’t be changed.

How can I fix this?

If i instantiate my GameObject and then try to change this property in the same method, it won’t be changed.

So when you instantiate, Awake will be called on all components before you get the new instance back.

Start will be run before the next frame starts.

So, if you Instantiate(), then change some properties, a few moments later Start will be called, overwriting your changes.

Consider moving the code into Awake instead of Start.

Adding my own possible solution to this problem:

    [HideInInspector] public bool rEnabled;
    [HideInInspector] public bool iByContact;
    [HideInInspector] public bool iEnabled;

    void Start () {
        actions = new Actions(this, rEnabled);
        connections = new Connections(this, iByContact, iEnabled);
    }

I created variables in the main class to store the values. And then added the values to the Constructor of the objects.

[HideInInspector] was just used to keep the Inspector window of the editor clean.