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?
UGUI/Canvas is not supported in ECS/DOTS
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:
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.
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?
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.
In my case its all one instanced material, so done in 1 draw call.
If I change the float param in one object, then all the others change. How to make them independent of each other?
Material Property Blocks. PerRendererData attribute in shader. Attribute for Hybrid Renderer in context of DOTS.
https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.3/api/Unity.Rendering.MaterialPropertyAttribute.html
Does this work for all render pipelines?
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.
Currently works with URP even in Hybrid Renderer v1, only updating the post
@ScriptsEngineer Which URP version? I’m on 0.9-preview55 and I can’t make it work
@Srokaaa in the 8.9.0 version