Search Unity

First System Feedback

Discussion in 'Entity Component System' started by RoughSpaghetti3211, May 18, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Got my first IComponemtSystem working (very basic ) and just looking for someone to take a look to see if I could be doing anything better.

    Some questions.

    1)Should the CreateArchetype be done in the bootstap class?
    2)If the hexSphereBuild is only needed once is OnUpdate() an unnecessary method call
    3) I also noticed that I have 1 entity per chunk, Why is that ?
    Screen Shot 2019-05-17 at 11.44.29 PM.png


    Code (CSharp):
    1.     /// <summary>
    2.     /// System for creating a hexSphere
    3.     /// </summary>
    4.     public class HexSphereBuildSystem : ComponentSystem
    5.     {
    6.         #region FIELDS ---------------------------------------------------------
    7.  
    8.         public static EntityArchetype tileArchetype;
    9.         private EntityQuery _query;
    10.  
    11.         #endregion
    12.  
    13.  
    14.         #region METHODS --------------------------------------------------------
    15.  
    16.         /// <summary>
    17.         /// OnUpdate, Must implement for ComponentSystem
    18.         /// </summary>
    19.         protected override void OnUpdate()
    20.         {
    21.         }
    22.  
    23.         /// <summary>
    24.         /// OnCreateManager
    25.         /// </summary>
    26.         protected override void OnCreateManager()
    27.         {
    28.             //
    29.             // Define Archetype
    30.             tileArchetype = EntityManager.CreateArchetype(typeof(VertexComponent),typeof(VertexTrianglesComponent),typeof(VertexSubdivisionComponent));
    31.  
    32.             //
    33.             // Create entities
    34.             NativeArray<Entity> entityArray = new NativeArray<Entity>(12, Allocator.Temp);
    35.             EntityManager.CreateEntity(tileArchetype, entityArray);
    36.  
    37.             //
    38.             // Build Icosahedron
    39.             BuildIcosahedronEntities(1.0f);
    40.         }
    41.  
    42.         /// <summary>
    43.         /// Builds the icosahedron entities.
    44.         /// </summary>
    45.         /// <param name="raduis">Raduis.</param>
    46.         private void BuildIcosahedronEntities(float raduis)
    47.         {
    48.             //
    49.             // Query Entities
    50.             _query = GetEntityQuery(typeof(VertexSubdivisionComponent), typeof(VertexComponent));
    51.  
    52.             //
    53.             // Set Icosahedron Entities
    54.             int i = 0;
    55.             Entities.With(_query).ForEach<VertexComponent, VertexTrianglesComponent, VertexSubdivisionComponent>((ref VertexComponent v, ref VertexTrianglesComponent t, ref VertexSubdivisionComponent s) =>
    56.             {
    57.                 v.position = new float3(IcosahedronData.posVtxX[i], IcosahedronData.posVtxY[i], IcosahedronData.posVtxZ[i]);
    58.                 v.index = i;
    59.                 t.connectedTriA = -1;
    60.                 t.connectedTriB = -1;
    61.                 t.connectedTriC = -1;
    62.                 t.connectedTriD = -1;
    63.                 t.connectedTriE = -1;
    64.                 t.connectedTriF = -1;
    65.                 s.divisionLevel = 0;
    66.                 i++;
    67.             });
    68.         }
    69.  
    70.         #endregion
    71.     }
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I think it should usally be defined wherever it's being used. Really doesn't matter, do whatever makes sense for your architecture.

    If you don't do anything in the Update of a system, does it even need to be a system?

    I only see 1 chunk in your picture
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Thank you for your relpy.

    Cool thanks

    Could you give me a clue on how to handle large set of data that need to be initialized/cached in pure ECS. I was under the impressions I need to inherit from ComponentSystem to get a hook into ECS through the OnCreateManager(), a replacement for Awake() in mono.

    After watching Daniels presentation again on the Debugger I understood the information incorrectly. So I have one chunk that is not full. But what is chunk utilization ?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    It's chunk usage :) Right -> Better, which means you not waste chunk space and reduce cache misses