Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feedback [ecs 1.0] Why can't ISharedComponentData be authored with prefabs?

Discussion in 'Entity Component System' started by Tudor, Mar 20, 2023.

  1. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    Just gamedev ux / dissonance wise: Why can only "arbitrary" types of components be seen in prefabs, while others only added from code?

    I suppose the very long term goal of Unity is to completely move to some form of ECS, when it's full featured and friendly enough, and not require all this bridging between the Mono assets side and ECS side.

    But I don't like not having an in-editor visual saveable asset with all its creation-time necessary components on it.

    Does anyone do any workarounds, or y'all okay with surprise hidden components appearing from random hidden systems?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,797
    A lot of ISharedComponentData are added during baking.

    I guess I don't get your question.
     
  3. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    Fair, I mean you can't make a Mono Authoring for a ISharedComponent -- the baker doesn't recognize it; so you can't "put it on" a gameobject or on a prefab.

    It was a project management concern. For example, you want to have a player prefab file, that has all the data the player needs in one place. Your team looks at it, and knows everything about it.

    But if some components can't show up on that prefab, then you don't know what's going on and where the data is coming from.
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,701
    You can.
    upload_2023-3-21_17-44-34.png
    upload_2023-3-21_17-43-36.png
    upload_2023-3-21_17-44-21.png
     
    Tudor and Rukhanka like this.
  5. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    Oh is that right? I was looking at the now removed [GenerateAuthoringComponent] which was known to not support ISharedComponent.

    Thanks!

    While on this topic of being able to see the data, can you / how do you do this for components of Systems?

    Systems always have their own entity, and can have components added to them, as of 1.0. But systems are created automatically -- you can't make a mono authoring for a system, right?

    So in that case, if I want a PlayerSpawnerSystem, which has various components e.g. randomness generator, spawner state, whatever. I create these components, and their authoring mono, and put the on a game object / prefab.

    But they won't actually be on the PlayerSpawnerSystem, because that only exists at runtime. So it's a bit annoying / confusing, that my system's components are not actually on the system's entity.

    I suppose I could move them to the system's entity at runtime, but...
     
  6. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    217
    Can't be better answer. Can only add that there are no direct equivalence between GameObject and some Component now (as it was in past days of AuthoringComponent existance). It is up to you as programmer to convert some editor representation (unity mono component) to optimized internal entity representation (IComponentData, ISharedComponentData, IBufferElementData) and you can do "single to multiple" and "multiple to single" relations between mono and entities worlds.
     
  7. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    217
    Do not tie spawner parameter to the system. Make a component that defines all spawn parameters and use it. I have made exactly the same task as you mention in mine Rukhanka samples. I have an spawner system to spawn many animated prefabs in scene. I've made a component with prefab list, spawn count, spawn radius and spawn delay:
    upload_2023-3-21_16-4-31.png
    PrefabSpawnerSystem consumes converted by baker SpawnPrefabComponent, spawns needed number of prefabs and removes it from entity. By this approach I can spawn things many times and it is flexible because code (system) and data (component) are decupled.

    Another example. To configure some global debug parameters I have created DebugConfigurationComponent, that has corresponding authoring script and created as singleton in entity world (idea is taken from UnityPhysics package configuration). Various systems that require to be switched in debug operation mode read data from this singleton. But there is no direct intersystem communication.
    upload_2023-3-21_16-11-23.png
     
    Last edited: Mar 21, 2023
    Tudor likes this.
  8. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    150
    Yeah alright, good examples. But it would be nice to also be able to bake onto system's entity directly. Hmm would be nice if you could, in an Authoring Baker, find and specify on what entity you want to AddComponent. :)
     
  9. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    217
    You forgot that baking process is split into two phases: Baker and BakingSystems. Documentation says:

    "A Baker can only add components to the primary entity that it's baking and the additional entities created by itself."
    And:
    "Baking systems are regular systems that process the output that a Baker produces, for example by combining results."

    Bakers can be used for simple use cases solely. For more compilcated cases use BakingSystems and do whatever you want in them.
     
    Tudor likes this.