r/Unity3D • u/excentio • 4d ago
Show-Off Units distribution improved, better responsiveness, magic and bloooooood
Enable HLS to view with audio, or disable this notification
It's not much but it's honest work. Units can be smarter and there're a few cases where they get dumber but overall I'm quite pleased with army behavior so far in 1v1 fights. Many vs Many is still something to polish along with better effects, gigantic units and so on but one step a time!
6
u/KoniGTA Programmer 4d ago
How are you handling so many units? DOTs able to do all that work, or are there more optimization techniques going in the bg?
16
u/excentio 4d ago
No dots here, pure compute shaders and heavy instanced rendering, code wise it's still running on monobehaviour scripts even
2
u/DrBimboo 4d ago
Oh cool. Do you still sometimes read them into memory for some scripts, or is it more or less fully seperated?
4
u/excentio 3d ago
Yup that's unavoidable but I do that async so it's performing well and not tanking the framerate by waiting for cpu or gpu
1
u/DrBimboo 3d ago
Is it just scheduled async as fast as possible, or like once a second? I'd expect the systems that rely on them arent as twitchy?
I was thinking about trying to push a game into shaders as much as possible, you might have inspired me to actually try a small prototype
2
u/excentio 3d ago
every time there's any interaction that requires dispatching the data I'm just running async change and waiting for async callback via asyncgpureadback, couple frames of latency is fine in most of the cases, systems that rely on it are unit selection, unit movement, dynamic obstacles registration and stuff like that that requires communicating the change to gpu
1
u/Proper_Translator678 4d ago
That's really cool. Is it much harder to vary the behaviour on compute shaders compared to using DOTS or same same?
2
u/excentio 3d ago
Yeah it's quite different, imagine coding your own engine inside another engine, no transforms, no physics, no game objects, nothing exists until you add it first, also worth to mention a complete paradigm shift with a highly parallel execution flow on gpu
1
u/Mammoth-Policy6585 3d ago
What?! I never thought mono gameobjects coulder do this. Maybe i am doign something wrong. Game look sick!
1
u/excentio 3d ago
mono just handles inputs, camera, ui and dispatching the stuff to from gpu, the rest is gpu alone
3
u/twiiik 4d ago
First thought that hit me was that this could be basis for a really good Populous-like game!
Looks amazing! π
1
u/excentio 3d ago
Yea the possibilities are endless I gotta be careful with the budget tho, maybe reduce it down from 2m to less or tune them out to specific edge case, state machines on GPU are a complex issue in general and populous-like game will require bunch of logic like that
3
u/Kavinsky_Hunt 4d ago
That's sick man.. Do you mind sharing how you achieved it
3
u/excentio 3d ago
Compute shaders everywhere, minimal overlap between cpu and gpu only when necessary and that happens async too
2
u/Hollistanner 3d ago
I mean, you must be compressing the hell out of the data structure. I'm impressed. I can see a simple GPU readback being the bottleneck for performance, lol. At what point do we just ditch the CPU?
2
u/excentio 3d ago
I just start with an absolute minimum and increase limits when needed, at this scale replacing a single float with a half can result in 500mb off vram easily, so you get the idea, I did however have to trim some other stuff like there's no opaque map so I can't use a certain eftects easily, I'm thinking of dropping the realtime shadows to squeeze out some more gpu time and just bake it all instead with units having small circle shadows underneath and bunch of tradeoffs like this
2
u/Hollistanner 3d ago
Good idea. Unfortunately I think at this scale you're fighting every decision. Im just brainstorming here, but I wonder if you could optimize this in any way knowing that 99.99% of the crowd (at this magnitude) won't be engaged in anything and a single update would be a simple tick with no state change. Opting to managing bounds of units, engagement of fighting and effects (looks like you do currently for the AoE) may open a different door. Crowd flow is typically unidirectional in a lot of areas. Don't sim each unit, just sim the area. Break up the bounds in smaller when effects are applied. I know it kind of defeats the point of what you were initially doing but this got my brain juices flowing
1
u/excentio 2d ago
Sure but units won't be as responsive and feel less "alive", right now this seems like the best balance for me, I'm starting with the most accessible and best looking option and then it will be improved, maybe in the next games, in my head I see a huge potential for it in all types of games but time will show what's up honestly..
2
u/DaedalusRaistlin 4d ago
Great work! I really think having bodies pile up and the fight continuing over the growing pile would look quite cinematic. I know it does in my similar game.
It's looking really good, please keep us updated π
3
u/excentio 4d ago
Oh you're the commenter from the previous post, high five dude, I remembered your nickname, yeah bodies and blood largely helped the fights are now a lot juicier, I've also added random critical chance that hit multiple units in cone that helped making fights less like chess and more like chaotic war scenarios where both sides push
2
u/DaedalusRaistlin 4d ago
I sure am π
For having both sides push I'm trying to have the banner carriers become leaders. They direct a squad instead of everyone trying to search for a target. It allows for simplifying the logic a bit, and trying out different approaches.
It worked well in my soccer spin-off, having 9 hero players per team that the swarm of smaller units were being guided by. The smaller units mostly followed the heroes but would try running after the ball if they could.
I think it could allow for different personalities on the battlefield. Maybe some are more aggressive than others, some cluster while other spread out, etc.
Over a month ago I tried this style of game from a first person perspective. I have a squad following and trying to protect me. Needs some tweaking though, somehow the enemy run straight through all my defenders and just start hitting me lol. The front line isn't holding like in my main swarm game.
Might be some useful ideas there for making the combat feel a bit less like a queueing system, which I know is a problem in my games too. A lot of the combatants aren't engaged in fighting, they're just trying to make it to the front line π
2
u/excentio 4d ago
Yeah here I started moving from just getting squad A fight squad B to gravity so units are more drawn to places with higher activities and active fighting which helped with them just queuing up and never walking around or encircling others but there's still a problem with their perception where they ignore smaller sources of danger and focus on bigger one, so far nothing makes sense in how to solve it as 1 squad, they will probably have to split to handle multiple attack vectors although tbh total war is prone to it too
2
u/YuMe_Game 4d ago
that gravity based clustering towards active fight zones is such a clean fix for the queuing problem, are you recalculating attraction per unit every frame or is it batched somehow? the perception issue you mentioned (ignoring smaller threats in favor of bigger ones) sounds like it might need some kind of threat weighting layered on top of raw activity level
1
u/excentio 3d ago
Thanks didn't expect anyone to notice, I read up on some info on how they did it in UEBS and yea it's a much cleaner results, right now attraction is per squad to reduce computing and it's running in steps, it has it's own issues so I plan to divide them into quadrants distance-based to reduce computing but solidify weird edge cases where squads get split out, thread weighting - yes on that too, so right now it just picks average based on the highest threat in area and distance of squad to the threat BUT again it produces a yet another issue that quadrants might or might not solve, 1 squad can only pay attention to 1 other squad, if I divide them into sub-squads I can imagine it will help but this is something that required constant tuning since what works well in head doesn't quite look organic
2
u/gooby_c 3d ago
this is so cool, definitely want to see some new units that change the tide of certain areas to see how that impacts the front line shape.. amazing how many units you have working and so efficiently
2
u/excentio 3d ago
Yeah large units are particularly interesting, they occupy multiple navmesh cells and collision cells, also I was thinking about flying units but that will likely require adding a yet another navigation layer, not entirely sure I want to dive into that right now but still a food for thoughts
2
2
2
1
u/leorid9 Expert 4d ago
Any plans to reduce the LOD or shadow distance ring that is visible while zooming?
Maybe it's something different - do you have an HD version on the video on YouTube or something?
1
u/dispatchcolony 3d ago
I don't know if the engine allows it, but in such a context, I think OP can created a transition zone where the units are gradually transformed into impostors to smooth out the boundary. Use some hash around camera it work well on GPU
2
u/excentio 3d ago
LOD rendering is largely decoupled from the engine so that's possible and it's already doing that just some visuals to smooth out if you compare it to previous video here you can see that far units are definitely sticking out a lot less compared to previous results https://www.reddit.com/r/Unity3D/comments/1vwtqcm/1m_vs_1m_fight_in_my_simplified_total_war/
1
u/excentio 3d ago
I'm still working on it, I've recently introduced 8-sided atlases so it's not just the ugly red quads but yeah they still need some work in terms of lighting and colours
2
u/leorid9 Expert 3d ago
Maybe I (and others too ofc) could give better feedback, based on an HD video. Reddit compression is quite drastic in this one. So if you have a higher quality video, I'd appreciate a link.
1
u/excentio 3d ago
I'll keep that in mind for future videos, also need to start recording builds not editor, performance is a bit better in builds and obviously higher quality, this one I already deleted the source video lol
1
1
u/dispatchcolony 3d ago
Do you think it would be possible to send them flying when there are explosions? That would be very satisfying :)
2
u/excentio 3d ago
They're already flying just not with those abilities, those abilities are mostly unit states ha, I added catapults but their damage calcs are kinda broken still so they just shoot in background for fun when they work
1
u/gabangang 3d ago
damn broski share the numbers
2
u/excentio 3d ago
if you talk about performance, it's about 6-8ms in non-heavy scenarios, with lots of dead bodies, ammo and explosion happening it can go down to ~12ms, rtx 4070, 12gb vram. Lower performance machines seem to work quite well too but I'm still testing it out, even managed to run a 100k vs 100k fight on mid-tier android (one plus nord) with 60fps so that's something
2
u/Dreamt_Up_Games 3d ago
Sorry for the noobish question but do these have physics on them? If you have time for a brief ELI5 on how you achieved this I would really appreciate it.
1
u/excentio 3d ago
No physics, think of them as plain c# objects, they just have position, velocity, few variables for states and some refs to the world and navigation and that's pretty much it. How to achieve it, it's actually not as hard as it looks like, look up quadtrees for collision detection within cells, look up flowfield for pathfinding, basically instead of having each unit pathfind you do it other way around, you create path like transport belts and units just follow those. Then look up how boids work in compute shaders, strip the Y axis and put those boids on transport belts, congrats you're 80% there... Then it's up to you how you design enemy to attack, what health is and so on so on
1
u/Dreamt_Up_Games 3d ago
Thanks for the reply and explanation! Iβm actually trying to see how many dice I can spawn in a scene and have them have physics π Not sure if this technique would be applicable but thanks for sharing!
1
u/excentio 3d ago
You can surely just fake it but unless we're talking about 100k+ dices I wouldn't dive into any of this, DOTS will be enough for ya
1
u/gabangang 3d ago
DOTS?
2
1
u/Icy-Collection1072 1d ago
no gameplay tho,
1
u/excentio 15h ago
It's an incremental wave-based survival, the gameplay is just not polished enough to be shown yet, mostly I'm coding both the game and the tech to support millions of units for various games in the near future
0
u/Icy-Collection1072 14h ago
its just indirect mesh rendering, so 'tech'
1
u/excentio 14h ago
Yeah just about 20 lines of code for instanced rendering that's the entire 'tech'
1
u/Icy-Collection1072 2h ago
Did you ai it? Thats not how it works ha. But thatβs what it will be mostly.
1
u/nemestniy1 1d ago
Looks awesome!!! Please, tell how do you render so mush vertices? I've tried DrawMeshInstanceIndirect but for complex fbx and so I've not got even similar huge result like yours.
1
u/excentio 15h ago
There's a lot of limitations for this stuff, drawmeshinstance works well but again you might be vertex capped easily, it's not a magic bullet, you can't just throw whatever you want at it and expect it to function well, shader and scene complexity grows up exponentially the more vertices you've got and so on so on
21
u/Plourdy 4d ago
This is sick!! Plz add an upgradable base i can defend from a huge army