I'm currently trying to create a 3D array of objects whose class I call "Blocks". But it seems that every time I create a block instance, one of the values that I pass into the constructor seems to be passing by reference rather than value. So, when I modify the variable -which is a List of enums representing the direction that each face of the block is facing- the lists in each of the block objects changes too. To be clear, I do NOT want to pass by reference, I want each object to have it's own List.
All of my search results are telling me that Unity only passes by value by default so I'm not really sure which questions to start asking and I'm hoping there's just some simple explanation that I'm missing.
Here's a simplified version of the Block class and how I declare the relevant variable.
public class Block
{
public List<FaceIndex> faceDirections;
public enum FaceIndex : int
{
East = 0,
West = 1,
Top = 2,
Bottom = 3,
North = 4,
South = 5,
}
public Block(List<FaceIndex> faceDirections)
{
this.faceDirections = faceDirections;
}
}
Here's how I declare the variable in a different class:
public List<Block.FaceIndex> blockFaceDirections;
blockFaceDirections = new List<Block.FaceIndex> { Block.FaceIndex.East, Block.FaceIndex.West, Block.FaceIndex.Top, Block.FaceIndex.Bottom, Block.FaceIndex.North, Block.FaceIndex.South };
Here's how I instantiate it:
new Block(blockFaceDirections);