U
U
Uncle Bogdan2021-08-20 12:39:22
C++ / C#
Uncle Bogdan, 2021-08-20 12:39:22

Why is information from the sheet removed from a static field?

Like there is a static sheet:

public static List<Cell> AllCell = new List<Cell>();


There is a method in which it is filled:

[ContextMenu("Generate grid")]
    public void GenerateGrid()
    {
        for(int x = 0; x < _gridSize.x; x++)
        {
            for(int z = 0; z < _gridSize.z; z++)
            {
                var cell = Instantiate(_cell, position, Quaternion.identity, _parent.transform);

                cell.name = $"Cell: x:{x}, z:{z}";

                GridActions.AllCell.Add(cell); // ВАЖНЫЕ СТРОЧКИ

                print(GridActions.AllCell[GridActions.AllCell.Count - 1].name); // И ЭТО
            }
        }
    }


I call the method in the editor. the most recent print outputs everything.

But then I wanted to do it and nothing happened to me. What's the catch?

This is:

private void Start()
    {
        foreach(Cell cell in GridActions.AllCell)
        {
            print(cell.name);
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
namee, 2021-08-20
@namee

did it fill up at all?
At the start of the game, the static will be reset to zero. It is not serialized.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question