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.

How to modify content of SharedComponentData for all entity carrying that component?

Discussion in 'Entity Component System' started by yc960, Jul 2, 2018.

  1. yc960


    Apr 30, 2015
    scenario: I have a tons of entity with the same meshInstanceRenderer and I need to change their material at the same time frequently. Since SharedComponentData are kept in one location in memory, I believe that would be as simple as changing the content of that memory without having to do relatively expensive operation of setting it per entity. Any idea how?
  2. dartriminis


    Feb 3, 2017
    If you are changing a property on the material object itself, then you should be able to change that property and have it affect all entities, since that Material object in each SharedComponentData is a reference to the same object.

    If you are setting that Material property to a different material, you will need to use shared component data filters. I'm not sure if/how filters work with reference objects (like the mesh and material in MeshInstanceRenderer), but, worse case scenario, you have a second SharedComponentData with some sort of integer to filter by.

    Check out the ECS detail page for an example and more info.