#Select/Hover Effects

1 messages · Page 1 of 1 (latest)

mental radish
#

Hey, so I'm relatively new to using ECS in Unity.

I am trying to make an RTS-like game with thousands of entities (possibly tens of thousands).

What are the best practices for trying to achieve a select/hover effect? I currently have a working system where I have a "HoverSelectRing" that is a child to every unit. Upon hovering, I remove the "DisableRendering" component from this child. I add this "DisableRendering" component back when I am not hovering anymore.

I am concerned regarding the performance since this is a structural change across thousands of units. There is not much material online regarding this behavior. I have tried baking my own "HoverMaterial" and "SelectMaterial" in an authoring component in an attempt to get access to the "MaterialMeshInfo" to toggle it on and off, but am a bit lost on where to go next.

Is my starting approach wrong? Is the performance hit from the structural changes even big?

obsidian dragon
#

Upon hovering, I remove the "DisableRendering" component from this child. I add this "DisableRendering" component back when I am not hovering anymore.
Is there a reason why you can't simply use IEnableableComponent for this tag?

#

I am concerned regarding the performance since this is a structural change across thousands of units. There is not much material online regarding this behavior.
The fact it is a structural change fortells the bottleneck if you're going to do it multiple times for multiple subsequent frames. Though once in a while may be fine, you should better run some benchmarks against your specific cases.

mental radish
# obsidian dragon > Upon hovering, I remove the "DisableRendering" component from this child. I ad...

I don't think the DisableRendering component has an "IEnableableComponent" per documentation.
⁨⁨⁨⁨c# public struct DisableRendering : IComponentData, IQueryTypeParameter⁩⁩⁩⁩

And yeah, I agree. Since it's an RTS there might be many situations where I'll be reselecting multiple thousands of units at a time and I'd want any optimization as possible when considering these.

To clarify, the DisableRendering is a component from the Unity packages and not defined by me.

obsidian dragon
mental radish
cloud bramble
#

You just need to compare the cost of adding/removing hte disablerendering component vs toggling MaterialMeshInfo on and off

#

i personally avoid structural changes so would use MMI

#

but i would probably just have a completely separate solution here

#

i wouldn't add the effect to every thing in the project

#

just create/move the effect to something when enabled

mental radish
cloud bramble
#

when not selected, you can just disable the effect by disabling MMI

#

the differenc ei just you don't have 100s or 1000s of these extra effects that are sitting there unused. in practice probably not a big deal, if you have a working solution that is just 1 effect per object just use it

#

i doubt this will be a bottleneck anytime soon

mental radish
#

But I think I got what I need. The rest I can just test and see what's the best solution for myself.

cloud bramble
toxic bloom
# mental radish Hey, so I'm relatively new to using ECS in Unity. I am trying to make an RTS-l...

If you make a big RTS, you'll soon find out that the LocalToWorld ComputeHierarchySystem (or something like that) can be a pain in the ass (performance wise), and scales badly when your 10 000 units have child entities. That's why I opted to Add/Remove the "Disabled" Component for now personally, on the units UI elements. This Component disables the rendering and keeps the entity from any query in any System, so it's kept out of the LocalToWorldSystem for example.

#

Turns out adding/removing 500 components in a single frame isn't that bad as long as it's periodic

#

Now of course you must Add/Remove before the TransformSystemGroup, else the UI will visibly snap from the last position when you added Disabled

mental radish
# toxic bloom If you make a big RTS, you'll soon find out that the LocalToWorld ComputeHierarc...

I guess now I'm going down a rabbit hole... so I created 50,000 entities using ECS, I GPU instanced the materials as well.

From my testing, this is what I found. I can get 50 FPS with

  • 400,000 entities with NO selection / NO hover childs
  • OR 100,000 entities with selection child, no hover child
  • OR 50,000 with both selection AND hover children.

im assuming since im literally tripling the number of objects basically, I have to lower my total entities.

Is there a more optimized way to do "selection/hover" effects instead of creating 2 children and enabling and disabling their rendering components?

I tried a shader graph approach but it only seems to broadcast the selection ring correctly when projected onto a quad, which then im assuming would naturally be childed to my "unit"

and this is with no animation. completely static objects so far... which will change in the future

toxic bloom
#

I don't remember if the LocalToWorldSystem is Bursted, but if it is, make sure you do your tests with BurstCompilation ON.

#

Beside all that, 50 000 is a LOT, I'm not sure what your game looks like but maybe you could come up with another solution like a shape that circles around the pack of selected entities for example

#

improvise, adapt, overcome

mental radish
#

yeah that's probably the most realistic thing to do... otherwise im rendering up to 100,000 effects just on selection/hover alone since i wanted a separate effect for hover and a separate for select... with that many entities it's just a lot. Okay, I'll think about it some more.

At least every roadblock is something new learned

cloud bramble
#

this is why i was suggesting just creating a pool of the effects
400,000 entities, no children
a pool of say 100? (whats the max selected, you can make it dynamic anyway) selection and hover effects

#

btw having children in entities is pretty expensive

#

just the fact you're creating 2 children per entity, even if they had no graphics on them is a lot of overhead if you're moving frequently

#

have you benchmarked the cost of calculating these hierarchies?

mental radish
#

the reason why i have so many entities is because im doing a total war style game

cloud bramble
#

i'm all for huge entity count

#

my base testing amount is 200k for all my libraries

#

but i sometimes test things at 20million

#

hierarchies is one of the things that start limiting the max count of entities you can have - one of the reasons why unity by default deparents all objects in a subscene unless requested.

mental radish
#

yeah it’s fun figuring out where my bottleneck is since it gets me involved in all the different systems… but yeah i figured i’d see the limitations of what i currently have and can optimise since the goal is to have two huge armies fight

#

like at least 20k per army

cloud bramble
#

pushing high unit count is the real joy of entities

#

i can have a few dozen, maybe if i'm lucky hundreds of gameobject units fight

#

or i can have 1000s of entities fight

mental radish
#

i just have a lot to think about cause the entities will be animated, so from what i’m reading i’ve gotta batch the renders with my skin meshes, multithread where possible, etc. the animation part and rendering is what i’m completely brand new at… at least the other concepts i’ve learned from just regular software dev

#

but yeah like at least 30-50k animated entities fighting each other across a large battlefield

#

so yeah that selection effect being both hover and select.. two children basically… it definitely tanked the FPS so i have to look at alternatives

#

the pool makes sense but a lot of the times you’re selecting all units

#

so i need to adapt around the limitations

mental radish
cloud bramble
#

back before 1.0 and where there was no 128 entity limit per chunk

#

i tested with 110 mill entities on one of my libraries

#

100 million effect entities targeting 10 mill entities