#archived-dots
1 messages ยท Page 200 of 1
That's my implementation, about as simple as it can be while still being generic
It works well enough for me
Hm, I recommend you put [NoAlias] in front of all the native containers inside that struct if you're using it in bursted code.
Burst compiler can not automatically identify that pointers (aka native containers) inside a struct do not point to the same block of memory so it compiles conservative code.
You might, probably not, get better performance if you just add that tag to the inside of your struct.
Ahh, I still have like no idea how noalias works, I'll give it a shot and see if it makes a difference
It'll also depend on how you're accessing the data but NoAlias has no downsides to adding it so eh, give it a shot.
If there's no downsides why wouldn't they make it the default?
Because if the pointers do point to the same block of memory, things break badly.
Doesn't seem like it makes a difference in this case. There's a lot of random access going on so I wouldn't expect burst to perform any miracles in this case
Yea, aliasing is basically chunk copying / modifying memory. You'll need to be running a for loop for every single aspect of the container for it to apply.
Well at least UI toolkit has been updated to 2021. Lets see if it still breaks with Entities.
Wasn't there a specific entities-based UI toolkit package released in December?
no, someone did release their own pure dots ui solution though
The major addition to this preview is the first iteration of UI for Project Tiny. The initial plan for UI was to deliver a subset of UI Toolkit (formerly known at UI Element) but we decided to postpone this approach and instead offer a more lightweight UI system inspired by Unity UI (UGUI). In this first version, UI for Project Tiny includes support for Image, Button, Text, Toggle, Sliders, Rect Transform and Canvas UI components. Note that this is not a complete UI system yet, see the documentation for more details on UI. The TinyRacing, TinyTime, TinyAquarium samples have been updated to use the UI system, so you can jump right there once youโve read the doc.
It's still -really- rudimentary at this point I see
I wouldn't take anything that Tiny is doing as an indication of what an official dots solution would look like
They're kinda doing their own thing
Right. Thanks for the clarification on that.
Speaking of Tiny, I wanna take another crack at that for a bit. Anyone able to build Tiny projects mind sharing their current .vsconfig so I can sanity check my own against that? (Visual Studio Installer > More > Export configuration). Thanks in advance!
hey all
Any ideas on the best way to sync data between 2 worlds?
Should the Simulation world push the data to the Rendering world (Sim => Rendering)?
OR
Should Rendering pull from Simulation (Rendering <= Sim)?
im thinking pull, but what to hear what others think
@gusty comet as in Math.Random?
Doesn't work good in parralel jobs
I actually saw a mention of how they recommend using it in jobs in that new doc they just put out
and returns the same result on a regular basis
theres a new one in the new math library
link?
Please xd
How to idiomatically generate random numbers in Burst-compilable jobs with Unity DOTS.
Scroll down a little from there
I have tried both suggestions
and still get the same random number on occasions
I think since i just need a random number between 0-1 I will add them all to a native list
and remove/add as they're used so I don't get the same number
yea so true random does give you the same number again
random like your describing isnt true random
your idea should be good tho
haha
is there somewhere I can read about the entityDebugger
so many colors that aren't defined
red/white/green what are the differences?
all the docs are linked via pined messages
top right of discord
if that dosnt help theres not exactly alot more ๐ฆ
best bet would be to read the code
Well then you're not asking for random
more like a balanced distribution, whatever it is called ๐ค
unsorted round-robin ? ๐คทโโ๏ธ haha
Is it at all likely that Visual Studio Community or using Unity Personal would be the root cause for Tiny Projects to not build?
This is dependency/package-resolution stuff that seems to be failing so it seems unlikely to me but that's what I'm using at the moment to try this out
Nothing about license version is specified in the google doc either - only 2020.17f1 or later.
How do I properly install all the packages for DOTS? I am using the latest platform, 2020.2.3f1.
I found out about the manifests.json, so i am trying that.
I'm on personal so I don't think that's it
What errors are you getting?
Oh, and that's just from a base project, nothing changed?
From one of the project Tiny samples, nothing changed at all
Did you try one of the other samples? I've only used the 2D sample and the 3D runtime geometry samples for this version myself
And did you try posting about it on the Tiny forums?
They're usually pretty responsive
I have them all pulled so I can give it a shot in a second. I'm about to add to another thread in which a guy is experiencing the same thing
We're probably both doing the same silly thing
You have to add packages via "github url" in the package manager. Package urls are at https://forum.unity.com/threads/dots-releases-latest-release-dots-0-17.1044523/
@zenith wyvern Thanks
Yes basically but usually randomizing it works good enough, unfortunately with ParralelJobs, that isn't exactly the case. I was generating a random number 1000 times between 0-1 and anywhere between 1-600 of them would get the same value every frame depending on some unknown factor (my guess is app startup time).
I was able to get it to work thanks to the article sark sent, but its still not ideal and completely mind boggling to me they haven't just made UnityEngine.Random.Range thread safe, considering how often it is used.
Hi guys, i recently has added a dots editor 12 which provides better entity inspector. And it's awesome but for some reason it doesn't update DynamicBuffer value in inspector. Is it package limitation / known bug or i do something wrong maybe?
@frosty siren Whats your versions? I'm using all latest and use a ton of dynamic buffers and it works fine
unity version? 2020.2.1f1
Did a writeup on what seems like a relevant thread
https://forum.unity.com/threads/problems-when-building-project-tiny3d.1053431/#post-6821819
How do i Parallel write to a dynamic buffer?
using GetBufferFromEntity
I get this error:
is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type.
You don't. At least not in a safe way. You'd have to retrieve it on the main thread and pass it into job with safety checks disabled
yea that dosnt seem like a good idea
You need to either structure your job around including the buffer in the query or just run it single threaded
yea i might try flipping it, instead of all my source entities writing into the single buffer, the job could be the single buffer reading from all the source entities
if that makes sense ๐
but it can wait, single threading it works for now
If you know for sure you're not writing to the same index from different threads you could just disable safety checks. If you can't guarantee it though then yeah you need to rethink it
Is there a way to see if an entity has a component with a command buffer?
or can I just call RemoveComponent without any care if it actually currently has it?
@zenith wyvern na im definitly writing to the same index
my setup is many entitis, writing to few entities but always adding to the buffer
@gusty comet no command buffer is write only but i do think remove component is safe if the entity dosnt have the component
lets find out
@ocean tundra works fine
I ended up writing a few systems to generate an icosphere and a half-edge data structure and its sooo dang quick compared to when I did it with gameobjects
Can you use ecs in editor scripts?
@gusty comet What sort of editor script?
Full DOTS (so entities and systems) have a editor world, or you could create a new world and manually update it
I am trying to create something like easy3droads
and imo dependency management and such is simple af in dots
so i was gonna make the editor scripts use dots since stuff like this can be resource consuming as is
hmm i would just build it into the authoring flow
im not sure but the built in editor conversion world might have a way to render
that has me on a side thought now haha
so your authoring gameobjects can be dumb and generate meshs ect then in editor it can just render the output like it would in runtime
is the mesh renderer unity provides for dots usable in parralel jobs?
what do you mean by usable?
and it renders it inteernally?
yea
internally its all magic
ummmmm
ok
๐
it will be better but right now its very wip
it managed megacity well tho
is changing the mesh expensive?
and i think theres a single threaded bit/bug in the current hybrid renderer for uploading the mesh to the graphics card
yea thats terriable
but i think building on what unity have confirmed is the 'future' is probably the best way
the whole authoring/conversion flow has been said to be the way to use entities so start with that
so I was going to compensate by generating a mesh for each keyframe of each animation at edit time and change the mesh at runtime but that doesn't sound very practical if changing mesh is expensive
also those conversion systems cna use jobs and burst and all that
well dont change the mesh then
So in the future they will be required?
instead take the entity and create many entitys with render mesh for each frame and then add Disable to them
yea somewhere it says that convert to entity will be removed
I don't use either tbh
you can still manually create entities from code tho
ok good
i dont think they can remove that
Pretty sure the animation package is as complicated as it is to avoid this exact scenario. Because it's a shared component, for every unique mesh you have attached to a mesh renderer that's another 16kb chunk unity uses up. Aside from the performance cost of jumping beween chunks so much you're going to use a ton of memory if you have a lot of unique meshes
yea thats a good point
@gusty comet is there a way you could get by without animations for now?
My plan is to get all the core bits working and add animations later
@ocean tundra ofc i can, but the game just kinda looks awful with every ai and the character in t pose, if i wind up having to do t hat I will just make everything capsules for now xd
haha yea i had that
i started using models in different fixed poses instead
still bad but at least not T's
Is there any other option?
fight the animation package untill it works?
How did they animate the entities in the nordeous demo that they showed when ecs was first annoced
Gpu skinning I believe
thats released somewhere
but pretty sure they took all that and built it into the animations package
@zenith wyvern can you talk to me about rendering and animating sprites within the context of DOTS? I want to create a bunch of pre-made pixel art tiles and draw them in when I render my tile entities
How are you rendering? Hybrid renderer?
I've currently got it setup to use Hybrid, yes.
But I'm not married to anything I'm still just prototyping
Hybrid V2 if that matters.
What I would do is figure out how to set per-instance uvs using hybrid renderer's material properties and use those to set your per-tile uvs
If you're not familiar with manipulating mesh uvs in code you should just create a simple project without ECS in it and read some tutorials on building and manpulating a plain unity mesh in code
Once you have a grasp on that the rest should be pretty easy
If all your sprites have the same mesh/material then it should be super efficient too
Okay, so I'm just rendering a small quad mesh for every tile. I don't know what mesh uvs are so I should go and figure that out.
Once you figure out how to swap out which sprite is displaying on a unity mesh by switching out the uvs in code it should make a lot more sense
How do i disable live link for a specific world?
Also depending on how many of these sprites you're going to have you could get away with just using plain unity sprites attached to entities as hybrid components. It won't scale that well but you'll get the huge benefit of being able to use all the existing 2D tools for animation/lighting/whatever
I'm wanting to build an alife sim and high entity count is sort of what made me chase DOTS so I'd like to do whatever I need to lay a good efficient groundwork early ๐
In a recent project I just finished we could easily have a few thousand hybrid sprites running around, didn't get to the point of animating them though
I guess now is a good time to ask, does Hybrid Renderer v2 automatically cull the entities that are off frame?
Yeah
you could do a hybrid approach but manage the linked gameobjects yourself, disabling and recycling the ones out of view
that way you get all the goodness of current 2d tools and most of the scale of dots
Well I'll head in that direction and see what I bump into. Thanks all.
I wish unity made all their things public, All i need todo to disable live link in a world is get the LiveLinkRuntimeSystemGroup and disable it
but its private!!!
@zenith wyvern when you talk about switching out the UVs in code, are you talking about rendering just a portion of a Mesh UV and changing which portion that is?
Okay. So is it better to have bigger spritesheets or a lot of spritesheets
The more sprites you can get in one texture (within reason) the better, since it means more meshes can share the same material which means less draw calls
Yeah it's the "within reason" I'm curious about.
AFAIK you should aim for some power of 2, not sure what the reasonable limit is though, I'm sure there's some technical reason to not go above a certain size
How do you handle converting the UVs into individual sprites? I guess what I'm asking is what is your workflow for carving a spritesheet into individual UV squares
In my roguelike I use Code page 437 ascii for my art, and I have the benefit of many pre-prepared ascii sprite sheets made by other people. In my rendering code I can calculate the uvs for a single tile from the size of the sprite sheet and the the "uv index", aka the x and y position of the sprite on the sprite sheet, since all my sprite sheets have the same amount of sprites (16x16)
Okay. Thank you for that.
You can also use Unity's built in sprite slicing tools to build unity sprites, then get your uvs from those during conversion and convert them into an ecs friendly format if yo uwant
Have a good night. I'm going to play some Valheim for a few then head to bed.
What's a common way to model events in Unity's ECS?
I'd like to model an 'OnCollisionEnter' event for entities. My first thought was to have a 'Dynamic Buffer' on the entity for these events and add an event to the list whenever a new collision was detected, then have a system run at the end of each simulation step and clear this buffer for every (collidable) entity. I feel like that should work, but not sure if I'm missing a more obvious way to model events instead?
@cerulean forge There are several approaches. You could either add a Tag component (e.g. OnCollisionEnterTag), use a buffer as you mentioned, create a new entity with a component storing the info relevant to the collision or take a look at some of the open source ECS Event systems that have been built on either of these solutions
I have not found a solution I am fully satisfied with though...
(1) Is adding/removing components like that cheap? I didn't really dig in to the 'archetypes' too much yet, but I was under the impression that you should avoid adding/removing components every frame.
(2) An issue with adding a tag component would be the fact that you might have simultateous collisions with multiple other entities, so you need multiple components of the same type? Is that a thing?
(3) I don't dislike having a separate entity for the event, but the problem there seems to be that I can't query that. E.g. If I want all the collisions between entities with a 'Damage' component and a 'Damagable' component, I'll have to loop through all the collision entities and use the EntityManager to fetch each involved entity and check for the existence of certain components. A dynamic buffer doesn't solve that issue completely, but at least you don't have to check 'both sides' (e.g. have a query for all entities that have a 'Damage' component and a 'Collision' component and for each of those check what entities they are colliding with through the EntityManager, and whether those entities have a 'Damagable' component.
adding tag components are practically free
Is it? It still needs to move the entity to a new chunk doesnt it? But its not that bad as it enables you to easily iterate over each collisionevent
it's not free
Hey
Is there a simple way to do audio in DOTS, I'm not finding much online in the way of basic examples such as a system that does something like
foreach entity
if(entity.condition)
play sound
once you change an entity's structure. it needs to move to its matching archetype
but do you change the structure by adding tags?
also please, can we have .net 5 in Unity soon plz?
@rare dew sure it changes the archetype. It has to move so you can efficiently query and iterate it
@cerulean forge as I mentioned there is no silver bullet that I am completely satisfied with
interesting ๐ค
It also depends on what you want to achieve. If you want a system that handles all collisions 3) would work well
but is it expensive to add and remove components from entities?
If you just want to handle entities with specific components you should probably account for that in the code that would trigger your collision event
@Inuk depends on what you count as expansive. As I said it enables to work on that data efficiently later on
There are basically just 2 options: Sort them and work fast. Or avoid sorting and work slowly
depends on the task you want to achieve
It's not that it's expensive. It's pretty fast.
but the moving the entity to another archetype is the expensive part
Alright, thanks for the input. I'll mull it over a bit more ๐
But multiple components is not really a thing, right? Nor is querying multiple entities as if performing a 'join' operation (e.g. have a collision event with pointers to two entity ID's, and treating those as foreign keys to the actual entities, and then being able to query based on these entities' components?)
there's dots physics
I'm avoiding dots physics as it's still very experimental. (which does mean I have to do some awkward patching like this in my architecture)
My game uses mostly 'regular old unity' stuff, I just like to process some of the game logic in an ECS manner.
multiple components is a thing.
Oh I see. What's the trade-off between multiple components and DynamicBuffer?
@deft stump but not multiple components of the same type (as far as I know) which is what @cerulean forge asked for
thats what you usually use a dynamic buffer for
aaaah yea yeah. multiple components of the same type isn't a thing
Join? ๐ค
As I described above. Treat an entity index in a component as a foreign key, and iterate both entities at once. (a bit like an sql join)
I'm having a peek at the documentation, since I didn't read up on 'manual' queries yet.
well I guess there are cases where you have to do that
@rare dew so I may have misunderstood what @deft stump was trying to say but:
- Add/remove components is not "that" expensive compared to monobehaviour equivalents. That said:
- Add/remove of a component does cause a change to the archetype of that entity. How costly this is varies. If it becomes an archetype that already exists, and there's allocated space available for another entity in that chunk, groovy. If not (or even if so but it leaving it's existing chunk affects thing), it can cause a bigger shuffle to entities. Still, not usually a big deal.
- If you're doing a few hundred operations a frame, you probably don't want to be doing it
- Add/remove has to be done on the main thread so causes a sync point. You want to avoid doing this usually anywhere but start or end of frame. This is what Entity Command Buffers are for: queue these operations for e.g. start/end of frame.
Multiple components is conceptually an array of a component type associated with an entity. This usually takes the forum of a DynamicBuffer. As for foreign keys etc, I'm not 100% on what you're asking but you can store an entity in a component and you can find data using that entity as a key. It's called GetComponentDataFromEntity<T>() but when you're writing code in a SystemBase you can just use e.g. GetComponent<Blah>(someEntity); - this is a random memory access but in general you don't need to worry about that until you're talking about a heavy optimisation pass.
oh interesting, thanks!
so if I do it every once in a while, it shouldn't be anything significant?
yup, totally - and if eventually you profile and find that it is, there are strategies
I just encountered a problem with spawning entities. As I use the BeginInitializationCommandBuffer and the custom systems usually run before the Transfom Group they always run at position 0 the first time they run
Am I missing sth or is the only solution to move every system that depends on positions to the end of the simulation group (after transforms group)
How you handle it is up to you but understanding and managing the order of your systems is very important.
When the Transform system runs, it uses all the e.g. positions, rotations & scales in a hierarchy and calculates the final matrix. Therefore, you can either a) Spawn before the Transform system runs or b) Spawn after Transform but before render, in which case set your LocalToWorld matrix manually or c) spawn after rendering.
Spawn exactly before the transform group could also be an option I guess. But to my surprise there was no commandbuffer at the beginning of this group
a command buffer would be a sync point - you generally want to avoid these mid-frame
yeah I thought so
similarly, ideally you wouldn't instantiate an entity in the middle of a frame.. but if it doesn't happen frequently, nbd
so I would have to either update the LTW manually or move all my systems that read position behind the transform group
well.. I don't know what's best in your case without knowing more. However "moving all my systems" should be pretty easy if you've got them all running on a ComponentSystemGroup - you can just add e.g. [UpdateBefore(TransformSystem)] above it. If it were me I might think if it was better to instantiate at the beginning of the next frame or something instead.
its basically the targeting systems that find valid attack targets and the attack systems that execute the attacks on the found targets
I just added an entity that attacks once and then gets destroyed which makes the problem obvious as it attacks at 0 gets moved to its position and then gets destroyed
but obviously that problem also happens for the things that live longer (but only for the first frame)
It's certainly a common thing people run into but I see it as something to understand and then pick your preferred behaviour. Hopefully now you can better understand how to get the behaviour you want? But let me know if you have questions.
Yeah thx. I guess I will try moving it to the end of the frame and see how it goes
Cool, good luck
Does anyone know what the difference between GameObjectConversionSystem.AddHybridComponent() and EntityManager.AddComponentObject() on the destination entity manager is?
I think the main difference is that AddHybridComponent creates a companion gameobject and keeps it linked with the entity
Hello, I'm using a NativeArray<int> in a struct. For some reason this breaks VS intellisense, if i do "struct_instance.", it doesn't pop any public methods of that struct nor public fields. If you use that struct in another struct, all intellisense for that struct is broken as well. Here's an example - https://pastebin.com/pVFBmGie. Does anyone know how to fix this?
I think you mixed with a DynamicBuffer ?
a DB in a component, that you can get in your system as a NativeArray
Archetypes seem to be denormalization of data that was previously normalized from breaking down from objects/OOP to separate components. Am I understanding the usage pattern and performance tradeoffs right by relating it to SQL databases here?
I believe that's what unity themselves does when they explain it
yes. that's what you should imagine
just gonna bump this again does anyone have a really simple audio example in dots? I've been looking at megacity and it's a bit hard to follow
unfortunately theres not really a simple audio solution yet(besides old gameobject workflows)
As to your example you should be able to do that using hybrid components
I see, so a component who has an entity which points to a gameobject which has an audiosource?
More or less yeah. The gameobject becomes a hidden detail in this case, you're only concerned with the monobehaviour attached to the entity
That's what hybrid components do automatically
man, wheres that dots blog post
Supposing I want to start using and fully learning DOTS.. where would you recommend I should start? I did a DOTS workshop 2 years ago, and most of what I did is outdated, so I'd like some direction. No need to be spoonfed, just want to know where to start
Add com.unity.rendering.hybrid to your packages. Beyond that, really depends on what you want to make.
Is there a way to create an entity in a non job thread?
One i've created with c# threads
I wanna learn the DOTS workflow, basically
DOTS workflow, hm. A bit broad but there are the sample projects on: github.com/Unity-Technologies/EntityComponentSystemSamples
like kornflaks said, those samples + the physics samples are a good place to start. this guide was just released as well - https://learn.unity.com/course/dots-best-practices
@gusty comet I would create a Command Buffer on the new thread (or create on main and pass into the thread) then trigger the playback later on main thread
not 100% sure it would work, but i am pretty sure (90%) that you cant use entity manager on other threads
Thaank you
@robust scaffold & @safe lintel answers, + the official manuals https://docs.unity3d.com/Packages/com.unity.entities@latest (links to all DOTS packages in the left menu) + follow the forum
I'd add some Unite videos on Youtube, still relevant if young enough
and talk with us here ๐
Finally one or two blogs find useful things too
I'll get a DOTS practice project going, try to recreate unity's samples and use the course as a guide
if you have a bunch of jobs in a system in order, then the dependencies are supposed to be automatic arent they?
it doesn't seem to be in my case, maybe because I have a `ToComponentDataArray<CellData>(Allocator.TempJob); in the middle between them ๐ค
next I tried using ToComponentDataArrayAsync to manually create a dependency and I get haywire results ๐
am I doing this right or am I missing something? for a ScheduleParallel() job
Is this in startup? I highly recommend against using ECBs since they're very sensitive and hardly work most of the time.
Just create the entities in the main thread.
Also, that's a lot of buffers. If Entities e contains HePoint buffer component, you can just access it using the foreach lambda variable. Use in DynamicBuffer<HePoint> hePoints then use the for loop.
The only reason you want to pre-call access to the buffers is when you use one of the struct based Jobs. Lambda is really convenient that it does all the GetBufferFromEntity for you.
Thanks!
i disagree with that statement on ecbs, there shouldnt be any showstoppers regarding them and you should definitely use them if the case calls for it.
I don't suppose anyone knows if its possible to create a Jobhandle for ToComponentDataArrayAsync<>
When you call entityQuery.ToComponentDataArrayAsync<T>(Allocator, out JobHandle handle) the handle should be created for you
Agree with @safe lintel ECBs rule
so how do I find and use it?
use Handle as a input to schedule or schedule paraell
or combine it with Dependancy if your doing more nomal stuff eg Entities.Foreach
entityQuery.ToComponentDataArrayAsync<T>(Allocator, out JobHandle handle);
var newDeps = Job.WithCode(() => { ... }).Schedule(Dependency);
Dependency = JobHandle.CombineDependencies(handle, newDeps);
I thought it was to pass in a dependency
out parameters have to be assigned before the method finishes its scope
so ToComponentDataArrayAsync would have to assign the out JobHandle handle
JobHandle Jobuno = Entities.WithName("ResetCostandBestCost").ForEach((ref CellData celldudes) =>
{....
}).ScheduleParallel(this.Dependency);
var TempCelldata = CellDataQuery.ToComponentDataArrayAsync<CellData>(Allocator.TempJob, out Jobuno);```
so I'm guessing thats not valid
you might need to combine the final dependancy and assign it back to dependancy ๐
Dependency = JobHandle.CombineDependencies(handle, newDeps);
wait think i read that wrong
Jobuno is a depenancy you want to pass to ToComponentDataArrayAsync?
yeah
I get all kinds of errors if I don't use this.completedependancy() after that job
no clue how to do that sorry
complete will cause a sync point i think (wait for all jobs to finish)
and that's a syncpoint so I'm wondering if I can do it without a sync point
so not exactly great for performance
yeah
why do you need the data on the main thread?
can you have another Entities.Foreach after?
I don't the first job resets the values, then the second job uses those values
so why are you using ToComponentDataArrayAsync? thats for main thread stuff isnt it?
Well ToComponentDataArrayAsync allows you to schedule data collection and use it for a threaded job later
oh i see
so you schedule the data collection and pass that into something like Job.WithCode
oh I didn't realise it worked like that, I just saw the jobhandle stuff
the job handle will probably need to be passed into the jobs schedule method (Job.WithCode(STUFF).Schedule(dependancy))
I got this system and for some reason halfEdges and hePoints comes back empty (the data is populated in the entity debugger). points comes back with expected data. I've switched to Run() to run on the mainthread for debugging. not sure whats up, any suggestions?
data is set properly...
youre positive its the right entity?
If you your ForEach and EntityQuery are identical then the indices in the array returned from ToComponentDataArray will align with the entityInQueryIndex your ForEach
So instead of CopyFromData you run a ForEach and set the values manually
Typing on a phone sucks
Looks like you're passing your buffers as in. That means you can't be writing to them in that job
I figured it out, it was a silly mistake. I was triggering my HalfEdgeInit system at the same time as the HexGridGenerator system
Ahh yeah. Update order stuff is annoying to figure out
I added the tags to trigger the systems at the same time in another system instead of separately
atleast i learned a good amount debugging this xD
I have to say even while figuring out the ecs/dots approach the performance i'm getting doing these subdivisions generating icospheres is insane. even my laptop does it ridiculously fast compared to the old GameObject way I tried.
on my main pc with an i7700k takes about 19 seconds to do 8 subdivisions from the time I hit the play button. with the gameobjects method I think my PC was struggling to do 7 subdivisions without freezing lol
I've been doing some deep dives into mesh generation and honestly, if you want to create meshes with a decent performance, ComputeShaders is the way forward. DOTS may be fast but GPU side parallel generation is lightyears ahead in speed.
Of course, making it work is a lot more difficult.
yeah I've been reading up on compute shaders
I've seen some stuff mentioned about GraphicsBuffer to replace Compute Shaders
but I need to do some more reading
right now my brain is recovering from all the reading I did on generating meshes and data structures
Graphics buffers are even more broken than Hybrid Renderer right now. Honestly surprised they made it into production honestly.
haha what a shocker xD
Only part that works is StructuredBuffer and IndirectArguments. Nothing else works.
thats why Im using hybridcomponents for my main planets so they dont get rendered with the hybrid renderer
The only reason to use HybridRenderer is to use Havok Physics. No other reason to do so because you also have IParallelForTransform to move Mono Gameobjects. And gameobject rendering is much better optimized.
compute shaders definitely seem like something that would benefit me a lot for this project but just need time to figure them out.
ah right on, so is it best to just avoid the hybrid renderer totally?
Yea, I'm in that boat as well. Struggling to get a single quad rendered.
Yea, avoid Hybrid. Use base Entities packages.
ECS works perfectly and as intended. Some of the visualization and the whole ISystemBase is slowly being rolled out but the future is bright. Hybrid Renderer was a mistake.
yeah the rendering side of things is confusing
It depends on your use case. If you have a lot (like more than a few hundred) unique meshes then you should avoid it. Otherwise it's fine and it will only get better as unity works on it.
And really if you want to render more than a few thousand entities its the only option unless you get into low level gpu stuff
@zenith wyvern ah thanks that seemed to be the general consensus ive been reading online.
any one notice the build configs in editor killing unity
seem like if i doc it
or maybe its any layout off the default
yup docking the Wasm property kills Unity editor
wondering anyone know how to disable a sprite render in tiny
Thanks Sark, its confusing how they work, I guess I'll just replace both with a manual Entities.foreach assignment
I want to trace Camera's properties in ECS. What's more optimal: one system that queries camera object and copies its pos & lookat values to separate ecs component or querying the camera object in multiple systems on demand?
Depends on what you mean by "optimal"
In terms of performance the difference is unlikely to be noticable
My entities won't render, but they do appear in the entity debugger and Hybrid Rendere V2 seems to be running proberly
I'm having game components in a sub-scene
(If I use the to entity script, they won't render either)
Pure ECS ? converted gameobjects ?
@karmic basin it's game objects inside a subscene
strange
Just a cube I did nothing to
I recorded a lil vid
hmmm I dont see it converted
SHould say so at the top of inspector
and "by subscene"
uhm
save subscene ?
scene is autoload ?
yo uhave the define for HR v2 ?
sorry just throwing everything that comes to mind
try disabling srp batcher potentially
I'll look into it when I get back home
You can still use ToComponentDataArrayAsync, you just need to swap out CopyFromComponentDataArray with a ForEach - as long as the query archetype matches the one from your ForEach the indices will align
yeah no worries Sark, I changed both to a foreach it seems easier that way, I can dispose of the nativearrays more easily also
its not like its much code just this
var celldatacount = CellDataQuery.CalculateEntityCount();
NativeArray<CellData> TempCelldata = new NativeArray<CellData>(celldatacount, Allocator.TempJob); Entities.WithName("CollectAllCellData").ForEach((int entityInQueryIndex, ref CellData celldudes) =>
{
TempCelldata[entityInQueryIndex] = celldudes;
}).ScheduleParallel();```
Anyone know of any tutorials out there using the latest ECS 0.17 package to get an understanding on how to use this?
Well, manual has been updated and also the official github ECS samples are up-to-date
what is setEnabled in this case?
I see the github sample, i am just a little lost on where to start with this. I can find tutorials/videos but they use older versions of ECS or is a hybrid approach.
Start with the Hello Cube
clone the repo in local, it's easier to explore. And go to the next project in order (they are indexed)
It will introduce you to ECS concepts step by step
There's a smooool README in each folder to explain you in a few lines what they try to show you
I can find tutorials/videos but they use older versions of ECS or is a hybrid approach.
You can still understand the idea if they are less than, let's say 6-12 months old, then review the changelogs of each version to migrate your project.
Yes this involves a lot of work, but that's part of the fun that's expected if you jump so early into preview packages like DOTS
though ECS is kinda stable now really
Regarding the hybrid approach, that's the recommended workflow anyway
Are you asking if Components can be enabled and disabled?
No. as of now, UECS doesn't support that
Iโm trying to disable entities
But I seen now it actually adding a disable component
And itโs a structural change
But ECB does not have SetDisables only entituManager
then why not just add the Disable component via ECB?
Hybrid is recommended over pure ECS?
Iโm in tiny
Yes, for the power the authoring part brings you. While they work at porting the editor and all legacy API to DOTS
The setEnables traverse children too so I was hoping to use that
So you start from gameobjects, and convert to entities and/or use Jobs to perform heavy computation
but nothing wrong to migrate to Systems just for fun, even if no perf needed
Has the Unity team gave an ETA for porting all legacy APIs?
I'm not confident with their roadmap, I try to not bother. All I can say is they are "late" compared to what they wanted first.
ECS and Jobs are ready enough already to begin playing with it
Every other package.... well I'd say only for the more curious
theres basically no roadmap, everything is "at some point"
plus the fact they're not being open with the community on what they're working on next
partly
Jobs, Burst and Math is out
but still not the full stack which was promised for 2019
and then never mentioned ever again of when it'll get fully released
wait jobs as well?
Jobs is already production ready
what is jobs worth without entities? ๐
heavy duty math operation like pathfinding
or you can make your own particle system with jobs
now that I think about it. Jobs and C# async are in the same boat.
they can't really do anything with Unity's API
I believe Jobs rely on entities, but I may be wring
job system was added before DOTS was even a thing
other way around, entities relies on jobs
but jobs are built into the engine/editor core, the package just adds a few new types
oh interesting
'safe' multithreading and no overhead from C# threading since unity's worker threads are already there (and managed natively)
So jobs can also manipulate mono behavior?
no
oh
So what is project tiny...is it like...a seperate editor?
Everything I read on it assumes you know what it is...
It's a set of packages that you use in the normal unity editor. When you build a tiny game it can't reference anything to do with UnityEngine
The getting started guide goes over it all in detail
I think the most compelling reason to give Project Tiny a shot is that it's more paved if you want to have both WebGL build and DOTS enabled.
At least that's why I wanted to try giving it a shot ๐
Project Tiny is DOTS but it runs on its own Runtime called DOTS Runtime.
in my view, it's the most Pure DOTS way of doing things without Hybrid authoring.
and yes
it has its own editor
What do you mean? It uses the normal unity editor
There's no restrictions whatesoever when you're authoring
@karmic basin I fixed the thing with the entities not rendering
By turning off HR V2
this of course implies I've set up URP wrong
can someone real quick TL;DR me the dots editor?
if you didnt have the srp batcher on with v2 enabled, hybrid renderer wont work
Would you want to use DOTS for player movement?
@lucid lake strange question, you want to use DOTS for EVERYTHING!!!!
If that is the future lol
I understand it is used for performance when many entities are performing similar tasks. But when don't you use it?
i do pretty much everything in DOTS atm, but theres large things that will need old gameobjects
like particals
sounds
pathfinding is a weird hybrid
I very much love how systems and entities are tied together
I find it oddly beatiful
I have to say however, I really don't like the magic of systems
That you just make a system and the compiler just kind of... runs it
you can see the intermediate output
go to DOTS => DOTS Compiler => Open inspector
personally i think its great, you used to have to write SOOOO much code, now we get a nice clean API
and the cost of code gen is so worth it
and if you really really need to you can copy the intermediate output and edit that
Oh yeah you can view both that and the burst-compiled IL for a given system, right?
Is that only available within the Unity editor or is there a way to do that through command line and spit that out into a file?
probably only via editor
but you could probably make a editor script to respond when calling unity via commandline
using -batchmode ect
the hard part would probably be finding unitys code that does the code gen
There's some benefit to it being automagic. It will try to optimize based on what data you read/write.
You can still disable auto discovery and/or schedule dependencies between jobs/systems to change execution order
what is the status of DOTS right now?
ummm some core bits a good and stable
but many many other bits are missing
and some core bits still are having API changes
@ocean tundra Like DOTS animation
@ocean tundra How is the pace of development coming along?
it feels like its slowed down ๐ฆ
im not sure it actually has, but new updates seem slower and not a huge amount of new communication/future plans have been happening
at a guess i would say unitys new focus on stability has caused them to have to slow down a bit
but it could also be that the core DOTS(ECS) team has started looking at other packages (like particles? ) and havnt really said anything
honestly dont really know
Ok so when you describe the "Core" what does that include
Job system - good
Burst - Good
ECS - good but still undergoing API changes + new features were discussed months ago with no releases yet
and then things like
Editor Tooling (inspectors) - rough , latest release feels ok but still dosnt quite merge right with existing Unity flows
Editor Tooling (conversion) - poor docs/communication, old parts they have confirmed to be removing ages ago still exist and new stuff has all sorts of issues
Maths - good
Physics - okish, still undergoing changes and kinda dosnt feel like DOTS
oh and the hybrid renderer
very poor ๐ low to no docs and everyone seems to have some sort of issue with it
I hear they are going to release it in 2020 versioin as LTS
ive never heard that
Any timeline on when 2020 will be released?
no clue sorry
and i doubt DOTS will be marked as released (yet alone LTS) any time soon
not with unitys new focus on stability, the core might work but doing anything real with it requires rebuilding wayyy too much
2020 LTS is Q1 2021
so lets hope end of next month
yea but no way dots will be 1.0ed or released with it
its not even in the package explorer as preview any more
Yup
i have simple spawner and i getting that warnings
got to share some code
but looks like your using a native collection wrong
at a guess your creating a native collection without using Temp and not disposing it
netcode is very very early
that channel is for netcode? or its #archived-networking
I'm looking to multithread pathfinding AI using the job system
can someone point me in the right direction?
reading through DOTS best practices
it's kinda funny they're suggesting to Schedule when Run has little overhead.
There are plans for future versions of the Entities package to include an optional Enabled flag, implemented as a bit-field in a chunk component. This should provide a good balance between storage space for the flag bits, CPU cache bandwidth, Burst codegen, and should handle the tricky maintenance (for instance, rearranging the bitfields as a result of structural changes) automatically. When itโs available, this might be the best option for entities with very frequent state changes, but in most cases, a tag component would still be preferable.
Oh Unity, you're such a tease uwu
i wish i had one of those newer amd cpus to test to overhead of scheduling with tons of cores
quick question
camera is automatically converted
can i just do an entities for each on Camera and LocalToWorld component if i need to grab the world space of the camera
I did a quick attempt but I'd love to see someone do proper benchmarks: https://forum.unity.com/threads/future-of-scheduling.1048502/
Reality check: DOTS Animation doesnโt support skinned bone animation yet, right?
I was able to get one skin to work with thoughts animation but the instant I added a second one both of them messed up hard
I needed to get a hdrp lit shader graph version from GitHub and add texture coordinates or something to it
I don't think it's actually ready...
Also this is 2020.1 so maybe something changed
@untold sorrel
its possible to use hdrp with dots? i mean basic render pipeline works better than hdrp and idk
I mean I've been using hdrp with dots but I'm really just starting so I'm not sure what kind of ceiling I'm going to hit
Yes. HDRP is the most supported renderer for use with DOTS. Itโs also the one Unity recommends you use for ECS content right now.
Hdrp is better than urp for dots?
Where can I read that please ? Forums ?
I based my expectations on the manual https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.11/manual/index.html
I mean I'm going for mostly unlit rendering anyway, I don't need HDRP
talking about scheduling overhead which would you guys choose?
schedule single or schedule parrallel in this case
schedule parallel has a lot of overhead its not really much faster than singlethreaded, and it loads all the cores so not room for anything else
Yeah you might be too soon for optimisation. I would go for Schedule for now. Although I'm not one of the most knowledgeable yet on the topic
Is it a stress-test or normal conditions ?
stress test 1 million entitys
I'd go for Sched parallel in this case
I'd go for schedule and keep profiling the more I add systems, until I see one bottlenecking
but assuming you only have a handful of entities to loop through,
.Run() is way better
I'm still baffled why DOTS best practices is suggesting schedparallel as like the default.
I'm going to try and avoid using run() as that guide advises, even though it is faster
then fall back to sched -> run
I'm not totally convinced this exactly equivalent work - are you doing an extra copy back with the sched parallel or something? At any rate, as posted above, this somewhat matches the trade-off I've seen. Usually many x total amount of work done for small gain to single thread. Obviously here Schedule() is better I'd say but over a certain number of entities, you'll need scheduleparallel. Hopefully you never need to do it for lots in practice.
I don't know if I'm doing anything wrong with the copy backs I'll have to check with their versions
but yeah maybe I'll stick with parrallel for now, the total sum time is less and its in one frame
CopyFromComponentDataArray() is about 40ms faster, maybe they are using chunks or something its not really much faster plus I have to create sync points to use it so not worth it
I thought Run() was best practice? Dam
Well depends on your usecase I suppose
yeah.... best practices can always be rejected
Will GL API work in bursted jobs? ๐ค
But still, by assumption was that best practices where to use Run()
Run() is all on the main thread. The whole point of jobs is to try and get some work onto other threads. Schedule() (or ScheduleSingle()) is a good default.
yeah your just junking up the main thread if you use run() all the time
you have to look at it holistically, its not about how individual systems runs it's about how they all run and work together
Besides the attribute which tells a system to run after another, are there any way to determine the order?
Or is it "whenever", and with that asked, what about systems which are scheduled, will they also just run whenever convenient regardless of when their "sibling" (clone? other instances??) run as long as you don't have the shedparallel?
you can use SystemGroup
Oh I didn't know I had to use system groups, interesting
You don't have to
You can use existing ones (and sometimes should)
but it's a convenient way to make your own groups
sometimes ๐
Maybe Iโm missing something about your use case, but the advice Iโm reading here seems incorrect:
ScheduleParallel() is absolutely ready to use, and quite performant. Further optimizations to scheduling overhead may come in the future. But even now - the cost of scheduling a job across threads is usually dwarfed by the speed you gain by spreading out your job work across multiple threads. ScheduleParallel() has been the default go to for most job situations since Unity introduced the method. Thereโs no need to avoid it - itโs not unstable, and itโs usually preferable.
I would usually only avoid it if I could guarantee my jobs would always only iterate over a few entities. Even then, the best practice would be AB testing to see which is faster, but I wouldnโt avoid ScheduleParallel out of an assumption that itโs not ready. It is.
well like those images above show ScheduleParralell() takes 3.ms across 14 threads which is a total sum time about 40ms, whereas Schedule() is roughly 6 ms on 1 thread total sum time
I'd be curious if you have any examples to back that up. On a low core count it's partially true. With e.g. 24 workers you'll find you have to be a 10x overall energy/cpu cost for a halving of main thread time. Currently almost never worthwhile imo.
Youโre both right about your use cases - for sure. But - Iโd argue that those hardware situations fall well outside the norm of what most Unity games are likely to run on.
The proper case to use ScheduleParallel() falls in a sweet spot, in which your job is doing enough work to offset the cost of scheduling a job to begin with - and in which your thread count is low enough that each thread would be doing enough work to justify the split
But - most gaming hardware today has between 4-8 cores. Maybe 2 or 16 at the fringes. And in cases when your jobs are doing enough work to make parallel scheduling worth it, then ScheduleParallel() is a great option.
If your jobs arenโt doing enough work, or if you have a very high thread count, use Schedule() or even Run().
But - AB testing and profiling is usually always the best way to find out. What I thought was happening, is that the OP had the impression that ScehduleParallel() wasnโt ready to use - as in, it was unstable. That isnโt true - no reason to avoid seeing if itโs a good case for your jobs. ๐
Also worth noting that the second problem (jobs being spread across thread counts too high to be worth it), is something a unity can likely improve in their own scheduling code going forward. I hope so!
I could nit-pick a few of those points (e.g. I think most things we write now will be most likely going to run on 8+ cores) but I somewhat agree. It's also true that giving a job more work helps. Though even then, I haven't seen decent scaling on any jobs completed per frame. Being that a lot of us have to write code not knowing what quantiy of entities or what platforms the code will run on, it's not very possible to just pick one. Coding it to dynamically switch is also a big pain right now. They've stated they don't want to have any kind of dynamic switching because they want the scheduling to just be fast enough. Which sounds great but I don't know what gains we can expect in reality. Right now, with my practical use-cases, it's an absolute brutal trade-off. Either eg. 5ms on main thread or 2ms main thread, 50ms total.
Perhaps later on, weโll be able to give the jobs scheduler hints about how wide to go with a given job. But like you said, that need could change with the number of entities being worked on. Itโs a tricky engineering problem, for sure!
I suggested a ScheduleAuto or similar on the forums and was shot-down by Joachim so yea.. guess we'll wait and see.
e.g. you could in theory set the number of chunks you wanted to switch on pretty easily
Hmm..Well if one thing is likely to drive their choices (hopefully), itโs the raw performance numbers. If their current approach doesnโt work well in valid use cases, hopefully theyโll consider all options.
Thankfully a change in the scheduling code might not rip up their existing API too much
someone knows how i can fix that? or its related to netcode
i tried installing same packages from sample from github repo
but still its doing that
when i tried sample assets from github repo that thing was working
btw @untold sorrel did you look at the current animation samples? if that isnt skinned bone animation I dont know what is
@amber flicker where did joachim shoot that idea down?
That sounds kinda good to me but then again Iโm using unityโs jobs because Iโd have no idea how to do multi threading without it ๐
pfft
Just singlethread your jobs
who needs more than one thread anyways
(please note I'm just jesting)
someone knows how i can fix allocation warnings?
are you deleting stuff yourself?
uhm?
i just installed entities package and started playmode on default scene
with netcode
So you have done nothing besides that?
hi i was directed towards this channel as to my issue
my sprites are not rendering and giving me this error
its not rendering the floor sky and wall
is there someone who can possible help me?
please
pretty please?
if you call yourjobhandle.Complete(); on spriteshapegenerator does it work?
can you direct me to how i can do that as im not sure i see sprite shape generator nor know how to code the call
i have sprite shape controller sprite shape renderer and mesh renderer
oh its a package
how can i get it?
you already have it, it says so in your error that its in your PackageCache. When I first read your log I thought it was your own code throwing the error.
@mystic bay Are you sure you wanted to use dots for your first project?
Well that's because I saw the jobs part of the code
do i have to active some sort of code for this to fix the error?
You should start with any basic course or tutorial pinned in #๐ปโcode-beginner . This is an advanced system, and it is still under development.
but i didnt touch any of it
You are using its components without knowing what they are.
im not using spriteshape generator
i added a td object
2d
and i just wanted to make it look like a floor
id guess you might need to add a profile to the sprite shape controller?
is there a way to not have to mess with this issue by importing an image
to not have to deal with the cod
e
Is it possible to use the Jobs scheduler without safety features?
i'm not answering your question that's my own question lol
@mystic bay You are looking for basic 2d tutorial, nothing to do with #archived-dots You shouldn't probably even trying to use Sprite Shape package as well at this point. You should learn on basic 2d components first.
Is the blittable types restriction a fundamental limitation, or can it be disabled?
The Jobs scheduler makes good use of all available cores and I want to take advantage of that, without copying megabytes of memory every frame.
You can use class blah : IComponentData instead of struct blah : IComponentData for working with ECS when you have managed types. These can't be bursted however or used across threads. Afaik doing so can never really work. Instead focus on preparing your data and then copying back the results.
You can add various attributes to disable the safety features but.. you mostly shouldn't except in the case you're writing to a container in parallel and are very confident you're writing to unique keys in the job.
afaik cant use class components with jobs though
yes, exactly - amended thanks
what are you actually trying to achieve though? copying megabytes is somewhat vague, and imo you might be too reliant on old oop thinking if you are adamant on finding a way to use managed types in jobs
So I'm making a Minecraft clone or whatever with voxel terrain, and I need to update each chunk and run some simulations each frame. If I've written to a chunk, I also need to update the mesh. With 256 chunks, it's about 19 megabytes.
public struct ChunkData : System.IDisposable
{
public NativeArray3D<int> field;
public NativeArray3D<float> field_density;
public NativeArray2D<byte> field_heightmap;
public Vector3Int mins;
public Vector3Int maxs;
public int writeCount;
}```
My plan was to take a leaf from Noita's book for multithreading: https://www.youtube.com/watch?v=prXuyMCgbTc&t=11m8s
In this 2019 GDC session, Nolla Games' Petri Purho talks about the technical details of Noita's physics engine, including scaling up the falling sand simulation to support large continuous worlds and integrating destructible rigid body physics, while demonstrating the emergent physics based gameplay.
Register for GDC: https://ubm.io/341ZiaZ
Jo...
That way, I can update each chunk in place concurrently, 64 chunks at a time.
I tried doing this with slices:
{
return new ChunkSlice
{
field = this.field.Slice(),
field_density = this.field_density.Slice(),
field_heightmap = this.field_heightmap.Slice(),
mins = this.mins,
maxs = this.maxs,
writeCount = this.writeCount,
};
}```
@forest pike that's fine, think of nativearrays as pointers to your actual data, you're not copying the entire nativearray if you're passing it to a job
just the pointer to it
okay, so it's not copying the whole array when I copy the ChunkData over?
nop
so then it's just a code structuring problem. I wanted to get a 3x3 kernel of chunks to pass to my job: public struct ChunkKernel { public NativeArray2D<ChunkSlice> chunks; }
but at runtime, I get:InvalidOperationException: ChunkSlice used in NativeArray<ChunkSlice> must be unmanaged (contain no managed types) and cannot itself be a native container type. Unity.Collections.NativeArray`1[T].IsUnmanagedAndThrow () (at <e98ed0368295432e8c11e52d6243ee11>:0) Unity.Collections.NativeArray`1[T].Allocate (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArray`1[T]& array) (at <e98ed0368295432e8c11e52d6243ee11>:0) Unity.Collections.NativeArray`1[T]..ctor (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArrayOptions options) (at <e98ed0368295432e8c11e52d6243ee11>:0)
a slice to the underlying NativeArray
what type is a slice
public struct NativeArray2D<T> where T: struct
{
public NativeArray<T> data;
public int width;
public int height;
public NativeArray2D(int width, int height, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
{
this.width = width;
this.height = height;
this.data = new NativeArray<T>(width * height, allocator, options);
}
public NativeSlice2D<T> Slice()
{
return new NativeSlice2D<T>
{
width = this.width,
height = this.height,
data = this.data.Slice(),
};
}
public T this[int x, int y]
{
get
{
return data[y * width + x];
}
set
{
data[y * width + x] = value;
}
}
public void Dispose()
{
data.Dispose();
}
}
NativeSlice2D is the same as NativeArray2D, just without a constructor and with the NativeArray replaced with a NativeSlice
misunderstood your initial question, but yea there's no way around that, it's a fundamental limitation
So if NativeArray doesn't copy its buffers, the slice usage is basically useless?
so I have to do this? ``` public struct ChunkKernel
{
public ChunkData center;
public ChunkData n;
public ChunkData ne;
public ChunkData e;
public ChunkData se;
public ChunkData s;
public ChunkData sw;
public ChunkData w;
public ChunkData nw;
public ChunkKernel(VoxelBuilder terrain, int i, int k)
{
int max_chunk = FIELD_SIZE / CHUNK_SIZE - 1;
center = terrain.chunks[i, k].data;
n = (i < max_chunk) ? terrain.chunks[i + 1, k].data : new ChunkData(true);
ne = (i < max_chunk && k < max_chunk) ? terrain.chunks[i + 1, k + 1].data : new ChunkData(true);
e = (k < max_chunk) ? terrain.chunks[i, k + 1].data : new ChunkData(true);
se = (i > 0 && k < max_chunk) ? terrain.chunks[i - 1, k + 1].data : new ChunkData(true);
s = (i > 0) ? terrain.chunks[i - 1, k].data : new ChunkData(true);
sw = (i > 0 && k > 0) ? terrain.chunks[i - 1, k - 1].data : new ChunkData(true);
w = (k > 0) ? terrain.chunks[i, k - 1].data : new ChunkData(true);
nw = (i < max_chunk && k > 0) ? terrain.chunks[i + 1, k - 1].data : new ChunkData(true);
}
}```
is there a way i can make working with this less painful?
def not that
trying to remember what clean solution someone had
don't remember but anyway you could use UnsafeArrays and put collections in there, but you need to remember to dispose of them
what namespace is that in?
ohyea also not sure if that NativeArray2D struct will work in a job since it holds a NativeArray = nested collection as well
ah UnsafeList sorry, seems unity didn't bother implementing unsafearray
I don't get runtime errors when including a ChunkSlice in my job
please don't just @, reply gives better context not just to me but ither people as well
i tried using https://github.com/Unity-Technologies/multiplayer sample and that thing worked, now i have packages from that repo in my project but its doing that
hmm
what about UnsafePtrList
- playmode on default scene
@forest pike yea i think if going that way you'd have to use UnsafeList all the way instead of NativeArrays
Correct me if I'm wrong, but navmeshquery can be called inside the Job system right? So I just plug values into it and now I have multithreaded pathfinding?
I feel like I'm missing a step
I would have to make the job return the new position value of the NPC and apply the NPC's value outside of the job right? I've never done pathfinding before, just trying to get the hang of it
It looks like you're trying to abstract your data too much. And if you use unsafe containers everywhere it's going to annihilate your performance
If you're going to have one huge container that holds your whole world you might as well just do it in oop, it'll be easier and probably faster
When I did this I had a single NativeHashMap<int3,entity> that I passed to jobs. The entity being the chunk containing a buffer of blocks
You can use BufferFromEntity to access block data from an entity
Then you can easily convert to/from block positions from the chunk index and local index
Wondering if anyone has some idea how I can draw a line in tiny
Bรฉzier curves type of thing
We have no line render in tiny right ?
There is a EntityManager.HasComponent but I can't find a EntityManager.HasBuffer. How would I check if an entity has a buffer of a certain type?
Use hascomponent for the buffer
Oh, I see :D. Thanks!
Is the order of entities in query always the same as the order of insertion of these entities? I create entities through ECB in main thread and sometimes query.ToEntitiesArray() has different order
yeah you should assume that you're not guaranteed of order.
so what's the common pattern to have them ordered then?
I think about a separate entity containing dynamic buffer of these entities. Or just sort it after querying
why do you want them ordered / sorted anyway?
Because I can compute only the index of entity I need to process and nothing else
What do you mean by this?
I have entities that represent chunks of voxels in a scene. When I need to get information about a particular voxel I compute in which chunk the voxel is stored then I query all the chunk entities and access needed chunk by the computed index.
So you have an entity with a 'VoxelChunk' component? And you want access to that component, and you know which entity you are looking for? Then why not call EntityManager.GetComponentData<VoxelChunk>(new Entity() { Index = computedIndex, Version = version });?
Can anyone confirm that using Acion and Func is not allowed in jobs (or anything burstable)?
If that's the case that would be a huge bummer ๐ฆ
Correct. But we have burst FunctionPointers
Oh man ๐ข
Will a job without burst still run on multiple cores? In other words, do you still get some performance benifit in using ECS without burst?
You should profile, but in my experience no. Most performance gain comes from burst
if you have the data structured correctly you do still get a bit of a speed up compared to monebehaviour
I'm not sure that Entity's Index is same as my computed index there. I should have noted that I was talking not about entity indexes but ones in query.ToEntitiesArray(). Anyway, I've already implemented that using "chunk parent" entity which stores needed entities in dynamic buffer
Man, I'm really bummed out by this :(. No Action / Func means no quick easy abstractions. Burst has been a pain in the ass already but this is probably the nail in the coffin for me. I might stay with ECS without burst just because I prefer to build up the game this way than with OOP. But I had hoped things would go a lot smoother :/. Will these delegates ever be burstable, or is this impossible because of some hard technical limitation?
I think the takeaway is you really should be accessing stuff through Entity's Index and not the position in any list-like structure.
Not as far as I know. I don't bother with burst function pointers as it's too much typing for me, you can do a lot using generic constraints, interface implementations and static functions though.
May be. It looks like I'll need rewrite it if I want to use burst anyway ๐คท
Alright, thanks.
Running into burst issues as well, huh? ๐
yup. I forgot that I use GetBuffer() unpredictable number of times inside my algorithm
You can call into managed from burst using function pointers @cerulean forge
Or what is your use case for actions/funcs?
I don't get it. Is using interfaces in Burst allowed or not?
I'm using a struct that implements one method and see this
Burst error BC1020: Boxing a valuetype `Game.BlockProvider` to a managed object is not supported
It's allowed with generic type constraints
And your type still needs to be a struct
Yeah, just found that on forum. Making stuff work in burst is a quest ๐
Just general programming ergonomics and abstraction ๐
I already gave up and I'm back to non-dots unity programming
Does anyone here know how to load a Subscene at runtime? Do you just load itโs parent scene using the SceneManager?
Depends, do you load the parent scene anyways? Just load the entire scene (with AutoLoad active on the SubScene monobehaviours).
Otherwise use SceneSystem.LoadSceneAsync
Loading the entire scene does not seem to also load my subscene. Even if o have the parent scene open in the editor, if I hit play after Iโve closed the Subscene (which should run it through a conversion process), none of its entities will appear in the Entity Debugger.
You have AutoLoad on the subscene ticked and you aren't using NetCode?
Yes.
Both of those things are true
May be important: my Subscene is closed and unloaded.
Same result though, if itโs loaded but still closed
The only way I can get the entities to show up is if the Subscene is open in the editor, which defeats the point.
Ah, looks like the Entity Debugger just wasnโt retaining the entity names from before it was a Subscene. That makes perfect sense.
So my entity which was named โTestEntityโ in the debugger when the Subscene was open, was now named Entity 542, and it got lost in the mix.
Makes sense. Entities donโt retain their names unless immediately converted from a GO
They donโt need names
What's the difference between a system that has 2 queries and schedules 2 jobs and 2 systems that have a query+job each?
Barring dependencies.
you'll have a sync point between the 2 separate systems and a job each
Why would that create a sync point? There isnโt automatically a sync point between every system.
well yeah potentially then I guess
@dark cypress There isnโt much functional difference between the two. Iโll list some differences itโs good to know about:
- The time is takes for a system to update isnโt always negligible. One system scheduling two jobs will usually be faster than two systems each scheduling one job. But - organizationally, that may not always be the best approach. I general, I try to have one system per โtaskโ, so as long as all the jobs being scheduled by one system could be considered โstepsโ on the way to finishing one piece of work, then Iโll group them into a single system. If not, then Iโll divide them up and eat the extra system update cost.
Thank you, makes sense.
- There are some quirks to know about how Unityโs automatic dependency management. For instance: if you call ComponentSystemBase.GetBufferFromEntity<T>() for the same type from two different systems, Unity will automatically create a dependency between those systems. Jobs scheduled by those systems wonโt be able to run in parallel. But if you scheduled both of those jobs from the same system, they could.
wondering if somene could help me out please
im working in tiny and for the live of me i cant seem to scale an object up in Y
What's difference between GameObjectConversionSystem and IConvertGameObjectToEntity and which one is preferable?
Also, have someone had a problem that a single GameObject gets in conversion system twice when "convert and inject game object" is enabled? It is ok when GO gets destroyed though
Alright, it looks like my conversion system runs twice
Hmm. Fixed that getting rid of subscene since object is detected by both conversion worlds per scene.
What's difference between
GameObjectConversionSystemandIConvertGameObjectToEntityand which one is preferable?
@acoustic spire
GameObjectConversionSystem and iConvert are both run at similar times, and do similar conversion work. Technically, you could write your own conversion system which grabs all GameObject components of a type and runs them all through a conversion step, which would replicate the behavior of IConvert.
One isnโt preferable over the other, but a conversion System offers you some power that IConvert doesnโt. For example, if you wanted to collect data from all authoring components of a type, and then store some data from each of them into a single NativeArray, that would probably be much easier and cleaner to do with a conversion system.
You can also have more control over when a conversion system runs, using the UpdateInGroup or UpdateBefore/After attributes. There are multiple system group steps involved in the conversion process - for example, Unity doesnโt add โParentโ Components to entities until after all GameObjects have gone through the conversion process. Thereโs a system group which runs after that step as well. So if you need to access your entitiesโ Parent components as part of your conversion code, you would need to make sure your conversion system ran in that group.
(I apologize that I canโt remember the specific name of that group, atm)
Great answer. Thanks!
How do I make child render meshes not lag behind 1 frame when changing position on an entity?
This code makes the entities appear instantly at the desired locations, but the child render meshes of those entities are at origin for 1 frame.
I can't use empty args lambdas in a single job?
Job.WithCode(() => DrawAxes()).Run();
Zero-size empty struct `Game.DebugRenderingSystem/Game.<>c__DisplayClass_OnUpdate_LambdaJob0` is not supported. To fix this issue, apply this attribute to the struct: `[StructLayout(LayoutKind.Sequential, Size = 1)]`.
what are the advantages of Hybrid urp ? im looking at the ecs samples - Hybrid URP Samples Project
can it still be used normally without ecs , but only for specific cases like 1000 bullets run on hybrid for what i assume will have better performance ?
hybrid renderer doesnt render regular game objects it renders entities
you can use the hybrid renderer package and game objects at the same time though
all depends on what works best for how your scene is composed
I have some issues when I install dots into an HDRP preset project.
I do not have these issues if I make a 3D project and install dots and then install HDRP manually. Is there a specific order we're supposed to install these packages in to get it to work right?
should work just fine I just set up a new HDRP project and added the DOTS packages no problem the other day
are you using a beta version?
shouldnt be issues installing dots alongside an existing hdrp project, if there are and you can reproduce it, its probably worth submitting a bug report
Any one have a simple toon shadergraph shader i can test in tiny
Afaik custom shaders aren't properly supported yet in tiny. I wasn't able to get them working at least
Can i use collection as field in IComponentData?
Only the Unsafe* ones not the Native* collections
For really simple systems (eg, ForEach updating all Positions by Velocity *dt) will burst autovectorize the resulting loops?
(specifically, does generated assembly use scalar or vectorized ops?)
I have system like this and im getting problem when adding entity to LinkedEntityGroup id of added Entity always negative. So look like i should add entity to LinkedEntityGroup after playback and devide system into two jobs ?
When does it make sense to combine components ? Im currently working on a buff system... so my player has a max health and a current health. Those are two seperate components : Health{ float health } and MaxHealth{ float maxHealth }... I bet this is a bit too atomic, right ? Is there some sort of rule or guideline for splitting or combining components ?
@stone osprey there's very little downside to splitting up, so I'd say only if you can make the assumption they are always both present + always both iterated on then it makes sense to merge
if sometimes you want to iterate only health and don't need maxhealth from certain systems, then makes sense to split because iterating just health will be faster than merged
tho I guess with such small components (1 float) it's not a massive difference so architecture is worth considering too, if 90% of the time you iterate both then not worth splitting for that 10%
@hollow sorrel Thanks ^^ I guess then im gonna merge them... atleast i cant find any case where i only need to iterate over max health... and every health kinda needs a max health too for healing purposes. Thanks ๐
Buffs... well... my current approach is that each buff is one entity and gets processed by its own system. For example a physical buff system adds a certain value to the physical damage of each entity. But im running into a problem, order... lets say i wanna have a percentual physical damage buff which increases the overall damage by 10%. How do we make sure that this system runs after all buffs were applied ? Otherwhise it will calculate wrong values :/
You need to use ecb.AppendToBuffer to add a newly instantiated entity to a buffer. Only the CommandBuffer that created the entity can correctly adjust the entity id when playing back later in the frame
Also Im not sure why you aren't including your dynamic buffer in your query instead of using bfe
Why can't you use UpdateBefore/UpdateAfter?
tyvm. but how AppendToBuffer indicate for what buffer entity will belong ?
It's the second argument.
oh neat, there are finally hybrid rendering samples in the samples repo
i didnt realize lightmap baking actually was working!
@zenith wyvern Thanks that will work ^^
I bet theres no way to get around ordering/sorting systems, right ? I have a bunch of systems where the order does not matter... but those buff systems are killing me :/
You can create your own ComponentSystemGroups and order those relative to other groups as well. Should cover almost any use case.
How is SetBuffer supposed to be used? I was creating an entity from an archetype and was trying to add initial elements to its buffer. But SetBuffer does not take any data?
AFAIK SetBuffer functionally clears an existing buffer and returns it. You can add to the returned buffer
just found your previous answer ๐
I guess when instancing from an archetype AppendToBuffer should do the trick
@zenith wyvern Alright, thanks im gonna look into them ^^
@stone osprey I also just recently figured out how important that whole sorting thing is ๐ค
@pulsar jay It really is... well the most standard stuff works without sorting, like movement and stuff. But once real gameplay comes into play its a pain to order the systems ^^
but the cool thing is SystemGroups are also systems and can have conditions on when/if to trigger systems in its group. I think I will have a lot of use cases for these kinds of hierarchies
This brings me to another issue... the amount of systems... in my "buff/debuff" system i go with a pretty modular approach, that means i have a "PhysicalAttackBuff(float)" with a "PhysicalAttackBuffSystem" that loops over them to apply the damage factor. 1 Buff = 1 System... great to expand but a lot of boilerplate code. It would be great to have some scripting here, but im not that sure if its so smart to reference a "IBuff" interface or similar to replace the system logic ( IBuff{ apply(...); } ) due to the serialization later on :/ Any ideas on this topic ?
@pulsar jay Thats actually cool ๐ฎ didnt knew that, but that sounds great
I am using the same approach atm. Havent found any better solution yet. Would be a prime case for inheritance but thats "evil" OOP stuff. I guess we have to deal with the boilerplate code. Maybe script templates can ease it a bit
Not sure if interfaces work well with ecs as I guess you cannot use them in entity queries
@pulsar jay Glad to see that im not the only one with this approach... currently i requestion many of my design decisions because there so few examples ^^ As far as i now you can use them when you use a class that extends IComponentData... but yeah... actually its evil oop stuff ^^ thats why i cant really decide between both variants
but if you use interfaces do they work in foreach queries? I cannot think of a way that would work as the archetypes need a specific type to define its chunk
if you have multiple structs with the same interface they would (possibly) still require different memory layouts as the interface does not say anything about its fields
so they could not share a chunk which means you cannot query for an interface
I didnt try it but if querying does not work interfaces wont really help with reusing code
@stone osprey you can implement a generic system and satisfy the implementation of an interface on your struct
@last jasper but how would you query for components implementing this interface?
@pulsar jay pretty sure you cant use interfaces in a ForEach
my vote is to use code gen
You can't use any generics in a foreach as far as I know. You can use them in jobs though, including IJobChunk
So you can create a generic system like Elliot said and use type constraints for your derived components
Hey guys, how does ECS deal with event based stuff like effects? Lets say I want to be able to create an extendable system where different systems can apply modifiers to a player damage taking. In normal unity I'd use an on damage event and subscribe to that. How would I do it in an ecs?
Ive seen lots of people using 'event entities'
so create a new entity, add your event types, then your systems to react to the event can run
to make it extendable other systems (yours or other devs) can run before your final cleanup system runs
So I'd create an Entity with a damage event component and all systems would react to that
there is also a Event system in the unity Fourms, which are more event publisher subscriber model
yea
@fallen zephyr the issue with the event entities is there usually a frame delay
as you cant use EntityManager in a job to create entities
There won't be any delay if you don't use command buffers and you order your systems properly
You can also just use a dynamic buffer that fills with events and clear after processing if you want to avoid structural changes
I'm actually not using unity ecs
So my solution needs to be non unity ecs specific
But thanks for the help guys
hmm that sounds tricky
I think I'm going for the event entity style
That's a nice idea, I hadn't seen that before
I think the issue with that is where the dynamic buffer lives
If its a singleton entity then you could have many entities trying to write into a single buffer, meaning you cant use schedule parallel, but you could have many 'event' buffers on the actual entities
I actually use that idea, many source entities write into a single dynamic buffer
never thought of it as a event system tho ๐
here was an impl I had from before - caveat is that I did essentially move away from that pattern https://github.com/ElliotB256/ECSCombat/blob/4f98ee0afe0231e66157ccd3b95dbe466595d191/Assets/Battle/Equipment/Aggregate/AggregateEquipmentSystem.cs
Use case of the above system - you have different equipment which can be added/removed from a space ship, and modifies things like Thrust based on what the equipment is
Here's an example of a system that inherits that generic system - it defines how an Engine equipment changes Speed: https://github.com/ElliotB256/ECSCombat/blob/4f98ee0afe0231e66157ccd3b95dbe466595d191/Assets/Battle/Equipment/Engine/EngineSystem.cs
@pulsar jay so you write an abstract system, which specifies generic types which must implement your interface, then inherit that abstract system<T...> to specify the actual T. I couldn't find a way to automatically implement it for all structs implementing an interface, for that you could presumably use templates
Here's a specific example that might be of interest to you - It's a CalculateRangeEffectivenessSystem, which basically alters the strength of any Effect (could be damage, could be healing - they just have to be an entity with both LinearEffectiveRange and Effectiveness) based on the distance between user and target: https://github.com/ElliotB256/ECSCombat/blob/master/Assets/Battle/Combat/Calculations/EffectiveRange/CalculateRangeEffectivenessSystem.cs . In this setup, all actions (attacks, healing) are individual entities, which are spawned when a tool is fired or a tool is used.
someone have example of dots occlussion culling?
im not sure but i dont think thats done in DOTS
instead i think its in the render piplines
theres a sample in the hybrid renderer samples for occlusion culling
Oooo very cool
they were released fairly recently
so many new samples
True. Skinned meshes are good to go now ?
sort of? afaik its still considered experimental(whatever that means given dots is preview), and the visual scripting part of animating is kinda not there, all animation examples focus on code based stuff
I see. I'll wait more, don't need it yet ๐ Thanks
Hi all ๐ Looking for some feedback from some people fairly experienced in both dots and standard game object architecture. I'm coming back to Unity after quite a long break and was figuring since I'm re-learning a bunch of stuff anyway, maybe I should just start right into dots/ecs since it does looking its going to be the future of Unity anyway.
Is it a bad idea to consider starting now into a dots/ecs project intended to actually be released at some point or is it stable enough to potentially release in its current/near future state?
Also, are there any serious considerations that may be a deal-breaker at the moment for choosing dots/ecs?
ECS is not stable or production ready and it won't be for a long time, probably a year or two at least at this rate
Jobs and burst are stable and fine to use
I did see mention somewhere about hybrid game objects being able to fill in the gaps for certain systems not yet there in ecs. Is it pretty limited what can be hacked together with hybrid gos?
Any monobehaviour can be attached to an entity using hybrid components, and it does work well. You don't get much performance gain from that though
ok thank you. I might just stick to the standard workflow and play with dots on the side to familiarize while things develop then. Anyone else with feedback just @ me ๐
I am new to dots and I am studying the github sample project.
If I want to see the script of the system in the entity debugger, is there any shortcuts to do so? or I have search through all folders?
@sly jasper honestly i've never tried to go from unity to code with ECS
i would guess that the feature is missing
i always use Ctrl + T in Rider to go to the file
I just use ILSpy and look at the assembly
i assumed lee was talking about the actual code, not any complied/code gened ones
Yeah I just use it to browse the source code ๐ค
thanks, hopefully they can add more 'quality-of-life' features like this as promised
I've got another question:
Is it possible for rigidbody to interact with physics body?
I want to only make my bullets ECS and preserve the current gameplay/physics logics. Is it possible?
What do you mean by making your bullets ECS? What bottleneck are you trying to reduce?
I want to, say, having 10k-100k bullets in scene, but with just a few player/enemy.
So if I can make a hybrid ECS only on the bullet movement part, there are much less items I need to work on.
In order to make them work with built in physics they would need to be gameobjects, and afaik Unity can't handle nearly that many gameobjects, with or without built in physics
If you make them pure entities and do the collision handling yourself it would work, but it would be complicated. Or you could make the bullets entities and generate collision data from your scene every frame and use dots physics. It should be pretty fast if there are so few gameobjects
I think the last option you proposed is something I want to achieve, but I am not sure how to generate the collision data.
If I mark my gameobject 'ConvertToEntity', seems it lost its original component logics. If I dont make it 'ConvertToEntity', there is no collision at all.
Are you using dots physics or built in?
Installed UnityPhysics package. Using physics shape, and physics body for bullet, keeping rigidbody for player
It's a bit complicated then since you're trying to use both physics at the same time. Normally I would say use hybrid components but you can't because that requires you to give up on built in physics. I guess you would need to convert using the "ConvertAndInject" setting in ConvertToEntity and then sync the player entity's dots collider to it's gameobject position every frame.
Normally with hybrid components it goes in the other direction - gameobject positions get synced from entities. It's going to be an uphill battle doing it the other way
I see. I have some ideas now, thanks
whats the best way to disable physics simulation from a world?
note i still want to be able to do things like raycasts
but i dont need collisions or actual physics
Hi guys! Is it possible to somehow place my custom EntityCommandBufferSystem right after the BeginSimulationEntityCommandBuffer ?
Entities.ForEach((Entity e, ref LocalToWorld l)=>{ l.Value = loat4x4.TRS(new float3(l.Position.x, 2f, l.Position.z), l.Rotation, new float3(2.0f, 2f, 2.0f)); .........
can i do this
it doesnt seem to error but im not seeing any of the transformations at run time
Solved this by adding OrderFirst parameter:
[UpdateInGroup(typeof(SimulationSystemGroup), OrderFirst = true)]
@light mason that code looks fine
for a temp test duplicate LocalToWorld and set that value too
just to make sure its correct
at a guess i would say the transform system is overriding your custom localToWorld
its usually better to just modify the 'simple' types like Translation
you would need to remove those in order to manually set localtoworld
can i set scale without localToWorld
yup
really
of couse
as in Scale IComponet
2 sec and ill see if i can find it
i think last time is use Ecs that was not avaliavle
all good
How can I check if an entity has a buffer? There is HasComponent() but there is no HasBuffer(). I suppose just calling GetBuffer might throw an exception if the entity does not have this kind of buffer?
you can just use HasComponent I think
I tried but it complains that it has to be of type IComponentData
Did you try it using EntityManager? EntityManager.HasComponent<SomeIBufferElementData> works fine for me
no I am using ECB ๐ฌ
BufferFromEntity has a HasComponent method if I remember correctly
@north bay you mean BufferFromEntity checks if the buffer exists?
I am using GetBuffer but that calls BufferFromEntity internally
@amber flicker strange that EntityManager.HasComponent takes buffers but ecb does not
No I mean that the struct BufferFromEntity<T> has a method with which you can check if an entity has the buffer
yup
@north bay do I have to user IJob in order to use BufferFromEntity? Looks like its supposed to work with injection?
Or can I just create it via new:
var b = new BufferFromEntity<IgnoreTarget>();
b.HasComponent(entity);
You can call GetBufferFromEntity<T> above your lambda and use that
I am afraid I cannot. Because I get the entity I need the buffer from from a component in the lambda
What do you mena? Did you use ComponentDataFromEntity before?
It's just an access wrapper around the component type
Just figured out I was wrong. In this case it should work as I need the buffer from the current entity
Entities.ForEach( ( Entity entity, in Comp a ) =>
{
if (whatEverFromEntity.HasComponent( entity ))
{
}
} ).Run( );```
yeah thanks this should work
I just thought I was needing the Buffer not from the current entity the system iterates on but from one referenced by a component
so in this case it would not be possible do get the buffer before the lambda
It would
GetBufferFromEntity doesn't care what entity you pass to it
It doesn't even know what entity you iterate upon
Oh I see I have to pass the entity later on ๐
It is just so confusing as the name implies that it is getting a buffer (like right now)
So that works thx
Maybe another small question: Is there an easy way to copy the buffer onto another entity?
What I am trying to achieve is copy the buffer to a new entity and add the current entity to it
Its basically a history of entities that have been "visited"
Currently I just itarate it but maybe theres a better way?
var ignoredArray = ignoredTargets.AsNativeArray();
foreach (var ignored in ignoredArray)
{
ecb.AppendToBuffer(entityInQueryIndex, entity, ignored);
}
Looks fine to me. Though depending on your setup, instantiating an instance of the existing entity may be quicker.