title: How to expose mutable list as a readonly property in a MonoBehaviour
body: <p>Let's say I have something like this</p>
  
  <pre><code>public class BodyPart : MonoBehaviour {
      private BodyPart parent;
      private List&lt;BodyPart&gt; children;
  }
  </code></pre>
  
  <p>and I want to be able to maintain both links when adding/removing children and changing parents. Ideally I would just create properties, and ensure parent gets updated when I add children and vice versa. But exposing list as a property (even a readonly property) - allows me to do</p>
  
  <pre><code>bodyPart.Children.Add(new BodyPart());
  </code></pre>
  
  <p>which won't call the setter, so parent field won't be updated properly.</p>
  
  <p>I've seen people exposing List&lt;...> as a property of type ReadOnlyCollection&lt;...>, but I'm not sure if unity component system will work with such a property, and maybe there is some better way? Also - maybe IReadOnlyCollection is better?</p>
  
  <p>I know I could do a hierarchy of GameObjects instead, and use the builtin parent-child relationship of unity, but I don't want my BodyParts to be full-blown GameObjects with transforms and everything, it's just a model for RPG attributes and inventory system. Also the example is simplified and ultimately I want to have more logic and several kinds of relationships between Components encoded in that model.</p>