Visual Studio C# ignoring new array size until

Hey all.

Had a strange one a moment ago. I created a boolean array that was 4 elements in size.

public bool[] strikeMap = new bool[4];
I realised it wasn’t big enough so I increased the size

public bool[] strikeMap = new bool[5]

I stopped VS and Unity from running the game. I made the change then started the debug up again and run the game in Unity. Weirdly, the array stayed at 4 elements in size. The only way I could get it to see the new size was to stop Unity playing, stop the VS attachment (debug) and do a . . .

Build | Clean Solution
Build | Rebuild Solution

I Run the debug in VS and hit play in Unity. Looking at the VS debug locals the array was correct at 5 elements in size.

I saved in both Unity and VS automatically between changes.

Any idea why this happened/ is happening?

I know .Net caches solutions/projects/files etc, was Unity definitely not playing the game? My only thought would be that the script file was perhaps still in use. The fact that the clean/rebuild resolved it might suggest that also, as the clean/rebuild would have wiped the dlls and any other files and rebuilt them (obviously).

Can you reproduce the same issue?

Out of interest, got any spaces in the project/file names?

You may be right Rob about Unity having hold of it but I also closed them both relaunched but had the same issue. I’ll keep an eye on it and report back my finding.

hmmm… bit odd huh…

Let us know what you find, may well prove useful to other members :slight_smile:

1 Like

Privacy & Terms