Search Unity

Readonly structs as component data

Discussion in 'Entity Component System' started by Deleted User, Aug 10, 2019.

  1. Deleted User

    Deleted User

    Guest

    I have seen people using readonly structs and readonly fields in their component data structs.
    Does it make a difference?
    What are the pros and cons of using readonly structs (or readonly fields in a normal struct)?
     
  2. Silenus3

    Silenus3

    Joined:
    Jun 5, 2019
    Posts:
    20
    from what I gleaned it allows asynchronous process to use the same data without queuing , as in the case when different threads write to the same data where it has to be done in some order.
     
  3. Deleted User

    Deleted User

    Guest

    So basically it's same as adding [ReadOnly] attribute to the parameter in job?
     
  4. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    987
    It's just to assure that those components are immutable. Immutable objects have lots of advantages. I use it whenever I can.