#archived-dots
1 messages · Page 175 of 1
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
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.
@tardy spoke think of all the time you put into DOTS that you could've just worked on your game 😄
@trail burrow haha that's true. Probably about time for me to actually learn some OOP stuff anyway. Good to know it.
Ehh not sure, hahaha
welcome to the bright side
@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
I like the ECS paradigm, I don't actually really care about DOTS particularly
I like the ECS paradigm, I don't actually really care about DOTS particularly
@tardy spoke you can just make one yourself
XD
I like ECS as a pattern, but i dont like unitys implementation/hpc#
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.
it hurts me to say, but if you want to use ECS together with gameobjects the easiest is entitas
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?
yeah it does
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
My card game i made a completely custom architecture specifically for it
Yeah, I'd have to read some architecture books to not spaghetti an OOP project
Which relies on immutable game state, etc.
which is fine, and I probably would just use OOP if I was confident I could write large architecture without spaghetti
Not spaghetti in a Unity project is... difficult
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...
I feel like putting them in Assembly definitions might also help.
BUUUUT... still so much spaghetti...
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
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
I went down a route once of trying to instantate them, didn't work out so great and ended up being a mess
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
So to reuse unity serialization for the static data (that we can load dynamically on demand)
Please, post this question in one of the Art & Creative channels
[portuguese] Também sou brasileiro. Esse canal é para perguntas sobre programacao usando DOTS/ECS
#archived-art-asset-showcase should be good for it
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
@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?
its a lot of things, but yes workflow is one of them
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?
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
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?
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
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.
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
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?
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
are you talking about entt with unity or roll your own engine
yikes... 2040?
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.
what is the other
well, its sacrilegious, but ||adding ugc support to unreal and porting to it||
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
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
i've been remaking my game due to ecs and thinking about doing it again would prob be enough to make me quit
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
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
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
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
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
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
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
that one post on the forum thread where you contributed too was so funny "it is time to admit defeat"
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
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
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
oh, awesome
but it would always be bad UX/tooling
i thought the same at first but i realized i've spent more time writing custom tooling in unity than writing game code :/
its never on the level of any made for everyone style engines, there always rough, only changed to service the game at hand
The problem with buying Unity stock is you know they're gonna release some different incompatible stock in a year and then drop support for the stock you bought even though the new stock is in preview and has a bunch of missing features
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
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
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.
How long does it take you to build an engine?
unity seems to get a lot of criticism, but at least you can still use it to publish to apple devices 
not a 2d game? dont build any 2d rendering support, shaders, passes etc
6 months - 5 years
My biggest complaint with unity is that their 2D is awful
sounds about right
^in reply to june
i'm biased but tbh i think unity's 2d tools are actually pretty decent
Does anyone have experience with godot?
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
dependency locking on frameworks too
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
yup, its a real can of worms you dont want to open
yeah but when that happens you can just go public stock market
which is why I've never committed on a engine, other than in toy projects
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 😐
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 🙂
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
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.
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
yeah I know
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?
I think it's an object oriented workflow
might be an external plugin you can hook into it
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)
thats not official, just some random guy
i used ECS lib entt to optimize the godot renderer
you can see it in my fork
yeah it's not official - iwas just browsing around

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
what the hell
thats why godot spams linked lists so much
he forbids people from implementing alternatives
and godot Vector (nativelist equivalent) is trash
I knew the engine had bad decision smell, but that really proves it
I hope it doesn't turn into another project lost to the void because of crappy design decisions by high level people
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
I mean, anyone can read though learn opengl and put together pbr now
I love pbr, but its practically copy paste these days
Wuht why
Because it needs more than linked lists?
i honestly dont know why they dont even add fxaa
taa is quite tricky, i can understand
I love how the UI is structured just from opening a project
ive had a pretty hard time adding TAA to my engine and my implementation is rubbish
But the jagged lines are just offputting
you ever do anything more with entt in ue4? @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
find anything interesting out with it?
that unreal engine bottlenecks crazy hard
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
they are
and this is the job-graph that is autogenerated
how many transform copys is that
oof
instance mesh draw is updating 2000 instanced meshes
is there anywhere you can apply to the matrix directly, without dirtying it?
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
because I'd bet on them doing a lot of garbage work
i did it for a PUBG research project
ah alright
speedup was about 5x in that research
very nice
but it was super unsafe
you ever going to release any of this? I'm thinking about doing the same, entt in ue4
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
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?
oh within the github?
ye
awesome dude, thank you
this job scheduler thing is the current commit on the ECS_unreal project
now if I can just figure out UGC
the project has full custom networking and alot of physics based weapon ballistics
@signal flicker yes just use the Jobs system
If all you need is off main thread compute that is
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
gotcha
ive tinkered a bit with codegen
jobs system? i havent played around with dots yet
because stuff like this is just horrible https://github.com/vblanco20-1/ECS_SpaceBattle/blob/master/Source/ECSTesting/ECS_Base/ECS_BaseComponents.h
scroll down to the end
look at all those ucomponent wrapper things
btw, you cant put that in a macro
nor a template
damn, that sucks balls
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
not awful, but I've never been a fan of codegen
its kinda like the struct declaration part of a programming lang
yeah
yeah codegen sucks
i also generate reflection metadata
and imgui edit code
because, of course, cpp has no reflection whatsoever
yep
so writing editor code/debug code means you have to do it manually
or slap a codegen on it
I don't know basically anything about ECS but everything about godot literally screams ECS to me
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
Especially considering it has c++ support, so stuff like entt could be viable
yeah, theres a important distinction though, where components are smart or not
which they can be in godot
Godot could implement its current scene tree stuff as an ECS without changing user implementation
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
yeah I always wanted to do that myself
Technically since it's open source couldn't you just fork it, and make it use an ECS
a object, really is just a namespace set of functions, with the context of a set of data
like.. its really not so hard to connect an ecs to the godot scene system
its why you can do 'oop' in c, where the first param is the struct 'object'
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
yeah thats one thing I really wish we had in dots ecs
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
yeah
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
you'll be able to do faux virtual methods in "unsafe"-C# soon
for example a inmortal object could just remove the OnDamagedCallbacks component
with the new function pointer stuff
and then add it back when it becomes killable again
with damage code doing something like
gonna be waitin awhile lmao
8.0 coming soon
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
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
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.
@solid flume the method above is kinda like interfaces, except you can add/remove them at runtime wich is quite fun
and very efficient
it has kinda the same perf as just virtuals
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
I try to do that, but I always end up with monolithic classes when I try to avoid GetComponent calls
GetComponent is fast-ish
tho in unity ecs is worse than stuff like entt
in entt get-component is really cheap
What if unity used c++
I'm talking about GameObject get components, not ECS
well of course you should never use those at runtime
that one is incredibly expensive
exactly
Unity has a GameObject/Component architecture that forces you into a pseudo Actor architecture because GetComponent is so expensive
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
looks at Unity UI doing a ton of GetComponent per frame
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...
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)?
you shup up and enjoy the -ms
Right now, I just bite the bullet and do the get component
there is not much you can do 😦
there is some crazy trickery you could try tho
but is it worth the effort?
i was wondering if there was some magic hidden stuff i was overlooking all this time
you would have a GLOBAL singleton that holds a hashmap of all gameobjects that have a specific component
I once tried to replace GetComponent with a global dictionary lookup
It was not fun
select from all components at random, and go to the universe were it chose the right one
Quantum Computing (TM)
GetComponent is expensive, but honestly it isn't that bad as long as you're only calling it when it's necessary
yeah, basically eat the performance cost
if only unity reworked that side of the engine extensivelly
introducing hot paths where it could simplify things

given the original side is a clusterfuck for sure... that would be hard
thats kinda why they are doing unity ECS
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
think the codebase is too spaghetti to even bother?
hundreds of employees and they can't work towards unspaghettifying it?
It was calling GameObject.Find every frame
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
Camera.main is FindObjectWithTag("MainCamera")
@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
Not sure what it does now, but in a recent build they said they made major optimizations for it
I assume that unity has some internal caching stuff in place when it has found a component for a specific object before
like man, i could write their engine code with stuff like that lol
I read that, either after unity 4 or 5, the GetComponent was already rather efficient, maybe it was different before
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
FindObjectWithTag("MainCamera").GetComponent<Camera>()
is literally what it is yes ^^
I just want ECS to be finished so I don't have to worry about walking into landmines like that anymore lol
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
It was like 3 pointer jumps last time I checked
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
oh, yea, there is a linear search through all the components in the archetype
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....
what were the advantages of unity's ecs model vs the one that entt uses(besides getcomponent) and why arent they using that model?
@safe lintel because unity model parallelizes better, "merges" better, and has higher perf in high sizes
ahh
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
Is it possible to GetComponent and set the data for that component from inside a SystemBase for each?
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
wouldn't it be the opposite? I thought you would try and max out each archetype chunk on Unity ECS
IE is this a thing?
@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
gotta use SetComponent on the struct @tardy spoke
I figured that having fewer archetypes would be more cache friendly
@safe lintel gotcha
@odd bay but you dont have fewer archetypes
if those 4 components allways go "together", you have the same number of archetypes
oh I see what you mean
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
Anyone know if SystemBase ForEach loops can be nested or nah?
Epic said they were implementing ECS for UE5 right?
no?
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
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
http://actors.pixeye.games/ I forgot, was this a good ECS library?
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?
anything that is C# will work
the unity part is for editor support
which is super important
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
So what is the use of these libraries then
Why would I use entitas if it can't render anything
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
Ah
so the entities are constantly reusing the same sets of gameobject meshes
Makes sense
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?
marble.hasBeenTargetted = true
weird, thought I just tried that
I mustve forgot to save or something. Let me try it again.
i think its because you already are accessing Marbles in foreach
oh it was because of the unecessary GetComponent in the //only loop through untargeted marbles IF
in a ForEach
that get component is unnecesary, it can be done on the query itself
ComponentDataFromEntity<T>
Right
does the lambda take entity queries yet?
@vagrant surge not just unnecessary, it broke it haha.
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
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 ¯_(ツ)_/¯
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?
depends on what update means in this context
change some values? sure you can do that
you're using entities.foreach right?
don't need to do anything fancy then, you can access the component by ref if you add it in the params
https://docs.unity3d.com/Packages/com.unity.entities@0.14/manual/ecs_lookup_data.html
= you're modifying the component itself, don't need to cache entity or anything
Right right. It’s been a while since I’ve dug into this. Thanks!
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
what's the closestMarbleEntity? And how is it retrieved?
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?
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)
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
hmm what do you mean to dynamically add an element to the array?
So with a list I’d do list.Add(integerValue)
Ah so NativeList<int>().Add(intValue) isn't adding the element for you?
Intellisense isn’t showing Add as a valid method
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
but the Add(...) method exists for NativeList
Yeah no worries, happens to me too 🙂
Ok so that worked for intellisense but it’s throwing exceptions ‘invalid operation exception’ entityList has not been assigned or constructed :/
how's entityList created?
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>()
@coarse turtle How do you look at that color all day?!
😆
Or do you have tritanopia?
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 theusing (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 🙂
I believe Temp and TempJob doesn't get automagically deallocated.
you have to manually deallocate them according to my exp
Yeah I couldn't remember for Temp, thought it was like stackalloc at one point
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
Good to know for Temp, thnx Scorr 👍
found post that mentioned it https://forum.unity.com/threads/allocator-temp-container-need-dispose.852082/
even unity guy didn't know what it did at first hah
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 😆
PS: I'm immediately more productive forgetting about DOTS. Here's my few hours for a (nearly) zero lighting scenario for proc gen
congrats benjamin
Nice @violet cosmos
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]);
}
}
turns out passing in interface'd structs is a pretty common workaround.
question: what's the math library equivalent of vector3.moveto()?
I thought the math vector3 stuff wasn't related to transforms? It was meant as simd vectors for hardware optimization
Edit im wrong lol
there isn't an extension method if that's what you mean? Fairly easy to do it manually though.
@blissful gorge it makes it easier for transform calculations to be vectorized
@amber flicker yeah I did it manually
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
I'd be slightly surprised if anyone here had attempted it let alone best practices 😬 - you're probably the expert here
Haha, leading the charge I guess
well.. fholm and others might have done more I suppose 👍
You're worried about vectorization? Some serious optimization huh
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
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
Oh CDFE's has branched checks?
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
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
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.
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
IJobChunk is by far the most efficient way
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
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
That is a good point
IJobChunk > * when it comes to performance, it's more boilerplate for sure
I keep forgetting CDFE is a copy
but there's no competition when it comes to perf
Is that not what Entities.ForEach compiles down into
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
afaik no
I think most instances you'd have trouble profiling the difference?
It seems like it since the Burst output seems to create one inlined function without function calls
burst does its thing on top ofc
But I could be reading the ASM wrong
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.
Hmmm
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
I might switch to it if it's critical
also scheduling less jobs is much more efficient
Another question, is there a way to disable simulation but not rendering?
the inter-job overhead is not none
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.
@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
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:
- I have a X thread cpu
- Job is split into X pieces
- 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
I've found that has improved over time but obviously < jobs is better I agree
idk if it was an issue because my stupid high core count cpu (32) or issues in the job system
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
mine takes a fat 0.08ms lol
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'
My lib has quite a lot of different systems but it does quite a good job filling the threads from what I can tell
from my experiments, each component you have in your for-each query costs 0.01 of overhead
@amber flicker that gap is nasty
the one that goes straight down
like what the fuck is that, almost 0.1ms of
"nothing"
haha well.. I didn't say it or I was perfect - it's sync points I have where it's waiting to complete
does unity ecs overlap 2 parallel fors together?
this is like 100% unacceptable
caveat this is in editor
parallel fors allways have a sync point where threads sync at the end
@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
I don't have confidence that this isn't my fault for a start 🙂
@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
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
I'm hoping this is part of their system & job optimization work
if you're saying there's plenty of room for them to do better... cool... good news as far as I'm concerned.
tbh ours is purpose built
it's completely without sync points
between the threads
completely lockless/semaphore-free
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 🤣
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?
Fair enough. From my pov it's still 100x improvement on what was there before and it's not finished yet.
like this stuff
this is from my scrapped dots networking library
what the hell are those gaps
or even when you get it running, that big gap between the two block is like 0.7ms
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)?
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
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?
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
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.
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
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
This is the exact error message
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.
Has job scheduling in the editor gotten worse since 2020.1?
Comparing it with 2019.3, it seems to be slower
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?
Either run the jobs on the main thread, or have the collections be static somewhere(a field in the job?)
or well, has more gaps between jobs, and bigger gaps
Like, coll.Dispose(dep)
Hold on, I'm probably mistaken then.
@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
I'll try it
I mean instead of that you can just add the line Dependency = dep; but you get the idea.
what is BurstedParallelForEach?
on my machine, the hybrid renderer system takes... 0.55ms
that's.. nice? or you mean without rendering anything?
[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
@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?
Considering 10ms is being taken up by hybrid renderer
@amber flicker yes
Any reason why a culling job can take 20ms?
Over 2 instances
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.
for 2 meshes? It shouldn't be. What does the timeline view of the profiler look like?
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
That sounds too high - but performance with a large number of dynamic objects is generally really bad still with the hybrid renderer
Oh, also I guess the reason it's doing nothing is because they need to have colliders for my system
Any reason why a culling job can take 20ms?
Just turned on burst and now it's a nonissue
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?
to do what?
entities package not showing up in package manager in 2020.2.0a21.2837?
yea that grimace was aimed at Unity rather than you 😅
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
Haha magnificent
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.
Oop, there it is, I think.
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.
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?
well EM has batch operations
might shed some light on whatever topic you're interested in
^^ there, that was what I was saying
but yeah... EM can be fast, but ecb benefits from being routed in burst
Interesting, read the article. I like it because ECBs often give me weird errors even though everything still works, hahah
Traditionally I have fields on components attached to gameobjects that I can manipulate to tune things. Do those values now need to be hardcoded?
if you use the subscene workflow you can do the same with an open subscene
Never heard of that before
a subscene?
Yea
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..
@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
Not really. I have a tolerance for approaching a waypoint for example, or a spherecast radius
if your workflow is "hybrid" or whatever
ah, hmm
well you could load that from a piece of data on a component?
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
Yeah and if that component has generateAuthoringCompoennt you could adjust it in editor
before running
@solid flume https://youtu.be/HdJHk0moJ7c?t=969
^ tutorial that shows it
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
@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
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?
Generally include that in your EntityQuery
It checks at the chunk level instead of the entity level
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
In that case use HasComponent
There is a SystemBase function for it
Or if you want to manually do it in a job
Yeah, that
Use ComponentDataFromEntity
Ah, okay
Which also has the same function
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
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
So I'll do it in the parallel for job that does the collider casts
My design has been collider casts -> component checks -> NMHM in parallel
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
NativeMultiHashMap
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
convert 1, then use EntityManager.Instantiate(convertedPrefabEntity) - especially the one that takes a NativeArray
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?
you can, yes
What's the difference between SystemBase and ComponentSystem and all the other types?
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.
Ah
Okay
Can I create entities in the editor? Like outside of runtime?
Preload it
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
So I can make a subscene, and it'll already be converted to entities, then I just load it in with minimal overhead?
yea pretty much
That's the theory, anyway, haha
Can I have a monobehaviour populate a scene in the editor somehow?
It looks basically like a normal GameObject
From my experience even though they seem like GO's they don't seem to execute monobehaviours and things on them the same way
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
So I'm using Entities to control GameObjects
Is there a recommended way to control pooled GOs from ECS?
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:
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
1s
Since the ECS model is very distributed I’m having a hard time getting my head around it
Thanks! I’m not sure I see how this handles the different contexts though
?
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
Sidenote: That's a SkinnedMesh (without any sort of animation whatsoever)
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 🙂
@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?
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?
you can make a static function and call that inside your lambda
I thought burst doesn't like static?
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
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?
afaik, A* Pathfinding project pro has a beta for ECS/DOTS pathfinding
need to do it by hand mostly
Can I assume my system's onCreate will be called after all my gameobjects are converted to entities?
3K memory leaks 
gotta love hdrp
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
ho you just have to use the World constructor, neat
yah! its pretty awesome for writing tests
https://i.imgur.com/BocNw1P.png great, you can't add shared components to arrays of entitise in ecb --'
is Entities.ForEach burst compatible since it uses a delegate?
I see it has a try .. finally block
Entities.ForEach generates code for you, it doesn't actually use a delegate
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++
oh damn @rancid geode , I'm looking to do a similar thing with some LINQ-like methods. Have any recommendations on where to start?
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
What's the difference between NativeList<T>.RemoveAt and .RemoveAtSwapBack
RemoveAt keeps the order in the list
SwapBack moves the last element in that place
I'm guessing SwapBack is faster
You're guessing correctly
(btw, the docs explain the difference, so I'm not sure why you're asking here)
Ugh I tend to go here https://docs.unity3d.com/ScriptReference/30_search.html?q=NativeList
Why are the docs split up
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 🤔
Afaik the goal was to detach the package version from Unity version
The result is hard to google chaos 🤷♂️
Hmm, I don't have issue of finding the doc with Google even if what I'm looking for is in another package
I hate the docs format for packages
Though I would say the search on doc site really sucks.
"Unity NativeList" gives me the doc page as first result... package version 0.0
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 ...
FYI, relevant thread here 👀 https://forum.unity.com/threads/converting-gameobject-to-entity-90degrees-off.951326/#post-6249294
Seems to be a "common problem" with skinned meshes in Dots.
@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
thought you mind find this interesting @tardy spoke https://forum.unity.com/threads/hybrid-ecs-and-incorporating-monobehavior-apis.959562/
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.
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);````
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.
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
Entities.ForEach is full codegen ye
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
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
@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
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
why did I throw myself in such a rabbithole with combined meshes 
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?
You can use it non jobs but it can't be used with managed objects
@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
Link? Assuming they're misinformed
https://forum.unity.com/threads/can-we-gain-benefit-from-burst-compiler-without-using-ecs.550375/ there's a lot of older posts that say that, I wonder if it used to be the case
Burst has developed a lot since 2018
So, can you burst a struct that isn't an : Ijob ? As in any struct not using any reference types?
It did used to be the case
Right, that makes sense
But now you can use it for more
You can burst static utility methods in classes too
From the Unity.Mathematics library or are there others as well
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?
you can use burst on static methods, they do this within ECS for some of the EntityManager methods.
What's the difference between calling .Run() on a job and .Schedule().Complete()
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()
.Run() = makes it run on main thread
Hmmm
.Schedule().Complete() = waiting on background thread(s) to finish it
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
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())
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?
but I never cared enough to test that to see if my assumption was correct
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
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
So how can I initialise a native array?
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..?
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
would a filter job or a EntitiyQuery WithAny be too slow?
I dunno, I'm bad at ECS
What's a filter job
Also, I can iterate over an entity query?
maybe you can also write an entityquery with how you need it and reuse the results of it? (if the environment doesn't change)
It doesn't
you can get the results on an enttiy query, either all entities or specific components and iterate over them yeah
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
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
But when do I run this. I need it to happen after the subscene is loaded
There some sort of callback?
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
I could just try and move the map creation code to an oncreate I guess
maybe there is one when a subscene is loaded, no idea
I guess when I need the array I call a function that initialises it if necessary
also I noticed that this isn't really the same use case, sry
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
heh actually just trying to figure it out myself(no idea what im doing though)
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.
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
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.
_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?
no, BOTH Land and Water
ah nvm you are right, i didnt see Any
Ah