Search Unity

One Vs Many ECS Game with Source

Discussion in 'Entity Component System' started by CallToAction, Jul 15, 2019.

  1. CallToAction

    CallToAction

    Joined:
    Feb 10, 2014
    Posts:
    23
    I've put together a "one vs many" build using unity ecs.

    Play it here:
    https://thinkhuge.s3-us-west-2.amazonaws.com/onevsmany/index.html

    Source code here:
    https://github.com/areilly711/unity_ecs

    Questions:
    1) I'm using the UnityEngine.Bounds struct for collision in my system jobs. Whenever I update the Translation or scale component of an entity, I have to update the bounds manually as well. Is there a better way to do this?

    2) I create a pool of bullet entities at start and re-use them by setting them to active or inactive. The rational behind this was because I didn't want to create a new entity every time the player fires. The problem is, I am checking my isActive flag whenever I use bullets in my jobs, slowing things down. I'm wondering what optimization experiences others are having with pooling vs creating
     
    mannyhams likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    1. Are you bounds different to your mesh? If not have you considered just using the WorldRenderBounds that Unity already keeps updated. Otherwise only alternative I can think of is use local bounds and convert to world bounds when doing collision or recalculate bounds every frame (which is basically what WorldRenderBounds does.)

    2. If you're going to pool, why not just used the Disabled component then it won't even appear in queries.
     
    mannyhams and Jinnan87 like this.
  3. areilly711

    areilly711

    Joined:
    Sep 30, 2016
    Posts:
    1
    tertle:

    1) Thank you, I didn't think to use that. Makes things far simpler since the worldrenderbounds will automatically be updated

    2) This is a good idea. However, do disabled entities still get processed in job execute functions? It's great that the query doesn't give me the disabled ones, but I still need a way to enable disabled ones when firing
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Disabled entities will not be returned from any query unless you add disabled to the query. So you can just query the disabled ones and remove the component when up each to spawn another.

    This all said, I prefer just creating a new entity (instantiated from a prefab entity) instead of pooling entities. Don't really see what you're gaining from pooling.
     
    lclemens likes this.