#archived-dots

1 messages · Page 175 of 1

amber flicker
#

Don't know what you're talking about... that's just my aura... definitely not leaving a trail of ash behind me

violet cosmos
#

FWIW guys, I've fully migrated off DOTS, and not even thinking about it. Later, I might have some compute to run on jobs to free up the main thread, but... That's for proc gen chunks happening over a number of frames

tardy spoke
#

I'm in same boat, figuring out what to do for my project. 🤔

If I can get my weird "ECS references GO's directly" thing to work, I might stick with the paradigm and migrate things back over

#

I really think that definitely should've been an officially supported workflow.

trail burrow
#

@tardy spoke think of all the time you put into DOTS that you could've just worked on your game 😄

violet cosmos
tardy spoke
#

@trail burrow haha that's true. Probably about time for me to actually learn some OOP stuff anyway. Good to know it.

deft stump
#

so alex is now giving up on dots

#

good for you man

tardy spoke
#

Ehh not sure, hahaha

deft stump
#

welcome to the bright side

violet cosmos
#

@tardy spoke Instead of MonoBehaviours having logic... Just have them hold data, and register themselves with a singleton. Then, loop through all of them in the singleton per frame

Sometimes that's easier to manage than the Start/Update lifecycle

tardy spoke
#

I like the ECS paradigm, I don't actually really care about DOTS particularly

deft stump
#

I like the ECS paradigm, I don't actually really care about DOTS particularly
@tardy spoke you can just make one yourself

#

XD

trail burrow
#

I like ECS as a pattern, but i dont like unitys implementation/hpc#

tardy spoke
#

I'll probably split the project for a couple weeks, one version on Svelto.ECS and one on straight OOP and see which I prefer.

deft stump
#

you're gonna spend more time on that project than necessary now

#

XD

trail burrow
#

it hurts me to say, but if you want to use ECS together with gameobjects the easiest is entitas

tardy spoke
#

Svelto's learning curve unfortunately seems fairly steep, and the paradigms are different from Unity ECS which doesn't help.

#

Entitas? Doesn't it have that compiling step or something weird?

trail burrow
#

yeah it does

violet cosmos
#

Nothing wrong with organizing your code in an ECS if that's the way you feel more comfortable and think you can maintain/grow it better. Better than organization through spaghetti

trail burrow
#

My card game i made a completely custom architecture specifically for it

tardy spoke
#

Yeah, I'd have to read some architecture books to not spaghetti an OOP project

trail burrow
#

Which relies on immutable game state, etc.

tardy spoke
#

which is fine, and I probably would just use OOP if I was confident I could write large architecture without spaghetti

violet cosmos
#

Not spaghetti in a Unity project is... difficult

tardy spoke
#

Yeah, well the other problem is the project is huge so an extra large chance of epic spaghetti

#

Scriptable Objects seem like they can help fight the spaghetti.

#

But... soooo much spaghetti...

trail burrow
#

SOs are great

#

for static data

deft stump
#

I feel like putting them in Assembly definitions might also help.
BUUUUT... still so much spaghetti...

trail burrow
#

we use a metric ton of SOs

#

for configuration data

violet cosmos
#

ScriptableObjects are just data. It turns into a mess instantiating and keeping track of them. Treat their methods as just read only, and the data as immutable

trail burrow
#

yes we use them as immutable data

#

@violet cosmos fwiw the actual data is always a POCO, wrapped in an asset... which means you dont need to deal with any of that annoying instantiate shit

violet cosmos
#

I went down a route once of trying to instantate them, didn't work out so great and ended up being a mess

trail burrow
#
abstract class Asset
{

}

abstract class AssetWrapper : ScriptableObject
{
  public abstract Asset Asset { get; }
}

[Serializable]
class Spell : Asset
{

}

class SpellAssetWrapper : AssetWrapper
{
  public Spell Settings;
  public override Asset Asset => Settings;
}
#

like this

#

basically just using ScriptableObject as a way to expose the C# class to the editor

tiny ore
#

So to reuse unity serialization for the static data (that we can load dynamically on demand)

tiny ore
#

Please, post this question in one of the Art & Creative channels

north stream
#

ok

#

sorry

tiny ore
#

[portuguese] Também sou brasileiro. Esse canal é para perguntas sobre programacao usando DOTS/ECS

low tangle
#

currently looking at migrating from dots, but the grass isn't always greener on the otherside

#

thinking about grabbing EnTT and utilizing that over dots/ecs

amber flicker
#

@tardy spoke @low tangle @deft stump are your issues all basically to do with the workflow of mixing ecs & traditional monobehaviours e.g. animation, sound, pfx etc?

low tangle
#

its a lot of things, but yes workflow is one of them

amber flicker
#

I'm trying to get a better grip on the issues. When you put e.g. a text field in a subscene, the entity gets that text field as a companion object and then in a system it's easy to say ForEach((Entity e, TextMesh tm, .. etc. Do some of the MonoBehaviour things not work when you do that? Or is it about secondary things like save games, networking type of thing?

low tangle
#

well, its the complex hybrid problems that are issue

#

like say my IK + animation is all tied up to the direct structure of my users UGC humanoid models, which utilizes animation jobs for computing the blending between the various sources

#

all of that does not jive well with ecs at all, and requires a lot of hacks to utilize, let alone something have a discrete lifetime is a pain in the ass to deal with in ecs

#

animation, retargeted skeletal models, animation jobs, ugc are all a major pain point when it comes to ecs. which is to be expected, as I always planed on doing them hybrid

amber flicker
#

hmm.. can't that basically all sit in monobehaviour land? Is it trying to use the new animation package and trying to represent the state machines that are painful?

low tangle
#

I'm not using the animation package, its all hybrid

#

that interconnection between that ecs world and the hybrid objects adds a ton of complexity to something so simple

#

I've got at least 3 ecs worlds in my project being ticked as well

#

I'm just finding I'm spending more and more time on hybrid things, putting more and more into monoland

#

that there isn't a point in leaving anything in ecs at some point, it would vastly reduce the level of complexity I'm bearing in the project

amber flicker
#

I'm wondering how much that's about mapping gameplay to DOD and like how much is due to the friction where OOP & DOD meet.

low tangle
#

well, during a burn out break about half a year ago I build a custom engine in c for some hobby games I was working on. And in this engine I built it all with ecs at the core, rendering, animation, basic physics. If I had the option in unity to build the whole game using ecs, I would already have finished this game a year ago. I was mistakenly counting on unity to roll out the missing systems over time, but it really didn't pan out that way

#

you can 100% build a game with ecs / dod whatever you want to call it, because thats how engines used to be built.

#

forced into hybrid, and conversion workflow ended up not being compatible with my project at all, as almost everything is spawned at runtime, from ugc asset bundles

amber flicker
#

So do you think for you, let's say when dots timeline & animation are done, that'll go a long way to being an ecosystem you can be productive in?

low tangle
#

for me, I don't think I'll pickup dots again until all features of the engine are supported from ecs only, no hybrid conversion

hollow sorrel
#

are you talking about entt with unity or roll your own engine

amber flicker
#

yikes... 2040?

low tangle
#

or, if hybrid conversion becomes seamless

#

but all functionality works though hybrid

#

the games I've been building lately dont usually have lots of up front content creation which, I'm realizing more and more isn't compatible with unity

#

@hollow sorrel I've got two prototypes I'm working on right now, to see if they are a honest solution to the problem or just stupid. one is to finish up a core ecs+physics+matrix math core plugin outside of unity, that is plopped into the project, and tells unity where to place assets on screen. all physics, entitys, gamelogic is done within the core

#

currently building that in cpp, using entt and a few other libs.

hollow sorrel
#

what is the other

low tangle
#

well, its sacrilegious, but ||adding ugc support to unreal and porting to it||

hollow sorrel
#

daymn

#

i can't imagine how much work it would be to basically remake your game after working on it for 2 years

#

o wait i can because that's what i'm doing

#

but it's a lot of work

low tangle
#

its not a for sure thing, but its painful to think about

#

yeah only a million loc to port over, or convert to that engines modules

hollow sorrel
#

i've been remaking my game due to ecs and thinking about doing it again would prob be enough to make me quit

low tangle
#

I should've just wrote a engine to begin with, would've finished it before ecs animation came out lmao

#

but making your own engine is a trap, cant forget that

hollow sorrel
#

i feel like if they drop dots tomorrow i'd either be stuck with this and still finish it despite having no more support, or drop my project altogether

low tangle
#

it would make me quit, but quiting was never a option, I'm just trying to find a solution that I can live with for the next 5 years

#

nah, they wont drop it

#

its just taking awhile for them to finish it

hollow sorrel
#

tbh i think going custom engine entirely is a valid option for you

#

if you already have the exp to write a good core the next hardest thing is rendering which sucks, but you could prob find a decent framework for that that lifts most of the work

minor sluice
#

I think it is fine if you froze the project with a certain tech stack - package version combination and just continued to develop with that, but would suck if you can't use new features then if there would be any,

don't think unity will drop it

#

there has been another interesting thing, unity filed paperwork for their initial public offering and it is publicly available

#

so that might shed light on some of their plans etc., but I haven't really checked it out

low tangle
#

they've put too much into it, sunk cost will keep it alive unless, like major bad press started attacking the bottom dollar. so not dropping isn't even remotely a thing

hollow sorrel
#

i've thought about custom engine many times and i think that's where i'd be now if dots was never announced

#

and it'd prob be further along than dots lolol

minor sluice
#

that one post on the forum thread where you contributed too was so funny "it is time to admit defeat"

low tangle
#

thats why I'm not trying to be a naysayer, just a dev who made a mistake and bet on unity's roadmaps in the beginning

minor sluice
#

custom engine would be something I never touch, I want to make content/games and maybe tooling for games, and not only tooling for 4 years or something

#

so extending an existing engine seems like the more reasonable choice

low tangle
#

yeah I've read so many books, and written a few toy engines at this point, I'm pretty sure I could cobble together something to service my game pretty dang quick

minor sluice
#

oh, awesome

low tangle
#

but it would always be bad UX/tooling

hollow sorrel
#

i thought the same at first but i realized i've spent more time writing custom tooling in unity than writing game code :/

low tangle
#

its never on the level of any made for everyone style engines, there always rough, only changed to service the game at hand

amber flicker
hollow sorrel
#

the main things that i use unity for apart from DOTS is rendering and cross-platform building, which are huge things, but everything else like editor etc wouldn't be hard to build

minor sluice
#

so there are certainly people that are capable of it, but imo, it is hard to impossible to compete with any of the big engines, including godot, and there are so many things to keep in mind,
documentation, being able to export to certain platforms, input abstraction across different os etc. if desired,

and maybe your engine will be better in one specific thing that you focus on, but it will probably be worse in every other aspect

low tangle
#

yup which is why we never go for competing with the big boy engines, you build a engine in direct service for your game at hand.

solid flume
#

How long does it take you to build an engine?

minor sluice
#

unity seems to get a lot of criticism, but at least you can still use it to publish to apple devices Kappa

low tangle
#

not a 2d game? dont build any 2d rendering support, shaders, passes etc

#

6 months - 5 years

solid flume
#

My biggest complaint with unity is that their 2D is awful

hollow sorrel
#

sounds about right

#

^in reply to june

#

i'm biased but tbh i think unity's 2d tools are actually pretty decent

solid flume
#

Does anyone have experience with godot?

minor sluice
#

hmmhh, yeah, but I still like their 2d, even if it is not true in the standard pipeline,

also another issue for me with an engine that it can be an endlessly ongoing process and it might be easy to lose yourself either in details or you might have to pay technical debt big times later on if you wasn't careful about architecture and possible bugs early in development

#

just sounds scary to me

coarse turtle
#

dependency locking on frameworks too

solid flume
#

Just working with 2D and having the issue that internally the API is designed for 3D and 2d is just hacked on top is not fun to deal with

low tangle
#

yup, its a real can of worms you dont want to open

hollow sorrel
#

yeah but when that happens you can just go public stock market

low tangle
#

which is why I've never committed on a engine, other than in toy projects

coarse turtle
#

Like seeing handmade hero getting built from scratch was cool seeing how it all pieced together

#

but it can be very time consuming depending on your budget 😐

worldly pulsar
#

I think the fact Handmade Hero is 6 years in, and the game as is could probably be made in Unity in a month or two is telling 🙂

low tangle
#

exactly

#

5.9 years of aimless engine dev, .1 year of game dev

#

doesn't help that indy games tend to wander when they've been around too long, that and hyperfocus

worldly pulsar
#

My attempt at writing a game on my own engine ended when ~6 months in I realized I should have integrated Harfbuzz instead of rolling my own text layout (reasons I don't remember anymore). Bikeshedding is a project killer.

minor sluice
#

think there are some pretty neat things you can do in unity because everything is 2d,
people say godot has outstanding 2d, but I haven't used it yet

trail burrow
#

do not build your own engine

#

it's a fools errand

low tangle
#

yeah I know

solid flume
#

Ya know I'm bored so might as well try out godot

#

Not gonna use it, but what are the chances there exists some form of ECS for godot?

coarse turtle
#

I think it's an object oriented workflow

#

might be an external plugin you can hook into it

vagrant surge
#

godot component system would match an ECS quite well

#

the issue is that the lead dev hates ECS, by itself

#

so he will never want anything even close to it (even if the current godot system could be implemented as an ECS without user side changes)

coarse turtle
vagrant surge
#

thats not official, just some random guy

#

i used ECS lib entt to optimize the godot renderer

#

you can see it in my fork

coarse turtle
#

yeah it's not official - iwas just browsing around

vagrant surge
#

but i mean, the guy is still using linked lists everywhere

#

in 2020

low tangle
vagrant surge
#

and refuses to implement a proper Vector/Array

#

and bans everyone from adding better data structures

#

adding a data structure is banned unless you have incredible good reasons for it

low tangle
#

what the hell

vagrant surge
#

thats why godot spams linked lists so much

#

he forbids people from implementing alternatives

#

and godot Vector (nativelist equivalent) is trash

low tangle
#

I knew the engine had bad decision smell, but that really proves it

solid flume
#

I hope it doesn't turn into another project lost to the void because of crappy design decisions by high level people

vagrant surge
#

i actually offered the guy to implement better data structures to replace the linked list spam in the renderer, and also implementing those changes to make the renderer faster. He refused

#

nah, they are god tier at marketing

#

just see them with their fancy PBR and fancy GI

#

and still no LODs

#

also the fancy PBR is a forward renderer and has no postprocessing whatsoever other than badly-impl bloom and ssao

low tangle
#

I mean, anyone can read though learn opengl and put together pbr now

#

I love pbr, but its practically copy paste these days

vagrant surge
#

i have my own crappy vulkan engine lol

#

tho i use it for research

solid flume
#

My first impression is why are the lines so damn jagged

#

In the 3D renderer

vagrant surge
#

@solid flume because he has no antialiasing

#

literally

#

other than msaa

solid flume
#

Wuht why

vagrant surge
#

but msaa isnt enough on a PBR renderer

#

couse he refuses to add it

solid flume
#

Because it needs more than linked lists?

vagrant surge
#

i honestly dont know why they dont even add fxaa

#

taa is quite tricky, i can understand

solid flume
#

I love how the UI is structured just from opening a project

vagrant surge
#

ive had a pretty hard time adding TAA to my engine and my implementation is rubbish

solid flume
#

But the jagged lines are just offputting

low tangle
#

you ever do anything more with entt in ue4? @vagrant surge

vagrant surge
#

yeah. Latest thing was making a job system

#

think like unity job system

#

tho not exactly the same type of thing

#

you declare systems, each system with a task-chain, and each task has read/write dependencies (like in unity)

#

then a scheduler sorts everything and executes everything safely

#

fun stuff

low tangle
#

find anything interesting out with it?

vagrant surge
#

that unreal engine bottlenecks crazy hard

odd bay
#

thats why godot spams linked lists so much
Is there any reason as to why he's using linked lists instead of std vectors? I haven't done C++ in a bit, but as far as I remember, they're very easy to use

vagrant surge
low tangle
#

they are

vagrant surge
#

and this is the job-graph that is autogenerated

low tangle
#

how many transform copys is that

vagrant surge
#

@low tangle 400

low tangle
#

oof

vagrant surge
#

instance mesh draw is updating 2000 instanced meshes

low tangle
#

is there anywhere you can apply to the matrix directly, without dirtying it?

vagrant surge
#

because of course unreal has ZERO fucking way of mass-updating instanced meshes, it has to be 1 by one

#

not in this case without mayor changes to the engine, but its possible

low tangle
#

because I'd bet on them doing a lot of garbage work

vagrant surge
#

i did it for a PUBG research project

low tangle
#

ah alright

vagrant surge
#

speedup was about 5x in that research

low tangle
#

very nice

vagrant surge
#

but it was super unsafe

low tangle
#

you ever going to release any of this? I'm thinking about doing the same, entt in ue4

vagrant surge
#

unreal transform system does tons of things. So if you want to do it yourself, there is a hell of a lot of things to take care of

#

its all opensource

signal flicker
#

hey guys, if i were to convert my whole project to dots rn, would it be a pain in my ass? can i convert to dots in pieces, meaning can i use dots and standard physics/ gameobjects at the same time? and while i doubt it, will hdrp make any impact on it?

low tangle
#

oh within the github?

vagrant surge
#

ye

low tangle
#

awesome dude, thank you

vagrant surge
#

this job scheduler thing is the current commit on the ECS_unreal project

low tangle
#

now if I can just figure out UGC

vagrant surge
signal flicker
#

the project has full custom networking and alot of physics based weapon ballistics

dusky wind
#

@signal flicker yes just use the Jobs system

#

If all you need is off main thread compute that is

vagrant surge
#

the problem i allways run into when trying to do eCS stuff with unreal, is that the UI just doenst support it

#

and creating a custom ui for that requires a LOT of engine changes and crazy shit

low tangle
#

gotcha

vagrant surge
#

ive tinkered a bit with codegen

signal flicker
#

jobs system? i havent played around with dots yet

vagrant surge
#

scroll down to the end

#

look at all those ucomponent wrapper things

#

btw, you cant put that in a macro

#

nor a template

low tangle
#

damn, that sucks balls

vagrant surge
#

because unreal header codegen runs before cpp macros, and doesnt support templates

#

its exactly as painful as it looks. Painful enough to develop a codegen

low tangle
vagrant surge
#

with that project

#

i convert this

#

into unreal engine component boilerplate

low tangle
#

not awful, but I've never been a fan of codegen

vagrant surge
#

its kinda like the struct declaration part of a programming lang

low tangle
#

yeah

vagrant surge
#

yeah codegen sucks

#

i also generate reflection metadata

#

and imgui edit code

#

because, of course, cpp has no reflection whatsoever

low tangle
#

yep

vagrant surge
#

so writing editor code/debug code means you have to do it manually

#

or slap a codegen on it

solid flume
#

I don't know basically anything about ECS but everything about godot literally screams ECS to me

vagrant surge
#

because its gameobject system is literally one very little step to be ecs

#

it could be implemented as an ECS

#

with no problem

#

if only the dev didnt hate it lmao

solid flume
#

Especially considering it has c++ support, so stuff like entt could be viable

low tangle
#

yeah, theres a important distinction though, where components are smart or not

#

which they can be in godot

vagrant surge
#

Godot could implement its current scene tree stuff as an ECS without changing user implementation

low tangle
#

thats the 'object' part

#

yeah they could

vagrant surge
#

and then, users could either use the normal stuff they already do (smart oop-ish components), or create ECS components + systems

#

or hell, merge the two

#

it could work quite nicely

low tangle
#

yeah I always wanted to do that myself

solid flume
#

Technically since it's open source couldn't you just fork it, and make it use an ECS

vagrant surge
#

yes

#

some people have done it

low tangle
#

a object, really is just a namespace set of functions, with the context of a set of data

vagrant surge
#

like.. its really not so hard to connect an ecs to the godot scene system

low tangle
#

its why you can do 'oop' in c, where the first param is the struct 'object'

vagrant surge
#

i knew a guy who did OOP in ECS, but in a very interesting way

#

he had components that held function pointers

#

and those functions basically all get a "this entity" handle as first param

#

somethinglike

low tangle
#

yeah thats one thing I really wish we had in dots ecs

vagrant surge
#
struct OnDamageCallbacks {
void OnDamaged(entityID this, entityID instigator, DamageEvent event);
}
#

btw, done through function pointer

#

not virtuals

#

this is a very important thing

#

because it lets you swap them at runtime, and you skip the vtable fuckery

low tangle
#

yeah

vagrant surge
#

this actually did OOP, but better

#

because you can basically swap the virtuals all you want

#

and change the class itself

#

an OOP class is rigid

#

its its own... thing

#

but a class made with this sort of thing is dynamic. You can add/remove members from it by adding or removing components

trail burrow
#

you'll be able to do faux virtual methods in "unsafe"-C# soon

vagrant surge
#

for example a inmortal object could just remove the OnDamagedCallbacks component

trail burrow
#

with the new function pointer stuff

vagrant surge
#

and then add it back when it becomes killable again

#

with damage code doing something like

trail burrow
#

just waiting on that C# 9.0 support in unity

#

😄

low tangle
#

gonna be waitin awhile lmao

trail burrow
#

8.0 coming soon

vagrant surge
#
float damage = 20;

OnDamagedCallbacks* cmp = Get<OnDamagedCallback>(target);
if(cmp)
{
  cmp->OnDamaged(target, this, damage);
}
#

very oop except it works much better than using interfaces, for example

solid flume
#

I really like the entire concept of being able to add and remove functionality through components and having everything just work. I just don't like how convoluted it is to actually do

trail burrow
#

we already have a way of doing this in quantum now

#

but it's just a bit messy

#

but it works

#

or well its not that messy

#

but overhead, etc.

vagrant surge
#

@solid flume the method above is kinda like interfaces, except you can add/remove them at runtime wich is quite fun

#

and very efficient

trail burrow
#

so will be nice when they have this in C#

#

by default

vagrant surge
#

it has kinda the same perf as just virtuals

solid flume
#

I really like the concept

#

It's why I thought of designing my next game as like a lowkey ECS, where each component (in the traditional sense) is as self contained as possible, and as reusable as possible, and as single purpose as possible

#

So I can dynamically add and remove them and have stuff work

#

Instead of a disgustingly large player class

#

Which is a pain to go through and refactor

#

I can't be the first person to come up with this so I'm probably reinventing the wheel in a way

odd bay
#

I try to do that, but I always end up with monolithic classes when I try to avoid GetComponent calls

vagrant surge
#

GetComponent is fast-ish

#

tho in unity ecs is worse than stuff like entt

#

in entt get-component is really cheap

solid flume
#

What if unity used c++

odd bay
#

I'm talking about GameObject get components, not ECS

vagrant surge
#

well of course you should never use those at runtime

#

that one is incredibly expensive

odd bay
#

exactly

#

Unity has a GameObject/Component architecture that forces you into a pseudo Actor architecture because GetComponent is so expensive

vagrant surge
#

on some of my toy code in ecs (with entt/cpp), i use GetComponent a lot

#

the fact that get-component is cheap enough that you never need to even bother to optimize it is great for architecture

worldly pulsar
#

looks at Unity UI doing a ton of GetComponent per frame

vagrant surge
#

in unreal, getcomponent is relatively fast

#

it does a linear search on the actor component array and thats basically it

#

tho it could be made faster by caching stuff a bit better...

safe lintel
#

serious question but in gameobject land(non ecs) if you want to query components what are you supposed to use at runtime, given the performance hit of getcomponent(talking about like a bullet raycasting an object to check for a health component on another gameobject)?

vagrant surge
#

you shup up and enjoy the -ms

odd bay
#

Right now, I just bite the bullet and do the get component

vagrant surge
#

there is not much you can do 😦

#

there is some crazy trickery you could try tho

#

but is it worth the effort?

safe lintel
#

i was wondering if there was some magic hidden stuff i was overlooking all this time

vagrant surge
#

you would have a GLOBAL singleton that holds a hashmap of all gameobjects that have a specific component

odd bay
#

I once tried to replace GetComponent with a global dictionary lookup

vagrant surge
#

to do a "getcomponent", you look up on this hashmap

#

yeah, exactly that

odd bay
#

It was not fun

low tangle
#

select from all components at random, and go to the universe were it chose the right one

worldly pulsar
#

Quantum Computing (TM)

odd bay
#

GetComponent is expensive, but honestly it isn't that bad as long as you're only calling it when it's necessary

low tangle
#

yeah, basically eat the performance cost

#

if only unity reworked that side of the engine extensivelly

#

introducing hot paths where it could simplify things

vagrant surge
#

given the original side is a clusterfuck for sure... that would be hard

#

thats kinda why they are doing unity ECS

odd bay
#

so far the only major bottleneck of my current code has been iterating over a large number of components each frame, I haven't run into getcomponent obliterating my frametimes

safe lintel
#

think the codebase is too spaghetti to even bother?

low tangle
#

hundreds of employees and they can't work towards unspaghettifying it?

odd bay
#

baby steps

#

They fixed Camera.main recently, so that's one bottleneck out of 100 down

vagrant surge
#

what was the problem with camera.main?

#

i know its bad but not sure exactly why

odd bay
#

It was calling GameObject.Find every frame

minor sluice
#

I made some tests with unity 2017 once and to my surprise, GetComponent was far more performant than expected, over many iterations it even came close to dictionary lookup performance

worldly pulsar
#

Camera.main is FindObjectWithTag("MainCamera")

vagrant surge
#

@odd bay ayyy lmao

#

holy shit what

#

ok that is hilarious

#

i just didnt even knew it existed for looong, allways did my cameras semi-manual

odd bay
#

Not sure what it does now, but in a recent build they said they made major optimizations for it

minor sluice
#

I assume that unity has some internal caching stuff in place when it has found a component for a specific object before

safe lintel
#

like man, i could write their engine code with stuff like that lol

minor sluice
#

I read that, either after unity 4 or 5, the GetComponent was already rather efficient, maybe it was different before

worldly pulsar
#

They have an index of all the tagged objects, so in the usual project that has 1 of them in the scene (the main camera) it was actually reasonably fast

minor sluice
#

FindObjectWithTag("MainCamera").GetComponent<Camera>()

#

is literally what it is yes ^^

odd bay
#

I just want ECS to be finished so I don't have to worry about walking into landmines like that anymore lol

vagrant surge
#

with unity ecs model, get-component is slowish

#

on my own ecs, i implemented a workaround

#

flecs ecs (cpp lib, very high end) then also implemented it as it was a good idea

#

now unity needs to implement it LOL

worldly pulsar
#

It was like 3 pointer jumps last time I checked

vagrant surge
#

nope

#

its 3 pointer jumps + some searching

#

either linear/binary/ or hashmaps

#

so its slower than just 3 jumps

#

what i did, is to cache the "get component" state

#

and then, if the entity didnt change archetype

#

i can reuse that state

worldly pulsar
#

oh, yea, there is a linear search through all the components in the archetype

vagrant surge
#

very useful

#

so thats basically what i cache

#

i cache the offsets of the component array within the archetype

#

so the second time you need to access, it goes fast-path if the entity didnt change archetype

#

from hardcore benchmarking, i calculated it as "literally the same as a pointer access"

#

beetween 1 pointer access and 2. And i use prefetch so....

safe lintel
#

what were the advantages of unity's ecs model vs the one that entt uses(besides getcomponent) and why arent they using that model?

vagrant surge
#

@safe lintel because unity model parallelizes better, "merges" better, and has higher perf in high sizes

safe lintel
#

ahh

vagrant surge
#

in unity model, having a background world for background loading or procgen

#

and then merging that to the main sim world

#

is suuuuuuper cheap (algorithmically)

#

in something like entt is trickier

#

entt also has higher memory overhead

#

due to all the maps it has (one per compnent)

#

for optimality, you would use bigger components in entt than in unity ECS. in unity ecs you can spam tiny components to get nice SIMD

tardy spoke
#

Is it possible to GetComponent and set the data for that component from inside a SystemBase for each?

vagrant surge
#

like, for example in entt, a Transform component, that has matrix + location + rotation + scale would be best

#

vs unity where you have each of those be a different component

odd bay
#

wouldn't it be the opposite? I thought you would try and max out each archetype chunk on Unity ECS

tardy spoke
vagrant surge
#

@odd bay it doesnt matter in unity ECS if you have 1 big component or N small ones (with the sasme total size)

#

it ends up about the same

#

but with the smaller components you get better cache behavior so it might be faster

safe lintel
#

gotta use SetComponent on the struct @tardy spoke

odd bay
#

I figured that having fewer archetypes would be more cache friendly

tardy spoke
#

@safe lintel gotcha

vagrant surge
#

@odd bay but you dont have fewer archetypes

#

if those 4 components allways go "together", you have the same number of archetypes

odd bay
#

oh I see what you mean

vagrant surge
#

you only have more archetypes if they are used in different combinations

#

btw. From all of my testing, entt model (also entitas model) excels at low entity counts

#

unity ecs only starts winning at 10k-50k units

tardy spoke
#

Anyone know if SystemBase ForEach loops can be nested or nah?

vagrant surge
#

they can

#

Tiny Racer ecs sample uses it

odd bay
#

Epic said they were implementing ECS for UE5 right?

low tangle
#

no?

safe lintel
#

in the old component system you could but you cant do nested jobs if you are doing .Schedule and not sure how .Run is treated

vagrant surge
#

no

#

but there have been leaks

#

and in current master "github"

#

there is a full unity style ECS, job system included used for optimization on the animation systems

#

but not exposed

solid flume
vagrant surge
#

i dont know

#

never used it

solid flume
#

It's hard to find alternatives to svelto and entitas

#

Can any C# ecs library work with unity or does it need to be specifically tailored?

vagrant surge
#

anything that is C# will work

#

the unity part is for editor support

#

which is super important

solid flume
#

What editor support exactly?

#

Also I've never understood how third party libraries tie in to unity specific things like the rendering or physics engine

vagrant surge
#

they dont

#

for example, entitas just creates game objects that it controls

solid flume
#

So what is the use of these libraries then

#

Why would I use entitas if it can't render anything

vagrant surge
#

because you use it to control normal gameobjects

#

and not all your entities actually control a game object

#

for example

#

in the music game i made

#

i had 1 entity per note

#

and they updated with the timing of the song

#

but i didnt create one gameobject with a mesh per entity

#

not at all

#

when a entity gets close enough to be visible, then i create its game object for displaying a mesh

#

and that logic is done in a pool

solid flume
#

Ah

vagrant surge
#

so the entities are constantly reusing the same sets of gameobject meshes

solid flume
#

Makes sense

tardy spoke
#

I'm having this aliasing problem...

Entities.ForEach cannot use component access method GetComponent with the same type Marble that is used in lambda parameters with write access (as ref).

Is there an easy way around this or something I missed?

coarse turtle
#

marble.hasBeenTargetted = true

tardy spoke
#

weird, thought I just tried that

#

I mustve forgot to save or something. Let me try it again.

safe lintel
#

i think its because you already are accessing Marbles in foreach

coarse turtle
#

Yeah ^

#

GetComponent compiles to CDFE

tardy spoke
#

oh it was because of the unecessary GetComponent in the //only loop through untargeted marbles IF

coarse turtle
#

in a ForEach

tardy spoke
#

CDFE ?

#

lol

vagrant surge
#

that get component is unnecesary, it can be done on the query itself

coarse turtle
#

ComponentDataFromEntity<T>

tardy spoke
#

Right

safe lintel
#

does the lambda take entity queries yet?

tardy spoke
#

@vagrant surge not just unnecessary, it broke it haha.

rare umbra
#

I have a system which reads a transform component. I’d like to determine which entity has the transform which is closest to a given position (e.g. the player) and then update some data on that entity. How would you approach this? Is there a better way than looping through all entities that the system finds and caching the closest one for each entity and then in the next run of the system update the data on the appropriate entity?

#

Feels a bit long winded to me

coarse turtle
#

I guess it depends on the # of entities, for many entities what I ended up doing was hashing their positions and storing them into a spatial map. If i wanted to gather the entities that were close to a point, I just retrieved the spatial map values and collected all entities with some distance away from the point.

#

For some low entity count, I'd probably just do a loop and gather the entities because I'm lazy ¯_(ツ)_/¯

rare umbra
#

Yeah eventually I might have a loading ring which will solve this issue. Ensuring only things that are within 100m or so are loaded

#

So looping through is fine but when you’ve reached the end and you’re confident of which is the closest at this point you can’t update the entity, right?

hollow sorrel
#

depends on what update means in this context

#

change some values? sure you can do that

rare umbra
#

Yeah that’s what I meant

#

I guess I need to cache the entity?

hollow sorrel
#

you're using entities.foreach right?

#

= you're modifying the component itself, don't need to cache entity or anything

rare umbra
#

Right right. It’s been a while since I’ve dug into this. Thanks!

tardy spoke
#

Can you use SetComponent out of the blue like that or does that need to be in a command buffer or something? Getting an argument exception "the entity does not exist" that seems to possibly be indicating that method has something to do with it

coarse turtle
#

what's the closestMarbleEntity? And how is it retrieved?

rare umbra
#

Hrmm I’m looking to keep a list of entities as I’m iterating through ForEach in a system. I’m trying a List<T> but it doesn’t seem to like it. I guess because it’s not job safe?

Any idea how I can track a list / array of unknown length when creating the array / list?

coarse turtle
#

Yeah List<T> won't work, you can try NativeList<T>, except T will be a struct w/ blittable fields or blittable type (like int/float/Unity's math lib etc)

rare umbra
#

I tried NativeList<int> but don’t seem to find a way to dynamically add an element to the array. Maybe I’m being super noob lol

coarse turtle
#

hmm what do you mean to dynamically add an element to the array?

rare umbra
#

So with a list I’d do list.Add(integerValue)

coarse turtle
#

Ah so NativeList<int>().Add(intValue) isn't adding the element for you?

rare umbra
#

Intellisense isn’t showing Add as a valid method

coarse turtle
#

oh, I think you might need to regenerate the csproj files (under Preferences -> External Tools, or just try closing your IDE and reopening it again - sometimes that works too)

#

yeah sometimes intellisense doesn't really want to work

rare umbra
#

grumbles

#

Thank you! I’ll try that! I thought I was going a bit crazy there

coarse turtle
#

Yeah no worries, happens to me too 🙂

rare umbra
#

Ok so that worked for intellisense but it’s throwing exceptions ‘invalid operation exception’ entityList has not been assigned or constructed :/

coarse turtle
#

how's entityList created?

rare umbra
#

Ok got it, I used Allocator.TempJob which fixes it

#

I think it turns out that I don’t know how to use these aside from the basic constructor new NativeList<int>()

violet cosmos
#

@coarse turtle How do you look at that color all day?!

#

😆

#

Or do you have tritanopia?

coarse turtle
#

So the other constructors pretty much let you set an initial capacity and let you set the Allocator type

  • Temp <- lasts for the frame (believe it gets deallocated at the end of the frame, but you can always call Dispose or use the using (var blah = new NativeList<int>(1, Allocator.Temp) { } syntax)
  • TempJob (used for the Jobs system so you can pass data in between jobs)
  • Persistent (lasts until you manually deallocate it)
  • the capacity just lets you have a set # of elements before it resizes when you exceed the initial amount you set (so calling new NativeList<int>(Allocator.Temp) will set the capacity initially to 1, so if you add 2 elements, it will resize the list to 2 the second time you add)
#

Or do you have tritanopia?
@violet cosmos Lol I don't think I do - but I make my screen really red at night 🙂

deft stump
#

I believe Temp and TempJob doesn't get automagically deallocated.
you have to manually deallocate them according to my exp

coarse turtle
#

Yeah I couldn't remember for Temp, thought it was like stackalloc at one point

hollow sorrel
#

Temp does get automagically deallocated at the end of the frame, disposing it yourself is a no-op

#

and TempJob is a fuckin trap
it lasts for 4 frames then gets automagically deallocated like Temp, which imo makes it useless for most things because it relies on render frames
so if your job is intended to update 0.1 seconds from now you'll get an error if the user's framerate is high enough to render 4 frames in the meantime

i suppose it works if you intend to only use it for current + next frame, but even then blegh

coarse turtle
#

Good to know for Temp, thnx Scorr 👍

hollow sorrel
violet cosmos
#

That moment when you're looking at a $65 asset and wondering if you can skim by with the free version...

And realize you already own it because you bought it on some deep discount sale or for a client project you forgot about already 😆

deft stump
#

congrats benjamin

trail burrow
#

Nice @violet cosmos

blissful gorge
#

hey y'all, I was reading through the burst documentation and came across that FunctionPointers don't work with generic delegates.

Since FunctionPointers themselves are generic, I tried to get around this limitation by specifying the generic delegate parameter in my job like this

public struct WhereJob<TPredicate> : IJob
{
  public NativeArray<int> Input;
  public FunctionPointer<TPredicate> Predicate;
  public NativeList<int> Output;

  public void Execute()
  {
    for (var i = 0; i < Input.Length; i++)
      // Here is *where* I'm running into trouble (pun intended)
      if (Predicate.Invoke(Input[i]))
        Output.AddNoResize(Input[i]);
  }
}

I'm getting a compile err on the Invoke, and wanted to know if there was some magic I could do to get this to work.

As an alternative, I've been making interfaces and passing those instead to pass in generic functions.

public interface IFunc<T, U> 
  where T : struct
  where U : struct
{
  U Invoke(T arg0);
}

public struct WhereJob<TPredicate> : IJob
  where TPredicate : struct, IFunc<int, bool>
{
  public NativeArray<int> Input;
  public TPredicate Predicate;
  public NativeList<int> Output;

  public void Execute()
  {
    for (var i = 0; i < Input.Length; i++)
      if (Predicate.Invoke(Input[i]))
        Output.AddNoResize(Input[i]);
  }
}
blissful gorge
#

turns out passing in interface'd structs is a pretty common workaround.

deft stump
#

question: what's the math library equivalent of vector3.moveto()?

blissful gorge
#

I thought the math vector3 stuff wasn't related to transforms? It was meant as simd vectors for hardware optimization

#

Edit im wrong lol

amber flicker
#

there isn't an extension method if that's what you mean? Fairly easy to do it manually though.

dusky wind
#

@blissful gorge it makes it easier for transform calculations to be vectorized

deft stump
#

@amber flicker yeah I did it manually

dusky wind
#

Does anyone know the best practices for fine grained physics based character controllers in ECS?

#

As in the character controller has a lot of exceptional behavior and physics queries

#

Which absolutely break any form of vectorization

amber flicker
#

I'd be slightly surprised if anyone here had attempted it let alone best practices 😬 - you're probably the expert here

dusky wind
#

Haha, leading the charge I guess

amber flicker
#

well.. fholm and others might have done more I suppose 👍

#

You're worried about vectorization? Some serious optimization huh

dusky wind
#

Just wondering how to reduce CPU load where I caj

#

Tangentially related, a huge number of the system queries I have target the same entities but different components on them

#

Is it better to have a general "Give me all of the players query"? And use ComponentDataFromEntity

#

Or just keep using Entities.ForEach?

#

The access patterns would likely be the same

amber flicker
#

Well, firstly, I'd use IJobChunk rather than many CDFEs

#

you'd definitely lose some of the gains by introducing the branching

#

but the branch is at the chunk level with an IJobChunk which is sweet

dusky wind
#

Oh CDFE's has branched checks?

amber flicker
#

well.. no.. maybe I worded that poorly

#

with an IJobChunk you can say if(chunk.HasComponent<Bob>){ ... iterate chunk and do stuff.. } - then most ICD accesses you do there will be in cache - like your foreaches

#

whereas CDFEs are all random access afaik

dusky wind
#

Ah, but if I make strong assumptions that specific components are there

#

And skip Has component entirely

#

That should void the problem, no?

#

Not saying it's the best idea for this

#

But I'm noticing that the overhead of many jobs with the same query targetting the same Entities

#

Particularly as I add a bunch of systems with fairly heavy jobs

amber flicker
#

so... supposedly jobs/systems are due some major optimization. So unless you need to ship right now I'd be very tempted to wait and see how that pans out before doing major refactoring.

#

That said, if you have 20 lambdas that all iterate (ICD A, ICD B, ICD C) for example, then yea, it will be quicker to iterate just once and do everything at the same time obviously.

dusky wind
#

Jobs I am OK with, the overhead of scheduling is within my tolerances

#

But ECS's queries are definitely very harsh, even when run off main thread

trail burrow
#

IJobChunk is by far the most efficient way

amber flicker
#

Most likely those 20 lambdas will have subtly different required components I guess - which you can do either by checking exists on a chunk or by using CDFE

trail burrow
#

it allows you to deal with the compnents

#

without any copying at all

#

or going through any accessor properties/methods/etc.

#

you can deal with the raw pointer to the chunk

#

for each component type

#

there's also fast ways to filter out entire chunks if they don't match for some reason

dusky wind
#

That is a good point

trail burrow
#

IJobChunk > * when it comes to performance, it's more boilerplate for sure

dusky wind
#

I keep forgetting CDFE is a copy

trail burrow
#

but there's no competition when it comes to perf

dusky wind
#

Is that not what Entities.ForEach compiles down into

trail burrow
#

yeah but you have method invocation for each, outer loop, filtering is slower, etc.

#

there's overhead on the Entities.ForEach thing

#

if that overhead matters or not... depends on what ur doing

dusky wind
#

Interesting

#

I thought they'd unwrap it into the body of the IJobChunk

trail burrow
#

afaik no

amber flicker
#

I think most instances you'd have trouble profiling the difference?

dusky wind
#

It seems like it since the Burst output seems to create one inlined function without function calls

trail burrow
#

burst does its thing on top ofc

dusky wind
#

But I could be reading the ASM wrong

trail burrow
#

it could've changed also, i havent looked at the ForEach system since it was first released

#

but despite that, there's still benefits to IJobChunk, specifically around filtering whole chunks out, etc.

dusky wind
#

Hmmm

trail burrow
#

FWIW whenever I do ECS stuff (rarely, but it happens) i almost exclusively use IJobChunk, i never use entities-foreach thing

#

IJobCunk or just the raw IJob is what I use

dusky wind
#

I might switch to it if it's critical

trail burrow
#

also scheduling less jobs is much more efficient

dusky wind
#

Another question, is there a way to disable simulation but not rendering?

trail burrow
#

the inter-job overhead is not none

amber flicker
#

I use mostly the lambdas - I haven't been able to profile a difference for something simple. I do use an IJobChunk the hot path though. If you're processing a lot of chunks in particular, it's definitely better.

dusky wind
#

@trail burrow unfortunately I have some stuff that I can't avoid chunking up into multiple jobs

#

Namely some stuff that needs to run on the main thread in between

trail burrow
#

i always had issues with the job threads not executing in optimal fashion and causing stalls

#

like they'd just randomly screw up the job-ordering

#

example:

  1. I have a X thread cpu
  2. Job is split into X pieces
  3. One of the worker threads does nothing and causing one of the threads having to pickup 2 pieces instead of just 1
#

causing the entire pipeline to stall

#

i was fiddling on a determinstic 2d physics engine for ecs/dots, but could'nt get it to execute optimally so just ditched it

amber flicker
#

I've found that has improved over time but obviously < jobs is better I agree

trail burrow
#

idk if it was an issue because my stupid high core count cpu (32) or issues in the job system

dusky wind
#

I'm curious at what threshold does job complexity overtake that overhead

#

Like I could squash a bunch of these systems and jobs into one giant one

#

That operate on the same data

#

But the query and number of components read is huge

trail burrow
#

scheduling overhead seems to be about 0.03ms

#

on my machine

deft stump
#

mine takes a fat 0.08ms lol

trail burrow
#

and that bvecomes a significanat slice when scheduling a lot of jobs

#

so we ended up doing our own task system inside of the job system

#

which runs on one IJob as each 'worker thread'

amber flicker
#

My lib has quite a lot of different systems but it does quite a good job filling the threads from what I can tell

vagrant surge
#

from my experiments, each component you have in your for-each query costs 0.01 of overhead

trail burrow
#

@amber flicker that gap is nasty

#

the one that goes straight down

#

like what the fuck is that, almost 0.1ms of

#

"nothing"

amber flicker
#

haha well.. I didn't say it or I was perfect - it's sync points I have where it's waiting to complete

trail burrow
#

how is that a sync point?

vagrant surge
#

does unity ecs overlap 2 parallel fors together?

trail burrow
#

this is like 100% unacceptable

amber flicker
#

caveat this is in editor

vagrant surge
#

parallel fors allways have a sync point where threads sync at the end

trail burrow
#

@amber flicker it has the same issue in build

#

FWIW the between-task wait for our system is so small i cant measure it

#

0.1 ms is HUGE

#

it's < 0.0005 ms

amber flicker
#

I don't have confidence that this isn't my fault for a start 🙂

trail burrow
#

its not ur fault

#

i had same issue with job system

vagrant surge
#

@trail burrow does the job system overlap 2 parallelfors together? Asuming its System A and then SystemB, not system A and B running at the same time

trail burrow
#

you mean if they can run at the same time?

#

if there's no dependancy between them then yes afaik, but idk how the Entities.Foreach and the auto-dependancy shit works with that

#

but if you're doing it by hand using IJobParallelFor, and schedul them w/o dependancy on each other yes it can do that

amber flicker
#

I'm hoping this is part of their system & job optimization work

trail burrow
#

that scale is on 1/1000 of MS

amber flicker
#

if you're saying there's plenty of room for them to do better... cool... good news as far as I'm concerned.

trail burrow
#

tbh ours is purpose built

#

it's completely without sync points

#

between the threads

#

completely lockless/semaphore-free

amber flicker
#

I mean.. I don't know where my expectations should be. On an intuitive level, it feels like splitting out work to 24 cores and all associated work is going to take some time.

#

and we're talking about in context of what other parts of the Timeline look like 🤣

trail burrow
#

even when we have one thread waiting on another thread

#

the overhead to notify of the compleition is < 0.0007ms

#

and this is in editor, with all libraries in debug mode

#

i wasn't expecting the unity job system to do this well because it is more generic ofc, but when i get random stalls of ... like 0.1-0.5ms

#

it's just... what?

amber flicker
#

Fair enough. From my pov it's still 100x improvement on what was there before and it's not finished yet.

trail burrow
#

this is from my scrapped dots networking library

#

what the hell are those gaps

amber flicker
#

Is it partly an issue of jobs being done before the next job is executed on the main thread (i.e. main thread stuff happening between executions)?

trail burrow
#

no

#

this just the job system... fucking something up

#

i dont know what it is, it's written in C++

#

I was never able to get it to run like i wanted

#

so gave up on all of my dots projects, both the netcode and the physics engine

#

and obv from ur screenshot, the issues are still there

amber flicker
#

I see that as a given that it'll improve over time and I'll get additional perf "for free" where as you know it works at a low level and find it abhorrent it's so bad I guess?

trail burrow
#

i have no idea how it works, i have never seen code behind it

#

but i know it can be done faster than whatever they are doing

amber flicker
#

From what they've said, priority was getting things working. They are starting to shift to optimisation on some parts of it now. I'm ok with that.

median mesa
#

Anyone else have an issue with the Unity Physics Package? I get this error as soon as I add it to my project.

#

0.4.1

solid flume
#

I need help scheduling dependent jobs

#

Right now, I'm doing ```cs
JobHandle dep = new JobHandle();
dep = Entites.ForEach(...).Schedule(dep);
dep = BurstedParallelForEach.Schedule(num, num, dep);
dep = Entities.ForEach(..).Schedule(dep);
//Dispose of collections used by first Entities.ForEach and ParallelForEach passing dep as parameter
dep.Complete();

#

However, when I run it throws an error at the bursted job

#

Saying I must complete the previous job before reading from the native collection

dark cypress
#

Job.OnUpdate runs on the main thread. So you schedule the jobs and then try to dispose of the collections immediately before the jobs even run.

stiff skiff
#

Has job scheduling in the editor gotten worse since 2020.1?

#

Comparing it with 2019.3, it seems to be slower

solid flume
#

Job.OnUpdate runs on the main thread. So you schedule the jobs and then try to dispose of the collections immediately before the jobs even run.
@dark cypress But I've passed that job as a dependency. Does that not make a difference?

dark cypress
#

Either run the jobs on the main thread, or have the collections be static somewhere(a field in the job?)

stiff skiff
#

or well, has more gaps between jobs, and bigger gaps

solid flume
#

Like, coll.Dispose(dep)

dark cypress
#

Hold on, I'm probably mistaken then.

amber flicker
#

@solid flume assuming you're coding inside a SystemBase you need to be setting the base class's Dependency property. Delete JobHandle dep = new JobHandle(); and replace all deps with Dependency.

#

at least that's my guess

solid flume
#

I'll try it

amber flicker
#

I mean instead of that you can just add the line Dependency = dep; but you get the idea.

solid flume
#

Nope, same error

#

Should I just do .Run and .Complete on everything?

amber flicker
#

what is BurstedParallelForEach?

deft stump
#

on my machine, the hybrid renderer system takes... 0.55ms

amber flicker
#

that's.. nice? or you mean without rendering anything?

solid flume
#
[BurstCompile]
public struct ColliderCastJob : IJobParallelFor
{
    [ReadOnly]
    public CollisionWorld World;
    [ReadOnly]
    public NativeList<Entity> Entities;
    [ReadOnly]
    public NativeList<ColliderCastInput> Inputs;
    [NativeDisableParallelForRestriction]
    public NativeMultiHashMap<Entity, Entity> Results;


    public void Execute(int index)
    {
        NativeList<ColliderCastHit> hits = new NativeList<ColliderCastHit>(Allocator.Temp);
        World.CastCollider(Inputs[index], ref hits);
        for (int i = 0; i < hits.Length; i++) Results.Add(Entities[index], hits[i].Entity);

        hits.Dispose();
    }
}
#

Should I just do .Run and .Complete on everything?
this seems to work

#

And is performant

amber flicker
#

@solid flume it's a bit hard to debug bit by bit. The error says there's jobs scheduled in MovementSystem - is JobHandle dep = new JobHandle(); dep = Entites.ForEach(...).Schedule(dep); dep = BurstedParallelForEach.Schedule(num, num, dep); dep = Entities.ForEach(..).Schedule(dep); //Dispose of collections used by first Entities.ForEach and ParallelForEach passing dep as parameter dep.Complete(); everything that's happening in your MovementSystem?

solid flume
#

Considering 10ms is being taken up by hybrid renderer

#

@amber flicker yes

#

Any reason why a culling job can take 20ms?

#

Over 2 instances

amber flicker
#

oh.. I think it might be you need to complete the dependency between jobs 2 & 3 - I think it's saying your last foreach can't safely read from the nativelist until the second job has finished.

solid flume
#

Ah

#

Weird, but okay

#

Any reason why a culling job can take 20ms?
Any guesses?

amber flicker
#

for 2 meshes? It shouldn't be. What does the timeline view of the profiler look like?

solid flume
#

Not 2 meshes, around 10k

#

Although one collider

#

I could merge it into one mesh but my navigation kind of relies on each tile being it's own mesh

amber flicker
#

That sounds too high - but performance with a large number of dynamic objects is generally really bad still with the hybrid renderer

solid flume
#

Oh, also I guess the reason it's doing nothing is because they need to have colliders for my system

solid flume
#

Any reason why a culling job can take 20ms?
Just turned on burst and now it's a nonissue

deft stump
#

that's.. nice? or you mean without rendering anything?
@amber flicker I mean it in a bad way... is the hybrid render system that exxpensive?

amber flicker
#

to do what?

fallow mason
#

entities package not showing up in package manager in 2020.2.0a21.2837?

fallow mason
#

heh thanks

#

been a few months since I've played with DOTS

amber flicker
#

yea that grimace was aimed at Unity rather than you 😅

violet cosmos
#

I updated that page to include all the hidden packages. Don't know why I didn't think about that sooner, I've visited that forum post maybe a dozen times to see wtf

#

Someone added a script last week that brings those packages back into the Package Manager 😆

#

and disables the preview package warning haha

tardy spoke
#

Haha magnificent

deft stump
#

has anyone mixed gui with ecs?

#

I'm trying to have a text follow an entity on screen.

tardy spoke
#

Hmm, I'm trying to do something fairly trivial, but it's with the hybrid workflow so i'm not quite sure how to do it.

Basically, if I put some code to spawn additional marbles during runtime in the mono-behaviour that is converting them, to access it's "create" function, I don't seem to have access to GetEntityQuery. Is there an alternative for that context?

If I move it out to a SystemBase I have to reach in awkwardly to that class to grab that method.

#

ECS could use some method renaming... lol

I noticed a few oddities, like it's setComponentData on a command buffer and SetComponent on an entity manager, things like that.

deft stump
#

welll they're basically trying to make ecb a bootleg em

#

but agreed

tardy spoke
#

Yeah - people keep saying entity manager can be as fast or faster but I'm not sure what context they're talking about. if you use EM you can't run burst or parallel, right?

deft stump
#

well EM has batch operations

coarse turtle
#

might shed some light on whatever topic you're interested in

deft stump
#

^^ there, that was what I was saying

#

but yeah... EM can be fast, but ecb benefits from being routed in burst

tardy spoke
#

Interesting, read the article. I like it because ECBs often give me weird errors even though everything still works, hahah

solid flume
#

Traditionally I have fields on components attached to gameobjects that I can manipulate to tune things. Do those values now need to be hardcoded?

amber flicker
#

if you use the subscene workflow you can do the same with an open subscene

solid flume
#

Never heard of that before

amber flicker
#

a subscene?

solid flume
#

Yea

amber flicker
#

cool - yea, worth googling around - maybe check out a codemonkey tutorial on them

#

if you can be working with them, you probably should be

#

but lots of people have various issues so..

tardy spoke
#

@solid flume are you talking about a component with a [generateAuthoringComponent] flag on it?

#

Might want to look that up as well, then the "fields" will show up in the inspector for the component

solid flume
#

Not really. I have a tolerance for approaching a waypoint for example, or a spherecast radius

tardy spoke
#

if your workflow is "hybrid" or whatever

#

ah, hmm

#

well you could load that from a piece of data on a component?

solid flume
#

It's hybrid in the sense that I generate a cubical tile based map in the editor before running the scene

#

Makes sense, I can try that

#

certainly makes it easier to fiddle with settings

tardy spoke
#

Yeah and if that component has generateAuthoringCompoennt you could adjust it in editor

#

before running

#

^ tutorial that shows it

solid flume
#

Awesome, thanks

#

I'm happy to say I finally have a ball moving around randomly

#

Do layermasks work the same in ecs?

#

As in they're still bitmasks corresponding to whatever I set in the editor

dusky wind
#

@solid flume yes but they aren't closely tied to the editor layers at all

#

And for the purposes of collision there are also groups

solid flume
#

Okay. I'll check those out

#

Can I check for components in jobs?

#

And can I iterate over the values corresponding to a key in a multihashmap without a foreach loop?

dusky wind
#

Generally include that in your EntityQuery

#

It checks at the chunk level instead of the entity level

solid flume
#

Basically I want to get all the colliders in a spherecast, then put them into different multihashmaps based on if they have a particular component(s) or not

dusky wind
#

In that case use HasComponent

#

There is a SystemBase function for it

#

Or if you want to manually do it in a job

solid flume
#

Yeah, that

dusky wind
#

Use ComponentDataFromEntity

solid flume
#

Ah, okay

dusky wind
#

Which also has the same function

solid flume
#

Is it better to do it in a job or an Entities.ForEach

#

I can only burst the entities.ForEach if I figure out how to iterate over a multihashmap without using a foreach loop

dusky wind
#

I am told that IJobChunk has less overhead

#

Due to missing a function call on each entity

#

But if you are using Burst it gets inlined anyway

solid flume
#

So I'll do it in the parallel for job that does the collider casts

dusky wind
#

My design has been collider casts -> component checks -> NMHM in parallel

solid flume
#

Also, I how do different entities interact? Before if I needed to say damage a player, I'd just TryGetComponent or something and call the damage function

dusky wind
#

The read the NMHM based on the keys

#

Into parallel jobs on each key

solid flume
#

And then the player would check on being damaged if it's dead or not

#

What's NMHM?

dusky wind
#

NativeMultiHashMap

solid flume
#

I can replace an entities.foreach with a parallel bursted job?

#

Suppose I iterate over the nmhm in an IJobParallelFor, then how do I get the values corresponding to each key?

#

nmhm.GetValuesForKey returns an Enumerator, which is used in a foreach right?

#

Can I make an Entities.ForEach run in parallel, and force it to complete? Kind of like doing IJobParallelFor.Schedule(...).Complete()

#

Turns out converting 10k gameobjects to entities takes an abysmally long time

amber flicker
#

convert 1, then use EntityManager.Instantiate(convertedPrefabEntity) - especially the one that takes a NativeArray

solid flume
#

I'll have to shift my map generation to the job system, but probably worth it

#

Oh wait I can make entities inside monobehaviours right?

amber flicker
#

you can, yes

solid flume
#

What's the difference between SystemBase and ComponentSystem and all the other types?

coarse turtle
#

So SystemBase (can schedule jobs with the Dependency field or run things on the main thread) was the latest version of ComponentSystem (originally for main threaded tasks and using managed objects, still used for GameObjectConversionSystems) and JobComponentSystem (mainly used for scheduling jobs and multithreaded work). Generally going forward best to use SystemBase.

solid flume
#

Ah

#

Okay

#

Can I create entities in the editor? Like outside of runtime?

#

Preload it

coarse turtle
#

I think that's what subscenes are used for - you already have these converted gameobjects as entities ready to load

#

but they're not preloaded - you need the world and such constructed for the entities to load into

solid flume
#

So I can make a subscene, and it'll already be converted to entities, then I just load it in with minimal overhead?

coarse turtle
#

yea pretty much

tardy spoke
#

That's the theory, anyway, haha

solid flume
#

Can I have a monobehaviour populate a scene in the editor somehow?

#

It looks basically like a normal GameObject

tardy spoke
#

From my experience even though they seem like GO's they don't seem to execute monobehaviours and things on them the same way

solid flume
#

I'm thinking I'll just add gameobjects in the editor by making that as the parent and see how it goes

#

Nope, doesn't work

#

I'll figure it out eventually

dusky wind
#

So I'm using Entities to control GameObjects

#

Is there a recommended way to control pooled GOs from ECS?

stiff skiff
#

A question, has anyone here used standalone playmode tests with ECS?

#

Nvm, seems my issue is fixed in Burst 1.3.3, why isn't used in ECS yet D:

rare umbra
#

Anyone know of any examples of how to handle input with ECS? More specifically how to determine which system should pick up an input depending on game flow context?

E.g. in a menu a [x] button press means something else to if you’re standing in front of an NPC

#

I guess my question is more about how to handle input / game flow

zinc plinth
#

1s

rare umbra
#

Since the ECS model is very distributed I’m having a hard time getting my head around it

zinc plinth
#

new input system

rare umbra
#

Thanks! I’m not sure I see how this handles the different contexts though

zinc plinth
#

?

spark glade
#

Just updated to 2020.1.3f1 (from 2019.3) and updated all dots related packages. Now all my converted prefabs are rotated for no apparent reason ...

#

Does that ring a bell with anyone?

#

(entities 0.14.0-preview.18, hybrid (v1) 0.8.0.preview-18, urp 8.2.0)

#

appears to happen during entity conversion, bc in an Open subscene the rotation is correct, and as soon as i close the subscene and the conversion happens this incorrect rotation is applied

spark glade
#

Sidenote: That's a SkinnedMesh (without any sort of animation whatsoever)

spark glade
#

Changed SkinnedMeshRendererConversion to take the RootBone into account. The render entities are now parented to the RootBone entity instead of the SkinnedMeshRenderer GameObject entity. As a result the RenderBounds will update correctly when the root bone is transformed.

#

sigh

#

It definitely is related to that. Setting the Root Bone to null in the inspector, does fix the issue. But that for sure will cause problems when once the animation package is released in the year ≈2029.

#

If I want to have the RootBone not set to null, it seems like it really wants no rotation/translation whatsoever on the rootbone, so I have to shift the base rotation down to the pelvis bone 😢

#

No idea if the "old' behavior is normal or if the new hybrid renderer (or whatever is responsible for this) is just very strict and my models are "wrong" 🤔

#

If anyone manages to get to the bottom of this, I'm very eager to hear about it 🙂

amber flicker
#

@rare umbra you're right, it's not super straight-forward. At the moment you need to do more than you would with monobehaviours. I'd also be interested in what people are trying and what scales well. For simple cases (menu separation from game) there are lots of ways. One approach is to create a singleton entity with a buffer of inputs this frame and another with an enum that has a focused value (menu or game). For the more complex case (like UI input propagation stuff) I think most people atm would opt for the existing tools and wait for Unity to rewrite - it strikes me as a tonne of work. Any people who have done more with Input got any thoughts?

solid flume
#

Unity has never crashed as much as when I'm working with DOTS

#

For some reason, when I have 3 or more of one type of entity, unity just refuses to work

#

Application.UpdateScene goes on endlessly

#

Also, does Entities.ForEach have to be a lambda? Can't I extract it to a local function?

opaque ledge
#

you can make a static function and call that inside your lambda

solid flume
#

I thought burst doesn't like static?

opaque ledge
#

make sure there is no divide by 0 or endless loop @solid flume disable burst temporarily to see if there is any error in console

#

opposite, burst likes static

solid flume
#

Turns out it was my parallelFor writing to the multi hashmap causing issues

#

I just preallocated some memory and used a parallelWriter

#

Is there any sort of pathfinding for ECS?

opaque ledge
#

afaik, A* Pathfinding project pro has a beta for ECS/DOTS pathfinding

solid flume
#

I found a codemonkey video

#

So. Much. Work.

trail burrow
#

need to do it by hand mostly

solid flume
#

Can I assume my system's onCreate will be called after all my gameobjects are converted to entities?

deft stump
#

3K memory leaks GWovoRaphiXD

zinc plinth
deft stump
zinc plinth
#

also when you create a new world(how do you even do that ?), by default it won't have any system right ?

#

since the DisableRendering tag doesn't work since stuff still gets culled by hdrp, I have to delete the entities currently. Tho I would like to be able to get them back in case I need to recreate merged meshes at a later point. So I want to save my renderer entities for each grid tile into a separate world

zinc plinth
#

ho you just have to use the World constructor, neat

mint iron
#

yah! its pretty awesome for writing tests

zinc plinth
blissful gorge
#

is Entities.ForEach burst compatible since it uses a delegate?

#

I see it has a try .. finally block

rancid geode
#

Entities.ForEach generates code for you, it doesn't actually use a delegate

solid flume
#

I need a min heap of sorts for my a* algorithm, but it should compare the value of a struct parameter whose indices in a nativeArray I've given

#

Any idea if and how that's possible

#

There are native min heaps out there, but can't feed them a custom comparator

#

I miss c++

blissful gorge
#

oh damn @rancid geode , I'm looking to do a similar thing with some LINQ-like methods. Have any recommendations on where to start?

rancid geode
#

you can see how Unity does that on Entities package (I think), haven't touch much on code generation lately, so I will not be help much there

solid flume
#

What's the difference between NativeList<T>.RemoveAt and .RemoveAtSwapBack

worldly pulsar
#

RemoveAt keeps the order in the list

#

SwapBack moves the last element in that place

solid flume
#

I'm guessing SwapBack is faster

worldly pulsar
#

You're guessing correctly

#

(btw, the docs explain the difference, so I'm not sure why you're asking here)

solid flume
#

Why are the docs split up

coarse turtle
#

they started doing docs per package

#

probably just easier for each team to get them out instead of changing the main docs page and adding links 🤔

worldly pulsar
#

Afaik the goal was to detach the package version from Unity version

#

The result is hard to google chaos 🤷‍♂️

lusty otter
#

Hmm, I don't have issue of finding the doc with Google even if what I'm looking for is in another package

safe lintel
#

I hate the docs format for packages

lusty otter
#

Though I would say the search on doc site really sucks.

worldly pulsar
#

"Unity NativeList" gives me the doc page as first result... package version 0.0

lusty otter
#

Oh right that 😂

#

That's more of an issue with their site and SEO though.

spark glade
#

Seems to be a "common problem" with skinned meshes in Dots.

dusky wind
#

@safe lintel honestly the main docs don't even document extension methods and have trouble showing the generic typing and constraints of functions and types

#

It seems like they are using a themed DocFX for their stuff

#

Which is fine, but it really makes searching cross packages hard unless you have sharpened your Google fu

amber flicker
safe lintel
#

it kinda reminds me of browsing unreal's api docs, just a wasteland of autogen stuff without explanations, but in unity's its forced to this narrow format that doesnt span the width of the page.

prisma anchor
#

Netcode question. How do I reference two different actors to spawn if they are the same type:

                var ghostCollection = GetSingleton<GhostPrefabCollectionComponent>();
                var ghostID = GameGhostSerializerCollection.FindGhostType<PlayerSnapshotData>();
                var prefab = EntityManager.GetBuffer<GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostID].Value;
                var player = EntityManager.Instantiate(prefab);````
spark glade
#

Did anything change in 2020.1 around IL2CPP options? I can't build for Android anymore due to:

System.InvalidOperationException: Sequence contains no matching element
...
...
...
il2cpp.Il2CppOptionParser.ParseArguments
#

I already tried toggling random IL2CPP related settings to see if anything changes in the Project Settings or the build configuration.

blissful gorge
#

dug through the entities code and found out where the lambda jobs are being generated. UnityEntities.CodeGen/LambdaJobs folder. Unity is using Mono.Cecil to generate the jobs for the lambda function.

#

in case you were curious like me how the heck they had delegates compiling with burst

zinc plinth
#

Entities.ForEach is full codegen ye

stone osprey
#

So i want to implement "drops" into my game using the ecs... Each entity should be able to drop stuff for various actions, like killing, gathering, harvesting. But im not sure how to structure this properly... One Drop-Component getting used for all three topics ? One Component for each, storing the possible drops ? And what if we wanna have some sort of validation for the drop weights ? For example if a player kills a mob, we use the standard drop set... but if that mob gets slain with a special weapon, it always drops a special item/more of a item/no item ? :/ So many questions... i cant find any good sources about that... would be really glad for any help on this topic

zinc plinth
#

you can have a shared component containing your loot table, and you can add some other components(non shared) on each of your mob entities if you want modifiers like luck or some unique drop

stone osprey
#

@zinc plinth Thanks ! So it basically works like this : Player kills mob, mob gets notification via event, component e.g., That modifies the weights, Weight calculation and drops, Mob removed ? Or could it also be smart to handle the loot table as a seperate entity each time we require it ? This way we could spawn it in, attach modifiers what ever and once the systems processed it its gonna drop the loot -> Destroys the loot entity

zinc plinth
#

when mob dies, tag mob for loot processing with metadata like weapon/magic/player used to kill it (for your modifiers)

when the loot system comes (before the system that deletes the mob entity), get the loot table and the modifiers from the mob entity, do your mix, add items to whereever they need to go

zinc plinth
#

why did I throw myself in such a rabbithole with combined meshes Cry

solid flume
#

Well I implemented a* in my project

#

The only issue is it doesn't actually work

tardy spoke
#

Does burst ONLY work with jobs? In non-ECS land, can't use it on a function or anything unless it's in "job" form?

safe lintel
#

You can use it non jobs but it can't be used with managed objects

tardy spoke
#

@amber flicker yeah that's cool, but some additional complexity upon complexity. I've been happy in OOP land lately, just reading software architecture books to try to avoid spaghettification, haha.

#

@safe lintel that's what I thought, but when people talk about it on the forums and stuff they basically say it HAS to be used with jobs, which seemed weird to me

safe lintel
#

Link? Assuming they're misinformed

tardy spoke
minor sapphire
#

Burst has developed a lot since 2018

tardy spoke
#

So, can you burst a struct that isn't an : Ijob ? As in any struct not using any reference types?

minor sapphire
#

It did used to be the case

tardy spoke
#

Right, that makes sense

minor sapphire
#

But now you can use it for more

#

You can burst static utility methods in classes too

tardy spoke
#

From the Unity.Mathematics library or are there others as well

minor sapphire
#

I'm a bit out of the loop myself, haven't used it for some time but yeah, it's developed passed jobs

#

I'm not sure exactly where the boundaries are today

#

Have you checked the burst manual?

mint iron
#

you can use burst on static methods, they do this within ECS for some of the EntityManager methods.

tardy spoke
#

Good, good

#

Thats what I thought, was just checking

solid flume
#

What's the difference between calling .Run() on a job and .Schedule().Complete()

safe lintel
#

you mainthread code with .run()

#

you are scheduling a single job(on a thread) via schedule and forcing it to complete immediately with .schedule().complete()

trail burrow
#

.Run() = makes it run on main thread

solid flume
#

Hmmm

trail burrow
#

.Schedule().Complete() = waiting on background thread(s) to finish it

solid flume
#

I'm getting an index out of range on a dynamic buffer

#

Soon as I press play

#

The stacktrace tells me nothing

#

Is there any way I can find out where?

#

All I know is that the GameObjectConversionUtility is coming up a lot in the stacktrace

rancid geode
#

You can burst static utility methods in classes too
@minor sapphire hmm, but even so, it will only actually be bursted when called from inside a Job, or am I wrong here?

AFAIK Burst only work with Jobs, you can Burst compile individual functions but their burst compiled version will only be used when called from inside a job

#

you can use jobs in main-thread, however (with theJob.Run())

solid flume
#

I've put a debug log in every system that uses the dynamic buffer and nothing pops up

#

Can I not have authoring components for dynamic buffers?

rancid geode
#

but I never cared enough to test that to see if my assumption was correct

solid flume
#

Will an Entities.ForEach not work if the entities are in another subscene?

#

I have an entities.ForEach in an OnCreate that doesn't ever get called

rancid geode
#

OnCreate is called when the system is being created, unless the system is being created manually it will be created before any scene (or subscene) gets loaded

solid flume
#

So how can I initialise a native array?

minor sluice
#

isn't it just
new NativeArray<T>(yourArguments);

#

either with predefined size and a given allocator or you can pass an IEnumerable of a struct type..?

solid flume
#

I'm basically trying to iterate over all entities with either a land or water component, and hence get the layout of my map in a flattened array

#

The map is premade in a subscene

#

So it doesn't take a bazillion years

#

I could add a sort of check in on update, see if it's uninitialised and try to initialise it

minor sluice
#

would a filter job or a EntitiyQuery WithAny be too slow?

solid flume
#

I dunno, I'm bad at ECS

#

What's a filter job

#

Also, I can iterate over an entity query?

minor sluice
#

maybe you can also write an entityquery with how you need it and reuse the results of it? (if the environment doesn't change)

solid flume
#

It doesn't

minor sluice
#

you can get the results on an enttiy query, either all entities or specific components and iterate over them yeah

solid flume
#

That's why I want to just process it once

#

It might not work though

#

The map is flattened into the array by position, so I can look up particular positions

minor sluice
#
var entities = enemySpawnSourceQuery.ToEntityArray(Allocator.TempJob);
var spawnSources = enemySpawnSourceQuery.ToComponentDataArray<EnemySpawnSource>(Allocator.TempJob);
#

to entity array to get all entities and to Component data array if you want to get a native array of a specific component set, but I think that will run on the main thread then to get you the results,
also the issue I think is that this is readonly, you can't just write back to the native arrays and expect the component on the entity to change,
but you can - with the information of the entity in the entity array, use EntityManager.SetComponent(Data) afaik

solid flume
#

But when do I run this. I need it to happen after the subscene is loaded

#

There some sort of callback?

minor sluice
#

I'd say just run the methods I mentioned above when you need them, in this case maybe you can find to call a method after the subscene load where you put this in?

#

I don't know about callbacks sadly

solid flume
#

I could just try and move the map creation code to an oncreate I guess

minor sluice
#

maybe there is one when a subscene is loaded, no idea

solid flume
#

I guess when I need the array I call a function that initialises it if necessary

minor sluice
#

also I noticed that this isn't really the same use case, sry

hollow sorrel
#

anyone using ExclusiveEntityTransaction? so far i understand you .begin to get one and pass it into the job you want to use it in
but where do you end? do you have to .complete the job to make sure it's done? kinda defeats the point of doing it in a job then

safe lintel
#

heh actually just trying to figure it out myself(no idea what im doing though)

rough crown
#

Quick question, how would you make a Idle / Incremental game logic using Job system without using ints and longs? (otherwise you will overflow sooner or later) I've tried to use BigInteger but it doesnt seem to be compatible with the Job system.

manic aurora
#

I had the same question a while back. Seemed like the only option was a custom BigInt implementation. Maybe implement it as a native container. It’d still be sorta annoying to work with since you wouldn’t be able to stick em in a regular component data. Depending how much wacky big number math you actually need to do, might be worth it to see how expensive it is to just do your number stuff on the main thread / no burst.

#

Idle games already run pretty well in resource constrained environments, so the power of dots might be better leveraged making something high fidelity, rather than doing a premature optimization on something you can probably assume runs well enough already. Idle games like to have thousands of the same objects, which dots just loves, haha

rough crown
#

Thanks @manic aurora ,that's what I thought, doing a custom addition logic with native Containers of bytes. But seems too cumbersome. I think I would stick to big int and doing other stuff with jobs rather.

solid flume
#
_mapQuery = GetEntityQuery(new EntityQueryDesc
                                   {
                                       Any = new[] {ComponentType.ReadOnly<Land>(), ComponentType.ReadOnly<Water>()}
                                   });
``` This should query all the entities with either a land or water component right?
opaque ledge
#

no, BOTH Land and Water

solid flume
#

Wouldn't that happen with All

#

How can I query for either then

opaque ledge
#

ah nvm you are right, i didnt see Any

solid flume
#

Ah

solid flume
#

Ugh I quit

#

ECS is wayy too messy