Search Unity

[Showcase] Battle Marines Vs Zombies built in ECS

Discussion in 'Entity Component System' started by CodeMonkeyYT, May 19, 2019.

  1. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    125
    Hey everyone!
    I've been doing my own research studying about ECS, Jobs, Burst and making videos covering what I've learned.
    This past week I've been converting a Animation System I previously made into ECS and researching AI and various other things to build a small functional demo scene.

    The result is this Battle Scene with 2 factions, Marines and Zombies.
    There's a lot at work here and most of it is in ECS. Targeting, AI, Movement, Animation, Spawning, etc.
    In the video I do an Overview of the various Systems and how they work.

    You can download the complete project files if you want to mess around with the code
    https://unitycodemonkey.com/video.php?v=fTw_fXsvC6I

    I've done a couple more videos on Getting Started with ECS, Job System and various others, here's the playlist:
    https://www.youtube.com/playlist?list=PLzDRvYVwl53s40yP5RQXitbT--IRcHqba

    Also I've only been researching ECS for a few weeks so it's possible I'm not doing some things in the best way possible, if you notice something that doesn't seem right or there's a better way of doing please let me know!
    Cheers!
     
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Really appreciate your tutorials. Thank you.
     
    CodeMonkeyYT likes this.
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Nice work on those tutorials.

    One piece of feedback:
    Please use game object conversion. In this case representing the zombies & marines as prefabs that can be configured seems like it should make things more familiar. Specifically i would have one MonoBehaviour responsible for setting up multiple i component data that directly relate to game code for a specific unit type. Could even be configurable marine vs zomebie on the same component type.

    Think what's good for authoring workflow (Totally different question from what's good for runtime performance & easy of querying) (One monobehaviour for authoring can make a lot of sense for adding multiple runtime components)


    Either SpawnFromMonoBehaviour or even better SpawnFromEntity so the actual spawning code can also be done from a system.

    By using prefabs you can also more efficiently Instantiate entities by using the batch EntityManager.Instantiate variant.
     
    Last edited: May 19, 2019
    Zoey_O and CodeMonkeyYT like this.
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    The Graphics.DrawMesh usage is a bit unfortunate. Have you thought about using a textureatlas for the sprite animation instead? This way you can feed one big uvatlas and kick all zombies off in one Graphics.DrawMeshInstanced call?
    Allowing you to fully prepare all data on a job and just having a single final copy to materialpropertyblock on the main thead.
     
    Zoey_O and CodeMonkeyYT like this.
  5. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    125
    Hmm interesting so you're saying the ideal use case for ECS when it becomes production ready will be Hybrid instead of Pure ECS?
    I was under the impression that the best way would be Pure ECS so I haven't looked into the Hybrid and Game Object Convert workflow at all.
    Are you saying essentially defining the Archetypes and initial component values in a game object prefab and instantiate that as an entity instead of doing all the definitions and values through code? Guess I need to research the Hybrid workflow.

    For the animations I just converted the animation system that I've been using for several years so already have a nice library of animations as frames with vertices and uvs. I thought caching the Meshes would be an issue but they are quite light in terms of memory so that approach worked surprisingly well.

    Using a SpriteSheet Texture animation is something I'm looking into to see just how many units I can push on screen. The main issue with that method is I need a different spritesheet per animation and per character type.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Mainly i think that setting up prefab data from code is quite horrible UX.
    We are very committed to making a great workflow around editing game object based scenes and converting them to entities. Making it so that after conversion the game objects are not even loaded in the game (See SubScenes)
     
    FROS7 and Zoey_O like this.
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Conversion workflow is not Hybrid Workflow, it’s not even related on Pure or Hybrid. It’s just a tool, and which result it gives - on you :) It’s for more familiar data preparing, as Joachim said above - setting prefab data through code is horrible.