Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Access list/array of custom type from inspector in ECS system

Discussion in 'Entity Component System' started by BenMM, Nov 8, 2020.

  1. BenMM

    BenMM

    Joined:
    Jan 28, 2019
    Posts:
    16
    Hi,

    I'm working on an ECS wavespawner. I have a custom type wave which includes:
    - prefab to spawn
    - time between spawns
    - amount to spawn

    Each wave should be added to a list or array in inspector and be accessible in my ECS spawnerclass.

    I have tried using a wave scriptable object and a list In IComponentData to store them, but then i run into the "neither primitive nor blittable." issue.

    I tried a wave IComponentData script (with index of wave to order in Spawner) on converted Gameobjects in hierarchy but taht leads to non-nullable issue when entity querying them into native array in spawner.

    What is the best way to access a list from inspector and how would you ideally handle storing it with ECS.


    Any help/tips would be appreciated.
     
  2. DK_A5B

    DK_A5B

    Joined:
    Jan 21, 2016
    Posts:
    110
    It would be helpful if you could provide some of the code to help understand exactly what you are trying to do.

    For example, when you talk about the "custom type wave", is this a component that you're using and editing in the editor? For example:
    Code (CSharp):
    1.     [GenerateAuthoringComponent]
    2.     public struct Wave: IComponentData
    3.     {
    4.         public Entity prefab;
    5.         public float timeBetweenSpawns;
    6.         public int amountToSpawn;
    7.     }
    When you say you're adding" to a list or array in inspector", does this mean you're trying to configure the "waves" by placing them in lists at edit-time? If so, is the code that handles spawning an ECS System, or is this traditional Unity scripting? It would be helpful to see some example code to understand what you're trying to do.

    With regards to the "neither primitive nor blittable" issue, you could configure the Component as a managed component (declaring it as a class instead of struct), however this would come with significant performance penalties (not burstable, must run on main thread, etc.) and so while it could work, it isn't the best approach.

    I'm not entirely clear on what you say you tried doing when you said you "tried a wave IComponentData script... on converted GameObjects in hierarchy", again include examples of your code would be helpful.

    Can you explain why you need this to be added to a List at edit-time in the Inspector? What functionality are you trying to provide by doing this?