Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question SystemAPI.Query's question.

Discussion in 'Entity Component System' started by Silrider, Feb 13, 2023.

  1. Silrider

    Silrider

    Joined:
    Dec 5, 2019
    Posts:
    4
    Thank you for read my post

    in the ECS 1.0 doc,
    (https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/systems-systemapi-query.html)

    Doc said that "However, because it only reads the RotationSpeed data, it uses RefRO<T>. RefRO<T> usage is entirely optional: you could use the following instead as valid code"

    Optional mean that syntex is totally same as RefRO<T> == Data <T>
    or
    RefRO<T> will have safety check, Data<T> will not have safety check?

    Just confuse to use the syntext. Anyone know about it?

    Thank you.
     
  2. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    They're the same in that you can't write to either but they're not syntactically the same.

    RefRO gives you a reference to the data and without RefRO you get a copy of the data.
    The reason you would use RefRO is for performance in that it avoids copying all your data.
    If your components are small (8 bytes) or performance is of no concern, then you can leave off RefRO and avoid the syntax overhead.

    The safety check that RefRO performs on ValueRO access is part of the job safety system and in the given scenario, you're safe whether you use RefRO or not.
     
    Silrider likes this.
  3. Silrider

    Silrider

    Joined:
    Dec 5, 2019
    Posts:
    4

    First, Thank you for reply.

    Ah ha! performance! Thank you.
    And, also, I didn't know that reading will cause copy. Thank you for let me know that too.