#archived-dots
1 messages ยท Page 129 of 1
Guys sorry for those random questions, how can I fix a entity rotation? Do I have to set the rotation to 0 on a jobcomponent?
that's actually something of a #โ๏ธโphysics question depending on your needs
Oh sorry!
kinematic bodies can break a lot of things unless you know what you're doing
if it's just a visual thing then go ahead
Think that is about physics then
ok, a hopefully last question for the singletons:
If I do
OnUpdate(){
var globals = GetSingleTonEntity<WaterBuffer>();
var buf = GetBufferFromEntity<WaterBuffer>()[globals];
Entities.ForEach(){
//use buf
}
}
to what is the depency on WaterBuffer now added? For the entities.foreach job or for the system itself?
I'm guessing there's no way to get scene view render converted meshes in real time when using DOTS subscene?
I just found out that joints work on dots subscene now (but still having issues with some other physics conversion scripts there)
have to check codegen but to system itself most likely @junior fjord
it's just annoying to have to use debug gizmos on the actual game view, can't view everything as easily (gizmos work on scene view but are pointless unless you can render the meshes on real places)
yeah, but I need the depency on the job, not on the system right? I don't want the system to wait until anything finishes, I just want it to run, schedule the job, and the job has to wait until the buffer is free again
actually wait, there is no handling dependecy here, you are accessing the buffer in main thread, so if you were to make another system that access that buffer it will give you an error
you have to access the buffer inside your job so Unity can handle dependency
its not a problem for me since i am only doing it once in 1 system so it doesnt give me error
are there no jobs running while OnUpdate is running?
So unity first runs all onupdate and then schedules the jobs?
yeah something like that
ok, is there an easy way to check the dependences a system has? I never handled them explicitely before
afaik no
SystemBase.Dependency
haha ๐ ok then I'll just hope unity does the right thing?
@dense crypt is that something human readable?
Na, but it's the dependency chain
thats just jobhandle, it doesnt give you any information about what stuff that system is currently being depended on
New debugger should be able to help you show dependencies
there was a forum topic about an 'analyzer' to inspect dependincies, not sure if it is going to be reality
is that new debugger out already?
hmm ok, so by using the buffer in the foreach, unity sees that the job also queries the buffer and therefore adds the corresponding read/write depency to that job?
yes
is it enough to do it like this
OnUpdate(){
var globals = GetSingleTonEntity<WaterBuffer>();
var buf = GetBufferFromEntity<WaterBuffer>()[globals];
Entities.ForEach(){
//use buf
}
}
or do I need to call getbufferfromentity in the foreach for that to happen?
right now you are doing it on main thread so Unity cant 'see' it therefore cant do any dependency stuff
No, you do
Entities.ForEach(in/ref DynamicBuffer<YourBuffer> abc)
then unity resolves the dependencies automatically
var globals = GetSingleTonEntity<WaterBuffer>();
var buffers = GetBufferFromEntity<WaterBuffer>();
Foreach(()=>{
var buf = buffers[globals]
})
yeah but this is a singleton entity with global data
ok, so I actually need to access the BufferFromEntity thing in the foreach for unity to understand it (so in this case buffers instead of buffers[globals])
yeah
ok thanks as always ๐
its however pretty slow unfortunately, i am hoping that they will give us an easy way to access singletons
why not get this buffer with EntityManager ?
its a main thread access
and?
you will get an error if you do the same in a different system..
please notice that its not a read only
var globals = GetSingleTonEntity<WaterBuffer>();
var buffers = EntityManager.GetBuffer<WaterBuffer>(globals );
Foreach(()=>{
//do your stuff with buffer
})```
buffers is a WaterBuffer, not BufferFromEntity
but he has only 1 buffer
Yeah but there could be access from different places
lets say 1 system writes to it, 1 system reads from it, and they are both accessing it on main thread and schedules a job to access that buffer you will get an error
if there is only 1 access, then its fine, but not when multiple
reading online it seems that GetSingleton creates a sync point and waits for all jobs to finish
yes
so if I would have
System A -> Gets buffer, schedules job with it
System B -> Gets buffer, schedules job with it
Then the OnUpdate of SystemB will wait for the job scheduled in A to finish?
Singlton is simply and entity
as an naรฏve idea, why not use blobasset?
you can have blobassetreference in component
presumably the data in this case is mutable?
every entity which need acces to your global thing will have this component
if you need to change global thing, you create new blobassetreference and update all components
and you can change blobassets๐
I think the idea of a singleton entity for my global arrays is quite nice, I just noticed that I have no clue of how unity actually does the dependency management between jobs.
Therefore I do not understand what happens if I do some query in on update and then start a foreach job with another query
you can but it's just higher resistance right? dunno ๐
you will create sync points when you access your singlton๐
with my idead you don't need to sync anything
you get data straight from job
ok.. so there's a bit too much above for me to scan quickly but isn't this what the shared static stuff is for?
but until now I am just using static nativearrays for my data, the only reason I wanted to convert is to make use of future (or already existent?) "save all entities" "load all entities" stuff
and get rid of the disposing of the nativearrays and stuff
yeah either sharedstatic or global nativearray is also an option but people recommended me singleton entities for global arrays, and I actually like the idea
I just don't understand the depencies I am creating unfortunately
so if I would have
System A -> Gets buffer, schedules job with it
System B -> Gets buffer, schedules job with itThen the OnUpdate of SystemB will wait for the job scheduled in A to finish?
@junior fjord but what about this?
OnUpdate never waits
it might not be the 'best' solution or whatever, but it works ๐คท
unless you say .Complete()
yes @opaque ledge I know you showed me, I read it and thanks a lot, I just don't get it ๐
it waits if you make structural changes
Your job will run on another thread in the background
the job that get scheduled last of the two is the one that will wait until the first job is done
this thread https://gametorrahod.com/ecs-singleton-data/ says On GetSingleton for example, it will immediately complete all job dependency on that type (on the main thread) and get you the data.
Am I right in thinking... reading data in a job without sync point, you can do via Shared Static or BlobAsset - this is because both have a very explicit 'I'm not being written to' aspect. Singletons create a sync point but therefore they are less of a faff to write to so nicer to use?
@junior fjord use thins things < > around your links๐
Entities.WithName("JobA")
.ForEach((ref DynamicBuffer<WaterHeight> buffer) =>
{
Debug.Log("Hi");
}).Schedule();
Entities.WithName("JobB")
.ForEach((ref DynamicBuffer<WaterHeight> buffer) =>
{
Debug.Log("Hi again");
}).Schedule();```
This will make JobB wait on JobA. It will not make OnUpdate() wait
this is not the case we are talking about ๐
Oh no?
yeah no, I understand that case
our case is like get buffer from first query in main thread and pass it to second query
which basicallly will be JobA.Complete()
unless you use NativeArrays
Hmm ok then I misinterpreted the question
and this is some sort of solution too ๐
I am scared of this:
SystemA:
1. Get WaterBuffer from global singletone in OnUpdate
2. Use this buffer in JobA, which it schedules using Foreach.Schedule
SystemB:
1. Get WaterBuffer from global singletone in OnUpdate
2. Use this buffer in JobB, which it schedules using Foreach.Schedule
Now as I understand it, JobA will run, maybe through some magic even understand that its ForEach.Schedule also depends on the WaterBuffer and note in the job depencies that it writes to WaterBuffer.
Now SystemB runs right afterwards and when it does 1. and gets the singleton, it will now wait for the JobA of SystemA to complete. But that is not what should happen, it should schedule its JobB should wait for JobA (not the OnUpdate itself)
when I am using nativearrays instead of the global buffers, I don't mind, I do not have this problem, since unity does not care for them and I handle the dependence of the jobs myself (either explicitely or by using tag components s.t. the systems don't run in parallel)
I am basically trying to understand if the above case is somehow way more trivial than I am thinking or if I just should stay with my nativearray solution maybe
This singleton is the only entity with WaterBuffer?
yes waterbuffer is a singleton component
why not use something like this?๐ค ```cs
public struct ReferenceToGlobalBlob : IComponentData
{
public public BlobAssetReference<WaterBuffer> Value;
}
Entities.WithName("JobA")
.ForEach((othercomponents, in ReferenceToGlobalBlob reference) =>
{
}).Schedule();
yeah that is basically what I am doing, my current setup is
public static class Globals{
public static NativeArray<float> WaterHeights;
}
public struct WaterHeightsIndex : IComponentData{
int index;
}
Entities.Foreach((in WaterHeightsIndex id))
I don't know what these BlobAssets are, I can take a look into them
but seems like a similar way of doing it
but if you want to change your native array it is not safe and easy ๐
ok here, ths is my actual setup ๐ (I shortened it down a bit):
you will need to pass jobhandle from system wich changes your native array to every system which uses it ๐
public static class Globals{
public static NativeArray<float> A;
public static NativeArray<float> B;
}
public struct TileID: IComponentData{
int id;
}
public struct AccessToA : IComponentData {}
public struct AccessToB : IComponentData {}
Entities.Foreach((ref AccessToA _, in AccessToB __, in WaterHeightsIndex id))
and with my thing it is just cs assetRef = new BlobAssetReference Entities.WithName("JobA") .ForEach((othercomponents, in ReferenceToGlobalBlob reference) => { reference.Value = assetRef }).Schedule();
this now writes to A, reads from B and unity will handle it s.t. no other system writing to A or B is run in parallel
all I have to now do is check that I only write to A[id] in the for loop, s.t. I don't write to the same place from the same job
the only things that bug me about my approach are
- Nativearray allocation/disposing
- always having to do
var a = Globals.AandEntities.WithReadOnly(A)orEntities.WithoutParallelForRestrictionsin every systems that use the arrays - that if I have to implement my own saving/loading mechanism for the nativearrays
I wanted to get around 2 by using SharedStatic instead
And I thought singleton entities could get around 1 and 3 even, but it seems they are kind of complicated
@warped trail I don't really understand your example code
what exactly?๐ค
maybe I need to check what blobassetreferences are. But you are just setting all the buffers of your entities to the same assetref that you just created before?
thanks for the video ๐
looks good
ok these blobs are pretty cool, pretty much what I implemented with the tileIds I think
unfortunate that they are readonly ๐
you can change them๐
I like Brian Will's videos and usually agree with his points, but that first comment is correct. This is the guy who complained about Unity's naming scheme being too long and descriptive. Think he takes it in way too far a direction using variable names like m,d,e,e2.
but aren't they really too long?๐ค
yeah, not disagreeing with that premise so much as his proposed replacements in that video.
hmm now I can't find that video
yeah the videos are great, I just checked his channel
it is so unfortunate that you never seem to find stuff like that by yourself
yes, we're asking what happens if you make the internal storage buffer large enough that it can't fit into a chunk
@sour ravine
If an archetype is too large to fit inside a chunk unity will immediately throw an exception when you press play. Unity includes InternalBufferCapacity for a Dynamic Buffer in this size check
if you just search for unity ecs on youtube you don't find him
and I am a fan of very describive names ๐ all my stuff is way to long
i am fun of 80 characters per line๐
long descriptive names are typical in the C# business world
yeah I don't follow that rule, but I also never have two code windows open side by side
ok maybe if I am copying stuff from my webbrowser it would be nice if the code would fit in one half of the screen
i limit my line widths because im on a shitty laptop without much screen space and my vision is getting worse :S
but for me being able to quickly skim stuff and directly understand what is what is more important
I've been spoiled with a dual screen setup, so i make my variable name 80 chars long ๐
what I really hate about C#/Unity is their naming scheme of method members
I don't like camel case and I don't like member variables starting uppercase ๐
whats amusing is the mismatch, im fine with it if you go that way 100%
but like 30% of it is proper c# naming conventions and the rest is a batshit mix
hungarian notation is lowercase camelcase?
m_
i_like_this_version
you can change them๐
@warped trail
You can't change blobassets, you can replace them but you then need to go and update all references to the original blobasset to point to the new one
but why not work with nativearrays if you are already on that point?
this is how they change collider size in Physics samples
I haven't seen it myself, but I guess you would be right then. I remember seeing a unity person say the same thing I just said to someone on the forums wrt Blobassets
But maybe I'm misremembering that
some voodoo * stuff ๐
i've avoided blob assets like the coronavirus, the way they're created seems so annoying.
lol - I've used this mainly in the beginning but after a while I've stopped using it ๐ค
I might pick it up again to store font glyph information
you can create them once and then serialize them to disk๐
blob assets?
used by the conversion system, allows you to write some data to binary, and load it back
the fun part is that they are crazy fast
because its basically just a memory chunk you load and use almost directly
oh its dots only eh?
common use cases is stuff like navigation meshes, where you just compress the navmesh into a binary array and store that
blob assets?
@stable fog
There's actually no good docs/examples on them so https://youtu.be/q1_b--k3fQ8?t=869
Gives a good overview of them
I'm working on a map editor, was hoping maybe there was a new way to store data that'd be faster than building assetbundles
thats a good example for them
you would store most of your map as structs and arrays, as a blob of memory. Loading it doesnt need parsing, it just loads from file into RAM and you can inmediately use it
I don't think it's dots only really, it's just a big blob of read only memory you can access in parallel in jobs
very important for next gen consoles where that "load file into ram" is suuuuuuuper fast
@zenith wyvern + save/load to disk
Wouldn't it be preferrable to use some kind of compressed file in that case?
Depends what you're doing I guess
Oh?
having blob assets automatically get zipped is something very likely to be a thing
if its not like that already
next gen consoles both have hardware .zip decompressors, and extremelly fast ssds, so you want to make sure that you dont have any parsing
so stuff like blob assets, which are just a binary dump of some struct/arrays, are a perfect fit
blob assets can be copypasted from disk to RAM and then they automatically work couse its just a binary dump
Is there any examples or anything of saving and loading blobassets to disk?
there were some of that im sure, they go with the subscenes
and get stored alongside the subscene
but would need to go look at the specifics
Ohh I see
quick Q, if you have multiple RequireForUpdate(entityQuery) at the same time, do they AND or OR?
But subscenes are more for editor-time only, I was thinking of using them for procedural stuff
subscens are a serialized group of entities
why would you want to use them for proceduralism?
Not subscenes, blobassets
quick Q, if you have multiple RequireForUpdate(entityQuery) at the same time, do they AND or OR?
@wary anchor
They and, the default behaviour from implicit queries is OR
thanks!
I have trouble understanding chunk.DidChange and how it works
In case if I'm not mistaken, it takes the current iterating system version and compares it against the chunk's LastSystemVersion and that's how it can tell that the chunk actually changed
@zenith wyvern https://pastebin.com/5sGrTDAB ๐ค
But I don't understand how exactly can such a method even work
@warped trail Thanks!
It says "LastSystemVersion is updated to match the "GlobalSystemVersion" whenever a system runs."
So, alright, I have my systems and each time they have an incremented GLobalSystemVersion compared to the previous frame. Alright.
How does it help identifying that the chunks changed though?
you could always troll through the source code; but i believe the way it works is, whenever anything writes to something in a chunk, the version of the chunk is updated.
Well yeah, that's what I'm trying to do, but I can't make any sense of it
Like, here
It says that systems that access components from chunks write LastSystemVersion to it
its saying that it doesnt know if you actually changed the value, if the component used in a job is ReadWrite then its going to mark the chunk as changed.
But that doesn't make any sense. It's just writing the same value over and over then
with write permission
Anything that accesses a chunk with write access marks it as changed. Doesn't matter what actually happens
would you guys do 5 systems that have rarely run, related queries using Entities.Foreach... or have one system with 5 queries that are branched in Update with IsEmptyIgnoreFilter? I guess you could just still do 5x Entities.Foreach and let system base do the same Any RequireForUpdate behind the scenes.
If all the jobs the system is running are really closely related I would prefer the latter until the system grows pretty big, then go to the former
But then it would mean that if the entity "contains" the component that is being iterated upon at least on one system, then it would be marked with a new version and the check is useless
Is that right?
it only really comes into play when you're dealing with huge numbers of entities.
this is why you should specify read-only access to components whenever possible๐
Are there any more fine-grained approaches to discarding chunks from processing?
Adding more components
I've heard of SetFilterChanged, but it works only with SharedComponentData IIRC
You can use WriteGroups to override other systems based on the existence of a filter component
Just making good use of RequireForUpdate and change filtering can make a huge difference but yeah there's not a lot of simple options for really specific filtering unfortunately
Alright, now I'm confused about the [WriteGroup] attribute
How does it really differ from specifying which components to exclude from the EntityQuery?
It overrides other systems, so you have a system that runs instead of another system based on the existence of one ore more extra components
https://docs.unity3d.com/Packages/com.unity.entities@0.8/manual/ecs_write_groups.html Explains it better than I can
Yeah I just read that, but I still can't understand how can it be helpful
It feels more like a hack for you to silence other systems rather than just go on and refactor your other systems with which you may conflict
The transform system uses it extensively. There's like 10 different systems that all need to do specific things based on the existence of extra components added on to LocalToWorld. It's a bit old at this point but this video goes over it in detail https://www.youtube.com/watch?v=p65Yt20pw0g
March 23, 1:00pm (San Francisco) - Mike Acton demonstrates best practices for component design to achieve a high degree of parallelism, minimum synchronization, and high performance. He focuses on data layout and uses common examples in games (e.g. spatial queries, logic updat...
write groups are kinda super convoluted
It seems like a reasonable way to get polymorphism-like behaviour in ECS
Though they are complicated for sure
nah not really, its just automated filtering, in a way
in my cpp ecs i just do this
chunk iterate witch checking if you have a comp or not
For 100k entities... ScheduleParallel() ~1ms, 12ms total over 22 workers.... Run() 3ms main thread... in editor but safety checks off and burst enabled. Makes sense I guess but a shame total time is 4x
what about Schedule()?๐ค
thats an interesting trade off when it comes to CPU usage and battery life, if its doing 4x the work to get 3 times faster.
yea... I'll try schedule for comparison - guess I may be hitting memory bandwidth issues or other things I don't understand ๐
actually tbf.. this was with deep profiling on.. will redo
ratio about the same deep profiling off
schedule is about the same as run in my case (possibly v slightly faster)
also please do the profiling on the build ๐
you could do an IJobParallelFor{}.Schedule.Complete and compare it against Job.ForEach.Run with the same work, wrapped with StopWatch. I think it would be a more accurate comparison. You can also then compare different thread counts.
and what type of work are you doing in jobs?๐ค
work is a lot of CDFE and ifs - wish it could be otherwise but that's what it's doing - no buffers or anything fancy
fwiw timings look pretty much the same in attached builds
That's like the worst case scenario, nothing but random access
https://www.gdcvault.com/play/1026171/Connecting-the-DOTS-The-Unity
@warped trail
Also regarding Write Groups I linked to the wrong video. THIS is the video I was thinking of but apparently it's been wiped off the face of the internet
I actually cannot find it
it works fine for me๐ค
Write groups are super interesting, a bit hard to get my head around tbqh. But i learned something there so thanks for the link. The health example with the invincible component was really good.
yea - i was stuck when I was reading the old docs for so long
until they have that example in the newest doc version
it works only if i refresh the page๐
So after 3 days debugging an issue I assumed was from my DOTs code, looks like it's just been a issue with Unity that for some reason they keep having break again and again.
thoughts on project organization of components/systems? in two of my projects now ive grouped systems in a folder and then sub-grouped within that once the counts of related things go beyond 5 or so. Same deal with components. But now that im getting up to around 40 components im starting to think that in some cases it could be clearer to group components into the systems .cs files if they're only used there.
I did the same as you when testing before, and found having them contextually separated worked best
I used to do Systems/Components folders but it got to be too messy for me. I now group related systems and components together in their own folders
Only issue was I kept forgetting if id used folder to components or systems or if I'd used naming conventions...
interesting. that reminds me of the old MVC .Net days, where the accepted organization was copy of the same organizational tree for each data type. So ilke.
Components
>> Section
>> Feature
Systems
Section
Feature
almost everyone does separated systems and components folder
I have no idea why but the first link suddenly works for me now (it wasn't working before even if I refreshed)
Who knows
gdcvault.com/play/number is the default form for all vault videos
and of course, copious usage of go-to-definition
or all vault content in fact
More anecdotal numbers for comparison, a v simple job with linear access ~1ms total time Run, ~2ms total time for ScheduleParallel() - a multiplier closer to 2x than 4x - I guess it makes sense that more rand access makes the scaling across threads worse - all 3900x specific of course
Unity's own packages don't do separated systems/components
I've done some parser for gdc vault so I've played with their website structure a bit
They do related systems and components together
Well, it's probably not at all uniform across all packages actually
@amber flicker true rand access does indeed not scale well across threads, as it bottlenecks on memory bandwidth
and if it was on 1 core, more stuff would fit into the cache, so you would get a better L2-L3 hit rate
Huh, so if your job is only doing random access it's better to just do it on one thread?
talking about "for loop" type random access
if its a linked list, multithreading is a lot faster
the thing is that on very simple loops, something like:
for(int c : components)
{
c.val += components[c.parent].val
}
cpus crunch this pretty well
as they can pipeline the loops somewhat decently
if its a linked list or a graph, where you cant pipeline a thing, there is more stalling
so more threads (even hyperthreading) would help
so im checking the sample for Tiny Racing
and running it through the profiler to see where time goes
looks like something north of 90% is job system overheads
the actual time the code inside the for-each lambdas take to run would be something around 0.1 ms total
this is the profile capture for the "MoveCar" system in Tiny Racing
this is the profile capture, with the "useful" stuff marked
checks off
@vagrant surge you've toggled off the safety checks in the editor?
are you testing in editor?๐ค
also, I'd strongly recommend profiling in the build if tiny supports it
yeah its editor, so not that accurate. but still the sheer delta difference of useful work vs others is huge
what the point of testing Tiny in editor๐ค
@warped trail having a pure ecs environment
it is different thing in build
gonna try build and run and see if the delta is still this absurd
i don't think you can use profiler in tiny build๐ค
dont worry i cant make package anyway
it is like no unity in build๐
build errors XD on dots packages
trying to package for standalone, not really web
for what the profile callstack looks, it seems like all that overhead is the logic that checks if stuff can run in parallel or not
you need the new build tools to package for dots runtime afaik
they ship with platforms package now
all foreaches do it, because they are still a job even if they get "Run", on Run is job but on main thread, so it needs to check if there are pending jobs with data hazards
this also means that its likely that a ecs build that does Run ONLY is likely to remove a lot of this overhead
I'm inclined to believe vblanco's roughly in the right ballpark though.. my simulation group is like 0.5ms processing just one entity - it only starts increasing when I'm near 1000 entities
0.5 ms too much
systems here tend to have 0.05 overhead
which seems more about right
but the more interesting part
the more components you have on the for-each, the slower it is
and im sure its due to this dependency checking
systems that have a lot of components, like this MoveSystem which has 8, take like 0.1 ms
systems that only iterate 2-3 comps, are like 0.02
so it even looks to be linear
0.5ms for all systems - not an individual system.. that'd be bad
also btw, GetSingleton<> is slow as fuck for some reason
@amber flicker 10-20 systems?
less than 10 but some are run multiple times with .Complete (and yes, I know that's not ideal)
no wonder my cpp ecs is a lot faster. it doesnt do any dependency checking whatsoever xD
cant do a build
Does dots work with "Adressables" ? Sooo... for example a System which spawns in Prefabs from those adressables ?
guess to do a build you need the exact specific unity version or it doesnt work
@stone osprey nope - there's a recent post on the forums I think saying one day they plan to have better interop
without being able to do a optimized build i cant really properly check this stuff ๐ฆ
would like to see what is that checking overhead on a real build
@amber flicker uhmm... that sucks... there goes my plan... thought about storing prefabs, icons, whatever in those adressables... and a system which gets triggered by a incoming packet is used to spawn in the certain prefabs by using that adress system
@vagrant surge I know it's not 'pure ecs' but a normal unity project should show a similar thing right?
this is just job system stuff
but look at the profile capture ive seen
see how in the big middle checking thingy there are 8 function calls
for a for-each with 8 components
wonder why the checking is so slow
@amber flicker uhmm... that sucks... there goes my plan... thought about storing prefabs, icons, whatever in those adressables... and a system which gets triggered by a incoming packet is used to spawn in the certain prefabs by using that adress system
@stone osprey
You can still use them you just have to do it on the main thread without burst
@zenith wyvern You mean the adressables ? Or the system ? Can i somehow allow a system to run on the main thread ? Or disable burst completly ? Im just here for the data oriented part ๐
disabling burst is trivial.
you can do it project wide or for a specific system with .WithoutBurst( ) construct.
Yes. You can force jobs to run on the main thread and without burst, and you can even use monobehaviours in your queries if you use ConvertAndInject. So you can have something like
Entities.WithoutBurst().ForEach((Transform t, MyBehaviour b)=>
{
// Do something with all your MyBehaviours that also have a transform
}).Run();
you don't need specific version of unity to build Tiny๐ค
you just need windows 10 sdk if you are on windows ๐
Thanks ! Thats helpfull... so i could basically put all my junk into that adressable system... have one/several systems for spawning those adressables in...
ive allways had huge issues with unity builds
the fact that the build system is closed source so i cant see wtf failed is one of the main reasons
and you have to use new build system
Oh yeah... but i also have such problems without dots... especially android builds
those are doomed
at least in unreal when my build fails due to android being shit, i can debug it, and see exactly where does the manifest get wrong values or similar
Yup and in unity you just get a nonsense message... so you visit the forums, stackoverflow, page 5 on google and still havent found the cause
literally happened to me on a project
many tears where shed
at the end it was a dumbass store plugin causing conflicts
I fell that... happens everytime i do a major version upgrade, third party plugins are pretty awfull too...
the kind of thing that if you can debug the build, you can solve in about 10 minutes
you need to setup CI on unity
and basically never do engine upgrade
make sure the build is buildable from day 1 up to shipping date of the project
CI ? Was that git related ? Those automatic builds ? ^^
yeah - I wish I had CI - I had some issues with Unity build services ๐
alternatively, you can press that "build" button as a daily routine
with tiny build is alternative to play ๐
Only saw that on git, we had a lecture about CI, but we never were able to integrate it into gitlab... @vagrant surge But thanks, im gonna look into this ๐ sounds promising
you can just have a .bat of some sort that runs daily
by the way
public static class Globals{ public static NativeArray<float> A; public static NativeArray<float> B; } public struct TileID: IComponentData{ int id; } public struct AccessToA : IComponentData {} public struct AccessToB : IComponentData {} Entities.Foreach((ref AccessToA _, in AccessToB __, in WaterHeightsIndex id))
this is my approach from today at lunchtime :D
It does not seem to work, since unity does not care for tag components when scheduling jobs?
I.e. two different systems, both having ref AccessToA are scheduled at the same time
am I doing something wrong or is that intended behaviour?
You can't use mutable statics like that inside jobs
If it does work now I promise you it won't in the future
well it does work ๐
One more quick questions... is a component allowed to store a gameobject reference in dots ?
this is what I am doing all the time, just until now I did not need the AccessToX components, since the systems had other components that managed them not running in parallel
@stone osprey no - an ISCD does (wouldn't recommend for this since it splits chunks), or use a AddComponentObject from the EntityManager
now I have new systems that do not have overlapping components but write to the same position, so I thought the tag components would help me out
@stone osprey yes, its possible
just unfortunately unity seems to ignore them
What exactly is a ISCD ? ^^
but its a specific type of component
Isn't this exactly what SharedStatic is for
@zenith wyvern you can replace the nativearrays by sharedstatic if you want to (it actually is a sharedstatic by now), but that is not the point here
problem is that the systems are scheduled in parallel
So i am making a entity query to retrieve a singleton, and do SetChangedVersionFilter on that singleton to make sure my ForEach only runs when singleton value changes, but when i do ToComponentDataArrayAsync, that entity query runs even there is no change in the singleton but gives me array of length of 0 because there was no change, which makes whole idea useless, so should i simply go ToComponentDataArray and check if array length is above 0 or is there a better approach ?
ISharedComponentData` @stone osprey you'll need to implement IEquatable and override the GetHashCode() - im not sure if unity has made this a requirement yet 
What do you mean by It does not seem to work, what error is it giving you
I thought about a component for storing popups for a entity... each entity should have unique popups, we also need a reference to that prefab getting spawned
Yep - I know - that's why I wrote not recommended in my previous post haha
there is an actual component type that can point to gameobjects now
and to normal C# stuff
o
but you cant use it from jobs/burst
So we basically can store gameobject references in a component.... but not in that way? PopUpComponent : IComponent { public GameObject spawnInWhenClicked; }
@zenith wyvern was that for me? sorry I am loosing the overview here
It gives me the typical You are trying to schedule a job A while job B is still using that nativearray, please add dependency
in exactly that way
I can copy the message but unity just crashed, wait a second
Yes if you're accessing native arrays inside jobs you need to make sure whatever writes to your native array is included as a dependency for other readers/writers @junior fjord
Or always pass them with AsReadOnly
Managed IComponentData
It is helpful to use a managed IComponentData (that is, IComponentData declared using a class rather than struct) to help port existing code over to ECS in a piecemeal fashion, interoperate with managed data not suitable in ISharedComponentData, or to prototype a data layout.
These components are used the same way as value type IComponentData. However, ECS handles them internally in a much different (and slower) way. If you don't need managed component support, define UNITY_DISABLE_MANAGED_COMPONENTS in your application's Player Settings (menu: Edit > Project Settings > Player > Scripting Define Symbols) to prevent accidental usage.
Because managed IComponentData is a managed type, it has the following performance drawbacks compared to valuetype IComponentData:
It cannot be used with the Burst Compiler
It cannot be used in job structs
It cannot use Chunk memory
It requires garbage collection
@stone osprey @coarse turtle
Ah there we go - I was trying to find it in the change log - thanks
@vagrant surge Thanks ! So normal components can only use primitive datatypes or why exactly is a Managed IComponent required for storing Unity related stuff ? ^^ Thats a information that blog probably misses...
@zenith wyvern exactly, I wanted the dependency management to be automatically determined by using read/write access to the tag components
but unity ignores that
that is what I came here for
normal components have to be only very primitive structs, because they basically "ARE" C style stucts
to understand if that is on purpose
thats how burst handles them, and they get manually allocated on the chunks
for the C# runtime, normal components are invisible
managed components are basically normal C# stuff, with normal garbage collection, so they can point to other garbage collected stuff
Yeah I don't think you can do that, there's a hard restriction that if a job has write access to a NativeArray (accesses a nativearray without passing it as read-only) then any other jobs need to include that job as a dependency, or the write-job needs to manually be Complete()ed. If you want to stick with NativeArrays you can disable safety checks on the containers, assuming you know that no two jobs are writing to them at the same time @junior fjord
@vagrant surge Well that makes sense... thanks a lot ! ๐ The only question left is... are entitys possible with both normal primitive components and managed components attached ?
yes
Or use DynamicBuffers/BlobArrays/SharedStatic
its a suuuper recent thing
was only added like a month back
so it doesnt exist in tutorials nor anyone knows it even exists xD
Great, coming from a Entitas way of thinking this is totally normal... than i guess i need to move into the planning phase for the data layout ๐ @vagrant surge Thanks a lot for your help !
haha - that makes sense
@junior fjord yes I know that I have to have dependencies, that fully makes sense. I tried to reach that dependency by having the two systems have
Entities.Foreach((ref AccessToA a)) and Entities.Foreach((ref AccessToA a))
Normally, since both write to the same component, unity now would not schedule them at the same time and include one as a dependency of the other.
But it seems that in the case that AccessToA is a tag component (empty), unity does schedule them at the same time
while entitas actually works and its stable, even if much slower
was wondering when managed component objects were introduced...
also
entitas is faster
if you have low entity counts
due to not having all of this huge job system overheads everywhere
@junior fjord What do you mean it's scheduling them as the same time? The error is because of your nativearray, not because of the components
You can't just work around the dependency, you need to explicitly include the job handle from the job writing to the native array in any other job that accesses the native array
@zenith wyvern normally, if two jobs write to the same component, one is included as a dependency of the other. Therefore, they are scheduled to run one after the other
If the component they are writing to is a tag component, unity does not schedule them to run after each other
Havent implemented Entitas into my current project :/ Was using OOP before and hell, it almost ruined the whole project... the serverside uses Entitas so far. I guess i need to test both of them to determine whats stable enough for getting implemented ^^
Dont even know why they teached us OOP at university... great for small stuf, awfull for scalability
Dont even know why they teached us OOP at university... great for small stuf, awfull for scalability
@stone osprey it's being used in many parts of the tech industry, I learned FP first before I learned OOP - which made it easier for me to transition to DOD a few years ago
@zenith wyvern normally, if two jobs write to the same component, one is included as a dependency of the other. Therefore, they are scheduled to run one after the other
If the component they are writing to is a tag component, unity does not schedule them to run after each other
@junior fjord
Ohhh I see, I didn't know that actually. That's interesting. You mean this DID work if you weren't using tag components?
@zenith wyvern What I am saying is, if you have a component C, and SystemA and SystemB are both writing to C, they will be automatically dependent on each other (unity does that, right?) and I can safely write to the same nativearray from both systems, since I know they have the dependence.
Problem: If C is a tag component (empty component), unity does not do this dependency injection -> I have to do it manually
Entitas is pretty sweet, and you can write entitas in a similar way as you would use unity ECS (low add/remove comps, and not too much spam of reactive systems). This would make it fairly easy to adapt later
yes exactly @zenith wyvern
i honestly dont expect unity ECS to get close to entitas usability this year
I guess since Unity knows you can't be writing to anything inside a tag component it can safely schedule them in parallel, neat
haha no not neat at all for me ๐
I mean what other reason is there to declare write access to a tag component if it is not dependency management
this would be a very nice usecase for tag components if they would just treat them as normal
I guess that's just not how they're intended to be used, to be honest I would be very very confused if I was trying to figure out what was happening in your code if you didn't explain that to me
but right now I have another weird error, maybe I should first get rid of that
I thought this would be more elegant than always having to manually copy the dependencies between all systems that write to the same nativerrays
By it's very nature what you're trying to do is a workaround so I guess that's expected
You are trying to schedule a job A while job B is still using that nativearray, please add dependency
this was just saying you were not inputting your first job into the job input for the second that used the same array
yeah but we had a few very long discussions about the intended way here today and yesterday and either I missunderstood it, or the alternatives all have their problems to
You are trying to schedule a job A while job B is still using that nativearray, please add dependency
this was just saying you were not inputting your first job into the job input for the second that used the same array
@low tangle I understand the message
alright
it is about why this happens
I would personally lean towards dynamic buffers. But from what I understand there's no simple way to pass a dynamic buffer from one entity into a job for another entity without causing a sync point or without having to copy the buffer first for every job
since both systems write to the same component, it should not happen
they should be automatically dependency injected
two jobs, writing to the same component are scheduled at the same time?
@zenith wyvern yeah that is what I understood in an earlier discussion too. The nicest way would be a singleton entity but it seems to be kind of complicated to understand what happens if you want to include the buffers of that entity in a job
@junior fjord unity does not manage NativeArray dependencies between systems๐
yes but component dependencies
that is why I have bo Entities.Foreach((ref AccessToA _)) in both systems, I hoped unity would see that both systems write to the same component and do it for me. But it seems that if AccessToA is empty, unity does not do that
it does check that actually
ok, wait then let me get rid of the disposal messages before and hope that the error message was just some weird follow up ๐
that would make me very happy
from docsNote that the system Dependency property does not track the dependencies that a job might have on data passed through NativeArrays or other similar containers. If you write a NativeArray in one job, and read that array in another, you must manually add the JobHandle of the first job as a dependency of the second (typically by using JobHandle.CombineDependencies).
yeah I get that I would have to do it manually, I am trying to trick unity into doing it automatically for me by using tag components, thats the point
Entity _bufferEntity;
protected override void OnStartRunning()
{
base.OnStartRunning();
_bufferEntity = GetSingletonEntity<BufferType>();
}
protected override void OnUpdate()
{
var bufferEntity = _bufferEntity;
var bfe = GetBufferFromEntity<BufferType>();
Entities.ForEach((...)=>
{
var buffer = bfe[bufferEntity];
}).Schedule();
}
What about something like that
then all I have to do if I read/write from array A is to read/write include the AccessToA tag component
@junior fjord you can't trick it with components
unity treats native arrays and components separately
It should work in general, all my systems before access the same nativearrays but have no explicit dependency management from my side. They only have the dependency managament that unity did from the components which is enough before
its just a new situation that I have to systems that do write to the same array and do not share any component
@warped trail He was already tricking it with components. But now he is trying it with tag components and it doesn't work, is what he is saying
It doesn't work because Unity doesn't care if you have write access to tag components basically
well it seems that it should work, if June is right, I have to get rid of all other errors first and then I'll come back and report
But I think unity only checks if there is a dependence between the systems if they write to the same nativearray, not if the dependence is explicitely set by the user or automatically by unity due to components
I really wish I understood what the hell you were trying to do
because it sounds very not in line with how this framework works
to look at it a different way
He wants global mutable shared static data
automatic dependency management is another way you could call GC
and GC is what were trying to avoid, automatic memory management is what were giving up
global:sure
shared:sure
static:sure
mutable:nope
maybe your jobs was in same systems, thats why it worked before?๐
no, all different systems
I have basically 8-9 systems for the simulation of the water flow, most of them accessing at least the water heights array
because no matter the components write access you should end up in error, if your jobs access same native array without explicit dependencies๐ค
make it persistent allocated arrays in a static global class, or use a blob asset and use blob asset refs to get at it
or use that new wonky sharedstatic system with bad syntax
I would think if your systems are dependent based on component access then unity is just passing the job handle to the dependent system under the hood, so it would be no different than doing it manually
or use a dynamicbuffer on a entity
I think it's not a good idea in any way, but I don't see why it wouldn't work
personally I just default for the most general purpose tool keeping my data as close to entities as possible. idea is to minimize the amount of translation I need to do too and fro entities
@zenith wyvern but you are the one who posted example that this thing is not working๐ค
In my example my two systems did not have write access to the same component so there was no internal dependency
Ok, what I am doing
I have a 2d map of hexagon tiles. This is a simulation-heavy game, right now I am simulating waterflow and ground humidity. There are a lot of properties, that each tile has, e.g. waterheight, humidity, water velocity, ....
Approaches to do this
(1) Each Tile is an entity, with WaterHeight, Humidity, .... component. But the tiles often need to lookup their neighbors -> a lot of GetComponentData calls (this is what I did at the beginning). Also here I have to work tricks, if I want a tile and its neighbors to be in the same chunk (if they are not even in the same chunk, then the neighborhood lookup is even more expensive)
(2) Entities for chunks of tiles. Now Each entity has dynamicBuffers for WaterHeight, Humidity, .... Still, the tiles on the border of one chunk, will need to lookup the neighboring chunks -> I always have to check if a tile is currently on the border, maybe get neighboring tiles etc. A lot of branching in the code and lookups again
(3) WaterHeights and Humidities are saved in arrays, the entities just have indices into that array. Now I can make sure, that the arrays are layed out in a way, that data of nearby tiles is nearby in the array, I have no calls to GetComponentDataFromEntity etc.. All entities also have an dynamic buffer of its neighbor ids and can therefore look them up quickly
I started with 1 and then went to 3
I'm basically doing 2 in my voxel thing I made
its always the voxel/minecraft/tile chunk problem people do
swear its the first thing everyone does
haha no this is not the first thing I do unfortunately ๐
I jump onto a new idea every few months
but I think chunks are pretty common in big simulated worlds
2 works very well
yes you are going to want to group your hot data at some granularity into the same """"chunk""". yes your border data is going to be slow to find. precaching that data is a good idea. just taking the hit is also fine. profiling is also a good idea for each type
but as I have it now, I have to never check for the border, so no branching at all from bordering and no complicated find my neighborhood data stuff
Hey, can someone explain to me why the PhysicsVelocity keeps updating even when a Cube(with dynamic Physics Body) just sits on a plane? Shouln't the physics Velocity be still and not change unless something applies force?
I actually like most of it very much in how it works, just the dependency management could be tiring if I don't get unity to do it automatically
In my opinion the workarounds you're having to do to keep your data in native arrays is not worth it. You're working hard against the framework
@formal scaffold because this is how unity physics works ๐
IMO you should just use dynamic buffers. Yes it's annoying to have to access neighbours but I feel like it's more line with how things are supposed to work in ECS
To me anyways
well I'll use the framework more for the non-simulation stuff. But for the simulation stuff (I want to simulate the whole world), I think it is worth it that I can pick my own data layout in the arrays
and have no border cases (!)
I mean I basically just do
waterHeight = waterHeights[tileID]
instead of having waterHeights directly accessible
yes, you should be packing your own arrays if you feel that a: it will be easier to write or b: you know from profiling that it will be too slow otherwise
@formal scaffold unityphysics is stateless by design so i'm guessing it is doing a calc for gravity pushing it down and then the collision bringing it back up every frame having a slightly different result every frame
also it has no concept of sleep like physx does, you could add this yourself tho
I wrote a minecraft chunk and mesh generator in ecs in two hours the other night, it used one entity for holding the voxel data
another for holding the mesh arrays of verts etc
But dynamic buffers are arrays. And unity will handle the dependencies for you, which is the issue you're having right now
border lookup was just done in the slow way
and guess what, the unity mesh creation (using the new api) was still slower than generating the data in the first place
I found the same thing, mesh uploading was by far the slowest part
yeah but I don't do it only because of performance, but also because I don't want to do if(x == 0 || x == chunkWidth || y = 0 || y = chunkHeight) all over the place
ok my or statement was made spoiler safe to make it more interesting ๐
what could I be checking there?
You can alleviate a lot of that with static functions
and I am doing simulation of flowing water which is pretty expensive I think and I want to be able to do it on a as large map as possible
But yes there's no getting around it neighbour checks are very annoying
in cpp i use fun stuf like iterate_neighbours functions that take a lambda
You could always embed the edge data in each chunk. I was thinking about doing that but I hurt my brain too much trying to figure out if it would be better than just using random access
yeah I think getting around all edge data is worth the bit of effort I am getting due to handling dependence when writing to a handful of arrays
but yeah I am no professional and I don't get the games done I start normally so theres that ๐
Wierd ๐ง I have a Prefab selected in the inspector, press Play mode and watch the Editor Loop. Mine takes 20+ ms just for rendering the Inspector tab ๐ I just read a forum entry where one from Unity points to "something in your project that triggers some infinite repaints of some editor windows"
Does anyone know how I can locate those? Is this even DOTS related?
does anyone know why this gives me
public abstract class HumidityData
{
public static readonly SharedStatic<NativeArray<float>> humiditiesStatic = SharedStatic<NativeArray<float>>.GetOrCreate<HumidityData, HumidityValues>();
private class HumidityValues {}
public static void Initialize(int2 widthHeight)
{
humiditiesStatic.Data = new NativeArray<float>(30*30, Allocator.Persistent, NativeArrayOptions.ClearMemory);
}
public static void Dispose()
{
humiditiesStatic.Data.Dispose();
}
}
a memory leak message? Short after I start the game (I call Instantiate), unity notifies me that a nativearray has not been disposed which was allocated from instantiate
I am trying to switch from nativearray to sharedstatic ๐
Hey gents and not gents: a SystemBase Foreach is now translated in to a Job right? ParalleJob per chunk if I got it right. Is a Foreach inside a Foreach still a parallel job with the second Foreach becoming a normal foreach?
@junior fjord why doing a static array out of curiosity? It's possible to share arrays inside systems without being static
@scarlet inlet i was looking into it today, depends if you do Run or not
its allways done into a job
Why the GameObject gets converted in the entity without the mesh renderer (it becomes invisible)?
I have the packages: Entities, Burst, Jobs, Hybrid Renderer
but how that job runs and what type of job it is depends on how its launched
with Run, its main-thread, and it just does a for loop over the chunks
with Schedule it puts that job into the workers
with ScheduleParallel it does parallel for
what kind of job?
but need to check scheduleparallel
and a foreach inside a foreach?
@junior fjord the way they detect leaks is by putting a DisposeSentinel inside collections like NativeArray. They keep track of all the sentinels that were created. If they go through them and a sentinel hasn't been disposed, then throws a leak exception. What's probably happening is that there is no class holding a reference to your NativeArray, so GC comes along and thinks the class reference to its Sentinel should be disposed, and gobbles it up.
on that one i have no idea whatsoever
I can think only of the second foreach becoming a normal foreach inside a job
it must have been pretty complex to solve all these combinations
its more than just normal foreaches or not, there is a lot of cehcking on the job system
even the .Run does a lot of checking to make sure that there isnt a job on the workers editing the same components
@junior fjord why doing a static array out of curiosity? It's possible to share arrays inside systems without being static
@scarlet inlet just was the quickest way to do it with the least boilerplate when accessing it, dunno
@junior fjord in hindsight it wasn't ๐
what alternative do you have in mind?
my first choice is always to create entities
second choice could be dynamicbuffer or injecting nativearrays by constructor in the system
but I have multple systems using the nativearrays
@mint iron you mean since the HumiditiesData is an abstract class?
yes I would inject in all of them, however I understand why it may not seem a good idea to you, it's because Unity still let things to be created automatically
so I should save that nativearray somewhere else and then just set it into the sharedstatic?
which seems like a time saver, but instead hides possible patterns, like injecting data via constructor
what do you mean by injection?
just getting them from somewhere in the constructor and setting a membervariable to it?
well I don't wan to confuse you, but my Systems are always marked as [DisableAutoCreation]
this because I create them manually, which means I can call the constructor, which means I can inject data
however your first choice of data should always be the entities
so all your systems would have member variables pointing to the same nativearray?
if this is what you want, yes
but again I would prefer reaching the data through entities
I wouldn't use static for this
Ok, what I am doing
I have a 2d map of hexagon tiles. This is a simulation-heavy game, right now I am simulating waterflow and ground humidity. There are a lot of properties, that each tile has, e.g. waterheight, humidity, water velocity, ....Approaches to do this
(1) Each Tile is an entity, with WaterHeight, Humidity, .... component. But the tiles often need to lookup their neighbors -> a lot of GetComponentData calls (this is what I did at the beginning). Also here I have to work tricks, if I want a tile and its neighbors to be in the same chunk (if they are not even in the same chunk, then the neighborhood lookup is even more expensive)
(2) Entities for chunks of tiles. Now Each entity has dynamicBuffers for WaterHeight, Humidity, .... Still, the tiles on the border of one chunk, will need to lookup the neighboring chunks -> I always have to check if a tile is currently on the border, maybe get neighboring tiles etc. A lot of branching in the code and lookups again
(3) WaterHeights and Humidities are saved in arrays, the entities just have indices into that array. Now I can make sure, that the arrays are layed out in a way, that data of nearby tiles is nearby in the array, I have no calls to GetComponentDataFromEntity etc.. All entities also have an dynamic buffer of its neighbor ids and can therefore look them up quicklyI started with 1 and then went to 3
@scarlet inlet this is my kind of lengthy explanation of why I don't have them on entities from before
it is not to much boilerplate and I never have to check if a tile is on the border, which I would have to do nearly always in other cases
through two things, their coorindates int2 and their tileID int. The cool thing is that I can also choose the tileIDs (and therefore in some sense the data layout) myself, and can use a nice spacefilling curve instead of the default y*width + x
so the neighboring tiles will be rather close in the array too most of the time
but the main thing was that I did not want the border checks all the time and it actually works to circumvent them fully this way
I mean, my guess is that UECS guys created all the native data structures (also) as workaround to the prolbme that you cannot query an entity other than with the ID provided by unity itself
so while it looks quite ugly, why not create a singleton entity or whatever UECS calls it, to hold your native array?
๐
yeah but GetComponentDataFromEntity is also rather slow from what I heard. basically if I could do two things, my solution would not be needed:
- I would need to be able to set which entity goes to which chunk and in which order (so nearby tile entities would be close, I could choose my own spacefilling curve this way)
- GetComponentData to be as fast as an array lookup, which it isn't from what I've heard
no I didn't mean using GetComponentData
and we had the global entity buffer discussion like twice today already ๐ this was my most unproductive day in a long time I think ๐
I was literally saying why not query a singleton entity that holds your native array instead to use a static array?
the problem is, that if I do
var e = GetSingletonEntity<WaterHeights>();
var buf = GetBufferFromEntity<WaterHeights>(e);
Entities.Foreach(){use buf}
it does not seem to be clear, if the buf thing creates a sync point and in which sense the dependence of WaterHeights is actually added to the scheduled job
WaterHeights is a component right? cannot you do e.array where array is a antive array?
sorry I am not 100% used to UECS
I mean I don't use it for this stuff
no, components cannot hold array references
you'd need an unsafe array - so what native array is built on top of
cannot hold native arrays?!
those can be stuck onto components
hmm ok I thought they could, but ok as @coarse turtle was saying that are many arrays ๐
there is UnsafeList too
that can grow
^ that too
nothing new here tho
just confirming that hybrid renderer v1 is not going supported properly
@junior fjord would that work?
what? putting some kind of unsafe pointer into a component?
I mean yeah I could do stuff like that but I don't think that is nicer than doing what I am doing
well it has an interface not too much dissimilar to nativearray
is that native array read only?
some are, some are not, I have a handful ๐
static means you cannot make them thread safe too
so careful in using them inside jobs
it's quite a pickle this case though
I really don't like the framework forcing you to find these solutions
also seems quite a common scenario
I actually don't think the solution is so bad, its just a bit to much boilerplate ๐
in an ECS scenario, forcing you to access an array through a static class, is a terrible solution, in the sense that it doesn't scale well
however for simple case scenario ok, it was the same thing pre-ecs after all
the normal thing is that ecs have native support for singletons, and you use them for this sort of thing
better than the current singletons who cant have native arrays and similar inside
yeah I guess if you tell to the guy who designed the current ForEach to be super thread safe when using components, that you are putting in the code a global accessible native array, that can be caught by those foreach, he would just start to question all his decision in life ๐
If they wouldn't plan to remove support for SharedComponents having NativeArrays that would also be fine
well you just have to plan yourself s.t. the jobs that write to a nativearray don't run in parallel
I know but that's why it doesn't scale well as solution in larger teams
too many conditions/guidelines to remember
the for-each being hypersafe kinda makes sense
after all its the noob-friendly automaticjob thing
yes but it's so friendly that it can catch that static native array
and boom
at least the JobDebugger helps!
@low tangle I now tested it fully. When I have something in my AccessArray component (e.g. some int), then it will manage the jobs to not run in parallel and does not give a warning about the jobs writing to the same position. As soon as I remove the content, I get all the warnings
so yes, Unity ignores tag components for scheduling
that is pretty sad
would have been the ideal solution and no idea why they would do that
scheduling based on tag components sounds like a bad idea? Can you use [UpdateAfter], [UpdateInGroup] etc instead?
Any way to see local variables inside ForEach while debugging? The debugger won't tell me and I'm left with writing Debug.Log which is tedious, Sorry found it*
Yes thats the plan, why not a byte?
The Rider Debugger Shows them @formal scaffold
But it does not do data breakpoints
mmm never seen this error message before... good to know.
ArgumentException: DestroyEntity(EntityQuery query) is destroying entity Entity(55:1) which contains a LinkedEntityGroup and the entity Entity(93:1) in that group is not included in the query. If you want to destroy entities using a query all linked entities must be contained in the query..
thats pretty annoying, i dont know how to resolve it except put the parents tag component also on the children, or iterate the children manually. LIke... isnt that the point of having LinkedEntityGroup, that these things can happen automatically?
@mint iron I ran into that too, yeah it's pretty stupid. Not sure what the point of LinkedEntityGroup is given the restriction
Another fun related problem i encountered is if you have a prefab with children, who aren't setup with their own shapes/bodies, then they aren't instantiated with their parent... even though they're part of a LinkedEntityGroup. You have to manually assign the children with a prefab tag. ๐ข
id open that up to the forums, that restriction seems ridiculous
so im talking with one AAA dev who is using a unity style ecs but in unreal, and he has some interesting stuff
oh yeah my child array I have to delete manually, that is until I shifted to a systemstate pointing at a separate entity which was the list. I only use that for auto cleanup
he is lately adding polymorphism by storing function pointers in components
for some very specific things
in a way, its like oop, but fully dynamic, as the functions and the data can be changed at will
node graph
just because you can do it
as in blueprint/visual editor
ah
the concept looks interesting. The function pointers are all the form of (entityID "this", other data)
the component that holds the function pointer holds no data, the data is grabbed by grabbing components from the entity id
obviously slow as its reinventing virtuals, in a way, but for things like state machines or AI seems legit
makes sense
for state machines you can just swap the function pointers depending on state
yep
and if you made those function pointers a "shared component", then iteration is contiguous, so you dont get the normal penalties from virtual dispatch
Hello, is there a way to quickly get an array of components/components value? For instance if I want to do something with all positions of all entities that have components position&others
query.ToComponentDataArray<T>()
query.ToComponentDataArrayAsync<T>(JobHandle, Allocator) <- I think that's the API
that might work for your needs
mmm, you could do something similar by reinterpreting a struct inside a component as different things that contain methods. Its a different struct so magically a different function is called. And if you want, stash any params you need in the component.
its more or less equivalent to have a "enum type" on the component
and then switching to the actual implementation
but obviously, more elegant and less centralized
i think physics guys doing something similar with colliders, aren't they?๐ค
Thank you. It feels a bit weird that there is ForEach but not the full functional programming suite of Map, Reduce, etc. as they are common tool for easy-to-parallelize tasks.
im talking about unity physics and their blobassetreference<collider>๐
his use case was pretty interesting. He did it to get the info for the input and output of the nodes
so basically a "get input" and "get output" on the graph editor nodes
the actual data of those nodes is just implemented as other components for most of the stuff
so maybe its closer to, storing the ptr to another component on another entity, and then calling an interface function on it.
no, this interfaces are called with self
and called from ecs systems
its not really messaging around like typical oop does, its more to just allow some virtuals but without most of the normal drawbacks
the component data is still all stored contiguosly and stuff
the fun part is that this interfaces will likely be constant on the same archetype
so its still all very contigous in memory and consistent
So, tomorrow i am going to try to make quest/mission system, any ideas ? ๐ค
@opaque ledge are the quests linear, branching?
If they're linear you can probably have a linear fsm similar to what @vagrant surge was stating with components with a function ptr or what @mint iron was stating with reinterpreting the struct and when the condition is finished you call the function ptr which updates an index and allows you to jump around collection of 'quests'
I imagine with a graph/tree you can likely create a tree like array and do the same
Just from the top of my head - I've no idea how you want to design your quests ๐
how do we use ICustomBootstrap ?
the definition from docs here :
and acutal code doesnt exactly mathc
am i missing something?
entities 0.8.
check the URL above , its the manual from same version.
its 0.8 , not 0.3
i mean the manual , sorry
scripting API doc is same for 0.3 and 0.8
what exactly do you want to do?๐ค
The API doc hasn't changed much yeah, sorry
i want to create a world manually then populate it with systems manually as well
to better understand the setup instead of going with default world and system initialization
the Scripting API doc matches with code found in package , obviously because its auto generated. the Manual is saying something different
how come i am seeing 2 different declaration of ICustomBootsrap?
vs
{
// Returns the systems which should be handled by the default bootstrap process.
// If null is returned the default world will not be created at all.
// Empty list creates default world and entrypoints
List<Type> Initialize(List<Type> systems);
} ```
/// When entering playmode or the game starts in the Player a default world is created.
/// Sometimes you need multiple worlds to be setup when the game starts or perform some
/// custom world initialization. This lets you override the bootstrap of game code world creation.
/// </summary>
public interface ICustomBootstrap
{
// Returns true if the bootstrap has performed initialization.
// Returns false if default world initialization should be performed.
bool Initialize(string defaultWorldName);
}```
class MyCustomBootStrap : ICustomBootstrap
{
public bool Initialize(string defaultWorldName)
{
Debug.Log("Executing bootstrap");
var world = new World("Custom world");
World.DefaultGameObjectInjectionWorld = world;
var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
return true;
}
}```
1st is from 0.8 manual , 2nd is from package
that means Manual doc is not updated ?
seems like it
argh , this makes things harder
auto generated Scripting API doc doesnt help either
anyways , thanks. that does help.
changelog is the new manual i suppose
i guess you can create world and systems without hooking them to unity's default update loop
but you will not see them in entity debugger ๐
you can create world and systems without hooking them to unity's default update loop super useful for writing tests.
entity debugger is also throwing all kinds of nativearray and rendertexture memory leak exceptions on script recompile! ๐
I'm stumped, Does anyone know why this would not work?
Entities
.ForEach((ref Rotation rotation, in PlayerControl playerControl) =>
{
if (!playerControl.Value)
{
return;
}
if (pitch > 0)
{
rotation.Value = math.mul(
math.normalize(rotation.Value),
quaternion.AxisAngle(math.up(), 50f * deltaTime)
);
}
})
.Schedule();
If i try and apply pitch my rotation is set to NaN and the test cube I'm working on vanishes. I logged the value of math.normalize(rotation.Value) on load and that returns NaN but just logging rotation.Value.ToString() returns the expected quaternion containing 0f
given normalizesafe a try?
I hate my life
I couldn't find it in the docs and the only reference i found to the issue was someone saying to use math.safeNormalize
Thank you
I must be looking at the wrong documentation as I still can't see it even knowing its real name.
Published my events system and an example if anyone's interested https://github.com/jeffvella/UnityEcsEvents.Example
Cool, I'll have to have a look
How complete would be dots netcode as of now?
anyone who has used it for a game?
you can certainly build games with it, but I'm sure it will improve with time
but I'd say its rather advanced/complex to use still
I tried a week back I think and the copy pasted code from the documentation site even had errors ๐
but I'd say its rather advanced/complex to use still
Yea..
yeah it is funny that they don't fix Getting Started code ๐
It's a test ๐
I'm trying to get subscenes working - I had a scene with a bunch of debug cubes with rigidbodies/colliders that worked all nicely, however if they're moved to a subscene they become completely passthrough and no longer fall
can you even use "regular" physics and monobehaviours with subscenes or does it require you to go all-in on ecs?
it should be the latter - since they're live converted to its entity formats (I'm sure that the MonoBehaviour components will not carry over and are stripped)
Is there a way to download the "Entities" package from a website ? My package manager is buged... it only shows me v. 0.0.12 and i cant even download that one due to a error
That really shouldn't happen. Try closing your project, delete the Library folder and reopen it, see if that fixes it
You might also be able to just manually edit the package.json file
manifest.json*
I regenerated the libs 2 days ago... they are "completly" new :/ where do find that manifest.json ?
YourProject/Packages/manifest.json
Alright thanks, just added com.unity.entities@0.8 by myself... the editor is working on something... excited for the result
Damn... he tells me that it cant connect to "staging-packages.unity.com", havent a firewall up and also no proxy... i can load other packets easily
Whats your registry in the manifest.json ?
what editor version are you using?
2019.3.7f
That website in the registry does not exist... theres no https://staging-packages.unity.com
https://packages.unity.com/com.unity.entities What does this show you?
A huge json file
Okay, so your package manager might be trying to connect to an old URL
Oh wait... proberly if we remove the "staging"...
Not sure where to fix it, but I'd bet to just delete the whole Library folder again
Also, does your manifest.json have a registry specified?
@bright sentinel "staging-packet.unity.com"... i removed the staging part due to the url you posted above... im gonna look what happens ๐
@glad condor I've been trying to learn to use Unity.NetCode for a few weeks now. I feel like I'm starting to understand it. I'm pretty sure the example in the docs (https://docs.unity3d.com/Packages/com.unity.netcode@0.0/manual/getting-started.html) is taken from this project https://github.com/Unity-Technologies/multiplayer/tree/master/sampleproject/Assets/Samples/NetCube, if you're looking for a version that actually runs.
@stone osprey Not sure why it would have that in the first place? But that's probably why
@thorny vault have you figured out how to use CurrentSimulatedPosition and CurrentSimulatedRotation for interpolation?๐ค
Thereeee we gooo ๐ Thanks a lot ! Its working now... would have taken years to figure this out without that url above @bright sentinel thanks !
@stone osprey Yeah, you shouldn't have to change the registry unless you're running some very custom package solution
I actually didnt changed it, but i migrated from 2018 to 2019, that probably broke the package manager ^^
Maybe, but even then, staging was the old way of doing preview stuff
So maybe you did it in the past
ยฏ_(ใ)_/ยฏ
Really strange :/
@warped trail I haven't looked at it yet. I have a client and server connected and passing RPCs. Hoping to get into ghosts more sometime this week.
Are there any examples of RPCs? The docs are... Lacking
Is it possible to directly store a reference in one entity to another? Or rather, is it right to?
I'm setting up a simple camera follow system and want to be able to change what the camera is following (or setup multiple camera following different entities).
@loud matrix Yes, that's a decent solution. Components can store Entity references that you can then use GetComponent<T>(Entity) to get the specific component
E.g. translation
You could also invert the concept, and have a system that queries the object you want to follow, which sets a component for the camera to grab direectly
'getting-started.html' does cover them. The way they work seems to be:
- On the client side, you create an entity and attach your RPC to it as a component
- A system on the client side deletes it and replicates it on the server side
- A system on the server side matches on the RPC, acts on it, and deletes it
I guess its a little less RPC and a little more 'just sending a message'.
The question is just where you read and write
@thorny vault Well they do, but not in great depth, and there isn't really an example
I just wanted to know whether there are any examples that uses them
GoInGameRequest is an example๐ค
Oh really?
inherits from IRpcCommand
Oh
๐คฆโโ๏ธ
That's what I get for blindly following the tutorial without thinking about it
blindly following the tutorial will get you an error ๐
Ah yeah, I at least fixed that
Oh well... so i just installed entities 0.8.0, updated the other required packages... and the editor shows me about 199 errors in all kind of folders
is it possible to access a chunk component in Entities.ForEach ?
Oh well... so i just installed entities 0.8.0, updated the other required packages... and the editor shows me about 199 errors in all kind of folders
@stone osprey i was going through this hell like a day back. what helped me was downgrading to collections 0.6 from latest 0.7
then restarting the editor and , letting everything compile then upgrade back to latest
its weirds as hell but that worked for me.
"Note: Currently, you cannot pass chunk components to the Entities.ForEach lambda function."
Thanks @naive parrot similar exceptions ? https://prnt.sc/rvivwq
so the option is to use IJobChunk and iterate over each enitity ? @bright sentinel
@naive parrot Probably yea
@stone osprey Those looks like you have some dependency problems. First check the package manager to see if there are any errors in resolving. After that, delete the PackageCache to make sure they get updated
@stone osprey lots of things went haywire for me. multiple inbuilt packages had gone missing due to compile errors. looks similar to what i had , not exact though
someone had mentioned the order in which packages are installed matters. this leads lots of dependency based issues i think
entitites package has tons of dependencies
and is most susceptible to this order based issue
make sure you have the latest burst and collections, they werent listed properly on the 0.8 dependencies, but you need to upgrade them.
Thanks ! Im gonna try to delete the cache first :/ if that does not help, im gonna try that downgrade
this seems to common now moving from 2018 to 2019 and using entities package ๐ค
got 199 problems but the cache aint one.
collection downgrade to 0.5.2 brought me back to 196 errors
@bright sentinel I think this is the minimum code you need to send a single int as an RPC: https://pastebin.com/JVqRSUyr.
@stone osprey are you using vscode ?
Ah, thanks @thorny vault
Nope, editor shows me those 196 errors in the entities 0.8.0 version due to the dependencies :/
Nope, im not using this, why ?
So where the hell does IVisitAdapter come from ? That damn interface is causing 50 errors on its own
i just downgraded the collections... damn, thats a real dependency hell... 0.8.0 has real struggles
Platforms downgrade brought me down to 19 left errors
can't they just release small fix?๐ค
No idea... gonna update collections now to 0.7
4 left errors
NativeList, CollectionHelper are missing
3 errors on version 0.6
UnsafeHashMap is missing
and NativeHashMap
or is it like, this package is in preview anyway, so who cares about user experience? ๐
hi everyone, i am wondering, is dot will give us the ability to have better graphics in our games (higher polycounts for 3d models, higher textures resolution etc ) or it is mostly more effective with a huge count of entities ?
0.7 preview 2 on collection works
now theres other stuff missing
CompilerServices
@naive parrot Thanks ! Wait... gonna try that out ๐
Perfect, that worked ๐
two errors left xD but not from burst
Anyone here knows why it tells me that "SceneSystem" is missing stuff ? Thats one error
And bootstrapfilepath is the other error
@fallow zealot DOTS will let you right CPU friendly code but its not a magic pill solution for better gfx out of the box. its upto you as developer to manager the resources efficiently on your target platforms and make the most out of it.
@fallow zealot it'll not let you fix any of the things that are already gpu bound
so no, you can't render higher poly meshes with help of DOTS
DOTS is about scalability. hence most of its showcase is usually about tons of identical entities. but it has more passive advantages like lower power consumption , better thermal efficieny on mobile devices , when utilized correctly. @fallow zealot
@naive parrot thank you for the answer. I mean i know that, but what is your thoughts about that, do you think, someone with enought skill and using DOTS can have better performance than an other one using monobehaviour ? When it will be released of course
on the graphics side
easiest use case where you can see the difference is some brute force simulation
but most games we see today don't really care much either way
I guess doing large streaming worlds will get easier with DOTS eventually
fair enough. So it is mostly for that
its a subjective thing. with right effort you can achieve performant results even without DOTS. DOD ( Data Oriented Design ) is what drives DOTS technologies. GPU/Shader pipelines are purely data driven , data oriented. you can achieve same or better performance or scalability for a classical simulation even today using compute shaders for eg.
GPU excels at DOD by default. DOTS lets u aim for that level of efficieny on CPU
very clear opinion you give me, and i understand better now
and we actually don't exactly the ffuture of it i think, it will depend on Unity adding the right tools for that and developpers to use it properly
Sooo... i heard that modifications in the package code are getting reverted each editor restart ? Anything to make sure that modifications of that package code doesnt reset ?
out of the box if DOTS brings us Culling ( Frustum , Occlusion ) and LOD calculation today , then sure i think by default we might get 'better' GFX for CPU based rendering task. @fallow zealot i am not fully aware if DOTS based culling & lods are here yet. @dull copper might know better about up and coming stuff ๐
@stone osprey if you want to edit a package you have to copy it into the /packages/ folder, Unity wil then detect its in 'edit mode' and it starts showing up in your VS solution, and is flagged as such int he package manager (and it deletes the package copy from the library)
occlusion culling support is coming to Hybrid Renderer v2 afaik
but I wouldn't expect it to dramatically change things here
yea thats what i was wondering. hybrid renderer..
@naive parrot next gen consoles wont do culling and lods on cpu
but on gpu
(for some cases)
like batching but on crack, with culling
GPU Instancer on asset store does this i think. Culling on GPU
you mean those mesh shaders now?
RTX intensifies.
I loved the culling samples they showed on DX12 ultimate stream
thats something ive done myself
could cull stuff by vertices basically
on opengl
never render anything extra
indeed
but its not generally worth it to cull by verts
the guy himself talks that at absolute best you would just be at same speed as th hardware
unless you are doing fancy things of course
@naive parrot much stronger than that
i see
@naive parrot usually those techniques need dual-dispatch
so one shader does the culling, and then cpu reads results a couple frames later
or one shader does the culling, and then you use draw-indirect to do it on the same frame (harder, cpu cant see it)
mesh shaders are about doing culling with normal drawcalls
instead of having a vertex shader, you have a mesh shader, which is a compute shader that can emit triangles
so you can do your cull test there, and just "not emit" triangles
Is there a way to pass a NativeContainer to an Entities.ForEach job?
you can also select which mesh you output by distance (lod)
im going to assume the answer is "no" based on what i've seen first-hand, but does the Hybrid Renderer (v1) support Texture2DArrays in a Shader Graph?
can we do mesh shaders in unity ?
vertex shaders? yes
no mesh shaders
no, you cant
oh it's new tech. gotcha
also not in unreal
but both of them likely already have them, on their top-secret forks where porting to next gen consoles happens
kind of expected i must say. if unity/unreal arent keeping up with bleeding edge gfx tech then who will ๐
Is there a way to pass a NativeContainer to an Entities.ForEach job?
@obtuse swallow
You just assign it to a local variable before the job and pass the local variable in
the ones who makes exclusives for Microsoft and Sony ๐
can't wait for another season of fake gameplay trailers for new generation of consoles๐
the new generation is stronger than 99% of gaming pcs
by steam hardware survey
to that, add the "good ol console optimization"
PCs are kinda left in the dust for a year or two until we overtake consoles as usual
as an example, at the moment its literally impossible to get the level of disk speed (ssd) that consoles have, on PC
the only way to reach such speeds is on custom build datacenter tier hardware
gpus are about 2070-2080 RTX level
cpu is basically a underclocked 8-core ryzen
why do you think stuff like blob assets and subscenes are being developed
Need one more time your help... I fixed that SceneSystem error and now im getting 81 more errors because SampleGroupDefinition wasnt found in Performance package... any idea what version fixes this ?
the new generation has such stupid fast SSD that if you have to process the loaded data, you will bottleneck on cpu
@vagrant surge there is also apparent shift from offline baked "static" data like lightmaps , navmesh etc. Joacim has mentioned along these lines on forum. everything is going closer to full realtime. i watched HZD GDC talks about procedural placement tech. entire terrain is literally populated on runtime. i think loading times have been serious issue on current gen. even Insomniac one of the GDC talk on spiderman mentions about moving away from disk stored data and calcuating lots of the stuff on the fly
the thing with HZD procedural placement, is that its such a huge amount of data that you cant do it static
https://prnt.sc/rvk199 Thats the last error i have with adding the dots packages... any idea ?
its just too much grass
the space taken by that would be really huge
thats a weakness unreal engine has, it actually does store the vegetation instances (except little grass, which is procedural)
vegetation studio pro has been great solution to this. its basically the proecdural placement tech from HZD
its not really that hard to implement
and allows for both runtime and baked instances
ive thought of making a cpu based impl myself
yea its quite straightforward. but to have fullblown solution what all major minor requirements as small team is sure resource intensive
btw, mesh shaders make this sort of stuff even more powerful
because you can do the placement and the rendering at once from the same shaders, bypassing a lot of temporal memory
did you give it a go already?
yes
but that was mostly my mesh shader experiments to begin with
spamming a lot of rng gpu generated stuff, and rendering it, at once
i have been going through nvidia pages myself
but opengl mesh shaders, while they are very easy to use (vs the bullshit on vulkan), you cant use a debugger
might delve deeper into in leisure , fascinating stuff
you mean stuff like RenderDoc wont work?
nope
Is it possible to get an entity by name? The only way I can see to get a specific entity is to give it a unique component data and query that.
absolutely nothing will work
not renderdoc, not nsight
and btw, because on both of them its completly unrecognized commands, the entire debugger wont work
Does anyone here know why "MethodMeasurement" could be missing ? https://prnt.sc/rvk56r
Im still struggling with the dots import
upgrade test framework package perhaps and make sure you also have the performance test package. If you have a unity package in your /packages/ then it will introduce additional dependencies.
welp , then what gives? you just go on wits and whims ? trial and error ? @vagrant surge