Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

HP bars (canvas) for a lot of enemies

Discussion in 'Entity Component System' started by kro11, Dec 21, 2019.

  1. kro11

    kro11

    Joined:
    Sep 23, 2019
    Posts:
    95
    I would like to make an HP bar over every enemy. Need to update the data and rotate them to the camera. After "convert to entity", it disappears. Is it not currently supported? If not, are there any alternatives?
     
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    UGUI/Canvas is not supported in ECS/DOTS
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Alternatives is make your own bars system. In our game (WIP) I implemented it as JobComponentSystem which collects data from entities and filling couple of NativeArray masks for Post Processing Shader, after that just routine post processing shader drawing masks.
    Here example (when I press Alt bars drawing):



    Another solution is write simple unlit billboard shader (with or without Z-test for drawing or not, over all objects) and draw bars same as any another entity. For example Indicators System in our game:
     
    starikcetin, PhilSA, bb8_1 and 7 others like this.
  4. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    I did this recently using a simple quad, a shader and the new material param support in the hybrid renderer and of course with instancing enabled.

    Based on health calculate the percentage and send that as a "fill" float param to the shader graph.
     
    JakHussain, mkracik and Antypodish like this.
  5. kro11

    kro11

    Joined:
    Sep 23, 2019
    Posts:
    95
    If this is done through the shader, then I will have to create new material for each HP bar of the enemy. Does this affect performance? Or am I misunderstood?
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    No. In case of indicators it's same shader where by property blocks we change offset in atlas. In case of our HP bars we haven't any material - it's post processing shader.
     
  7. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    In my case its all one instanced material, so done in 1 draw call.
     
  8. kro11

    kro11

    Joined:
    Sep 23, 2019
    Posts:
    95
    If I change the float param in one object, then all the others change. How to make them independent of each other?
     
  9. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    kro11 likes this.
  10. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    485
    Does this work for all render pipelines?
     
  11. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Only HDRP. They said they will look into supporting URP in Hybrid around mid next year.

    If you need urp then your best bet is Eizenhorn's approach.
     
    ScriptsEngineer, Opeth001 and Singtaa like this.
  12. ScriptsEngineer

    ScriptsEngineer

    Joined:
    Jun 8, 2018
    Posts:
    37
    Currently works with URP even in Hybrid Renderer v1, only updating the post
     
  13. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    @ScriptsEngineer Which URP version? I'm on 0.9-preview55 and I can't make it work
     
  14. ScriptsEngineer

    ScriptsEngineer

    Joined:
    Jun 8, 2018
    Posts:
    37