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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

SetComponentData for whole chunk/query?

Discussion in 'Entity Component System' started by g3nuine3, Jan 21, 2020.

  1. g3nuine3

    g3nuine3

    Joined:
    Feb 13, 2018
    Posts:
    11
    Is there a better way to set ComponentData for all entities in a chunk/query as iterating them?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,648
    You can create a NativeArray<T>(EntityQuery.CalculateEntityCount()

    Then use UnsafeUtility.MemCpyReplicate
    to set all instances to the same value of the ComponentData

    Then use EntityQuery.CopyFromComponentDataArray(NativeArray<T>)
    To apply the value to all entities in a query

    Is it faster? Maybe.
    Is it better? Debatable.