0


I have the following line of code in my class:

public Vector3 HexagonSize { get; set; }

And then in a method I am doing this:

var tempSize = HexagonPrefab.GetComponentsInChildren<MeshFilter>()[0].sharedMesh.bounds.size;
HexagonSize.x = tempSize.x;
HexagonSize.y = tempSize.z; // Inverted because of blender
HexagonSize.z = tempSize.y;

And I am getting the exception:

cannot modify the return value of because it is not a variable

Thing is if a get rid of the property (auto-property) everything is fine.
I know how to fix the problem I have to do the following:

 HexagonSize = new Vector3(tempSize.x,tempSize.z,tempSize.y);

The question is why can I edit the values of the hexagonSize when it is a field but I have to create a new one when it is a property. btw I know that structs are immutable

Ivailo Korakov
  • 357
  • 2
  • 14
  • It's not that it's impossible to reassign the properties. Instead, the compiler is just warning that you probably didn't intended for it. – Biscuits Aug 12 '17 at 02:35
  • _"I know that structs are immutable"_ -- no, you don't know that, because not all aren't. They _should_ be, but obviously `Vector3` you're using isn't, because if it were you'd be getting a different error message (and by the way, that's a compile-time error message, _not_ an _"exception"_). – Peter Duniho Aug 12 '17 at 06:12

0 Answers0