#archived-dots
1 messages ยท Page 182 of 1
here's a list of packages you can't get just in case you need it
(apologies for the B R I C K of text, couldn't get spoilers to work :()
you know what this link does a better job
was this mentioned here?
All DOTS packages are scheduled for new releases the week of 27 Oct
kinda weird way to put it but they probably just mean some time during next week
there was another post mentioning end of oct which I linked but good to have a specific week... feels more likely to actually happen ๐
there's no week left in Oct after next week though ๐ but I guess now we know it's not happening this week
Imagine waiting 1 whole week for a new releases...
crossing fingers that enable/disable components is now added
I'm guessing it's mostly the rework of codegen stuff? don't understand why they can't say what's in 0.16.. so frustrating
I was just about to test few things in unity physics perf wise but knowing this I'll just wait for next package
imagine if they had like open development in github :p
it feels like some key people at Unity like to surprise users rather than do the dev openly
Hey guys I have a doubt regarding installing Unity
when I install unity it automatically installs 32 bit version but my computer supports 64 bit version. So, can someone please help me how to download 64 bit version of unity.
what
First off, this is the wrong channel for that
But second, are you using the Unity Hub or direct download?
afaik there isn't even 32bit version of Unity editor anymore
it's been 64bits since Unity 5?
I want a 64 bit version
that's like.. since 2014 or something
How do you even do a direct download?
you can get direct download for installers
but when I download from their site automatically 32 bit version is downloaded
just download unity from the unity hub
TBH you should probably download the Hub from
https://unity3d.com/get-unity/download
I really suggest you to take this discussion to #๐ปโunity-talk
this is totally wrong channel for this
But yeah, that too - the hub should work, and if not, try #๐ปโunity-talk
k sorry for that
I'm only saying this because it really sounds like there would be tons of beginner follow up questions to that
just added to that post asking what the high level changes we should expect are ๐ ๐ค ยฏ_(ใ)_/ยฏ
hope they update everything at same time (physics package etc)
I was about to say that "all dots packages" doesn't necessarily mean physics ๐
in past they've treated it bit differently
but one can always hope
there was another post mentioning end of oct which I linked
@amber flicker you still have this link?
I tried to scroll back a bit but didn't spot anything
ty
wonder if we'll get that DOTS blog post once we get updated packages :p
I did read the comment from Joe on the forums earlier
(about blog post taking some time still)
might have missed that - have a link handy?
ah yes I had read those, thanks
hmmm We have more than ~60 engineers full-time working on DOTS.
anyone know if you can set a specific GameObjectConversionSystem's target world? instead of the DefaultGameObjectInjectionWorld
IIRC the gameobject conversion happens in two steps:
- It creates a new world and builds the entity there
- Then it copies the entity over to the main world.
What you want is to get that temp world in #1? Pretty sure you can only do that in conversion scripts
I don't know the answer. Reminder that these api's are fairly unfinished and it's not necessarily a supported use-case. But maybe it is. If you did the above then copied all entities to your custom world, I guess you'd then destroy that conversion world and hope the system that would have copied it to main doesn't run? Guess this journey will take you through the source code. Otherwise maybe it's easier to mimic what the conversion stuff does - creating a second temp world for conversion yourself then copying back?
As always, depends on the use case - what are you trying to accomplish?
thats a long name
copying to a different target world in #2 would be fine too, just wanna be able to specify it on a conversionsystem basis
if i do the conversion manually like timboc said i think it's doable (without subclassing GameObjectConversionSystem) but if there's a built in way that'd be easier
as for the use case, i've got a simulation world and a render world, just trying to get something to show up in render world directly without going through simulation
anyways, how do i set center of mass from code in unity physics?
@maiden delta the PhysicsMass component has a centerofmass property
Entities.ForEach cannot use component access method SetComponent that needs write access with the same type Translation that is used in lambda parameters. why? im setting translation of the other entity
guessing it's because you pass Translation as in but are also setting it
in = readonly
ref = also write
thats dumb
the safety check or whatever this is needs to be somehow adjusted to check if it's actually the same entity
how is it going to know the entity you're setting isn't also in the same chunk
@maiden delta just remove the in parameter and use GetComponent to get it from your current entity too
yeah thats what im doing @rancid geode
is there a better way to structure getting information out of entities.foreach? I am creating a nativeArray is there a way to know how big to make the array ? i feel like i am missing something
Get structure information out of foreach?
yeah
If you mean get amount of entities matching a query, you could use the entityquery estimate count thing, I think?
But also, nativearrays apparently rescale if needed? No idea if that's safe, but honestly I'd just start it off at a good estimate
So to begin with, intentionally make it lower than it needs to be (size 0?) and see if it explodes
that's what im going currently, the calculate
if it doesn't, then you can safely use a "probably big enough" size
oh they do?
The docs said something about that, or rathjer implied from the methods they had and stuff
yeah that would be fine, just didn't know if there was a way to get an exact count prior
There's also:
EntityQuery query = GetEntityQuery(
//Your components here
);
int count = query.CalculateLength();
It does say estimate, so not sure if it's guaranteed to be accurate
Back with some design questions :/ Im trying to design some sort of inventory-items relation. Inventory is attached to the player and item is its own entity. So the inventory is pretty much only a list of entity-ids. I want to react to "changes" or "events", for example when the item was modified ( amount... ) or when a new item was added to the inventory... Would you use events for this ? Or would you simply mark the entities ? // Mark Item, Mark Inventory... {Item, Changed} => ... {Inventory, Changed} => ... ? What would you stick with ?
One problem is that when i mark the inventory entity with "Changed", i dont know what item exactly was added, removed or modified
@stone osprey what kind of things do you want to happen in response to the event?
@amber flicker Debug logging, Applying of effects that modify stats, sending network packets, marking entities for being saved to the database, merging of items ( stackable items ) :/
I think some people might go the events route. In particular I think Tertle said he mostly used his event system for debugging. I would probably do these all with Tags/Components. E.g. InvetoryUpdate { bool Enabled } - when enabled effects/stats are modified/recalculated, network packet is sent, items are checked if they can be merged.. maybe?
@amber flicker Thanks, thats properly the right way ๐ Any tipps on storing what item was "modified", added or removed in the inventory ? Should we just store them in a several component like "AddedToInventory{ list of entities }" ? ^^
I think (it depends) I would try and make things independent of what's been added. When does it really matter?
That sounds logical... so instead of listening to to the inventory, we would attach the logic we wanna execute to the item itself... thats a lot cleaner, thanks ๐
I don't know about attaching the logic to the item - perhaps that's a good idea ๐ - more just that I would try to make things work without requiring a pre-existing state. i.e. rather than have a system that adds/removes meshes to a character based on what's equipped, have a system that sees the equipment has been updated, set all those meshes to be enabled and disable anything else. Stateless basically.
Ah i see ๐ well that would fit perfectly in this situation... an ecs architecture just offers so many different ways... its kinda hard to keep the overview ^^
totally.. just to add my usual caveat... I don't see myself as an expert, just offering up how I'd think about it.
@amber flicker And thats totally fine ๐ Im glad for any feedback and thoughts... this is the only way to improve ^^ I had a time where i coded everything like i wanted ( or thought it would be the best way ) and it turned into a real mess ๐
@tawdry tree Forget about it, Iโve given up on DOTS. Iโm still gonna try to implement a slower custom ECS in my game. It should take less long to implement.
@foggy stream You could probably look into Entitas for C#
@dull copper did that number seem more or less than what you were expecting?
@stone osprey Thanks for the link, Iโll take a better look at whenever Iโll use it or not later.
@safe lintel it's a lot but I do get they have people split into numerous teams and only fraction actually work on ECS core itself
TBH ECS core is quite usable already. There are points to be improved (enable/disable, anyone?), but what stops most people from doing anything useful with ECS now is all the auxiliary libraries for physics, animation, and whatnot
scope of the game matters a lot
the enable/disable thing surprises me given how many people kinda seem to make it sound like a huge issue vs say like audio, animation, pathfinding etc
its not that big of a deal, but everyone is obsessed over performance. wanting to get rid of the tag component chunk copy cost
Enable/disable is just a nice convenience feature really, and one I can't imagine being too complex
but it doesnt work on 1mill/frame REEE
what about, ya know, doing the rest of your game structure where your gonna loose the rest of your perf first?
im more in the camp of give me features ๐ฉ
yes
UECS needs a bit more features
I wish the internal type manager was easier to work with for networking
ended up going with hand rolled codegen
Physics and animation should at the very least work, and work easily, since those are oh I don't know, used in 90% of projects?
yep
need a #srplife equivalent for dotslife
tbh the whole build your own srp if urp or hdrp doesnt work seems like a massive undertaking, i dont understand how anyone could really look at it and think it looks like a good place to roll your own given how long its taken unity to get to where they are with either rp
I'm more in camp of give me proper editor experience
as for custom srp, it's not really meant for average indie dev to roll their own solution
I don't like core rendering systems being in slow c# instead of cpp
how I see it, it's only a thing for people either interested on fiddling with renderers or bigger teams that have dedicated people building this tech
been digging though a lot of unreal the last few weeks and damn I wish we could just interface with unity though cpp
yeah fixed workload games, where you dictate what shader passes, shader workload you might have
cpp is not very nice to iterate code with
its perfectly fine
spend a little more time in unreal then ๐
I mean, you wait for it to build something all the time
nah I can't stand the data size
on my internet I've wasted 3/5 work days last week just waiting on uploads and builds
i would imagine any big company wanting to take this on a significant custom srp would probably just go with their own engine entirely?
I'd love to have c++ api on Unity too, but mainly because it would be nicer for native plugins
some companies dont want to switch from unity
as for proper editor experience, id like to see this too but this also seems really far away
shader compiling was far longer than cpp build times in unreal, the last several weeks. the raw engine build did take 45min though. but that was once per type (debug, shipping) @dull copper
you'd really want some high end rig for ue4. shader compilation times are tolerable on high core count cpu's
I think I last timed 4.22 or 4.23 for raw engine build and it was like 1h 15m on my old i5 and 20 minutes on ryzen 3900x (13 minutes for actual engine rebuild without tools getting rebuild)
you can imagine the time savings on the longer run on faster computers if you work with unreal
I'm actually most impressed on the improvement on 3900x for those shader compilations, they used to take forever
can only imagine how fast it is on modern threadrippers
for sure
on my old xeon server it isn't very fast either doing CLI builds
but I think unity builds should be faster (il2cpp)
actual cpp builds have been MT always on windows afaik but not the conversion, it's been single threaded before
yeah it was
relevant thread https://forum.unity.com/threads/il2cpp-player-build-time-improvement-coming-to-2020-2-0b2.963614/
ty
For 6-8 core machines the conversion process will see roughly a 60-65% decrease in conversion time. On a 64 core machine conversion time decreased by 73%.
not the best scaling for a lot of cores apparently ๐
yeah I know ๐ still funny how it goes
in DOTS you even get worse perf the more cores you give to it :p
so it goes negative
yeah stupid ass scheduler
I'm still hoping to see them allowing us to limit max worker amount per schedule etc
or per system, whatever makes more sense
I'm currently dialing back most of my ecs systems, shifting to managers scheduling bursted jobs
yeah that would be nice
or them redoing the scheduler totally
theres a lot of other ways to do it than just work stealing with a DAG
wonder if the scheduling is on their radar
I think it is, remember seeing them working on it to make the cost less
I think so too
pretty sure Joachim mentioned they are going to handle the non-bruteforce cases better as DOTS needs to perform on lesser scale simulations as well
and Physics talk from Unite Now did say they want to be able to run Unity Physics at user set worker thread count which wasn't possible by the time they made that video
we all know that DOTS can be nice for brute force simulations but I need it to do regular gameplay scenarios well too
yeah saw that earlier, im really skeptical of what the non dots version looked like
I'm going to go and guess it was just some trivial setup where they did it single threaded
and not using TransformAccessArray etc
stop spinning cubes! make meaningful tests!
we should have some bot that does inverse for fps every time you type it in gamedev context :p
yes
is it possible to have mulitple sharedcomponentdata on one entity?
yes
thanks
one other question
is it possible to avoid this if i want to get some information from a shared component without sacrificing ScheduleParallel()?
is there a way of storing a reference to the sharedcomponentdata on another component or something so i can access it?
been awhile since I did, but yeah you can, it involves caching the shared components into a array for the job
@shy pilot most of the time I advice to just use the jobs structs instead of Entities.ForEach
also, you can't have reference types in jobs outside main thread
so if your shared component is a reference type then it'll have to run singlethreaded on main thread
which looses the point of jobs really
if there is some way you can make that type a value type I would strongly suggest you to do it
and no you shouldn't ditch SystemBase
ok @zinc plinth so you're suggesting i just turn my component into a normal IComponentData and just deal with having all that wasted memory?
can anyone provide an example of entities.foreach-like behaviour in a job?
you can completly have value type shared components
i just can't access them from within a parallel job?
create your struct, copy your shared compient inside the struct as you would for any other value type/native container
the restriction is on reference type, some value type data comming from a shared component doesn't matter at all
in the job if i try to do this
NativeArray<SpeciesSharedDataComponent> speciesComponents = chunk.GetNativeArray<SpeciesSharedDataComponent>(speciesTypeHandleAccessor);
i get a boxing conversion error
hmm
does anyone know if it is possible to store an array inside a component (not on an entity with a dynamicbuffer)
can you just declare a dynamicbuffer from within?
Well you can store a pointer inside a component or an UnsafeArray inside a component, which you can treat as an array - you'll need to manage the memory when you destroy the entity - so you can dispose the memory allocated
hmm
can you just do something like this?
public struct TestBufferComponent : IComponentData
{
public DynamicBuffer<FixedString64> fixedStringBuffer;
}
No
Well truthfully I've never tried, but I imagine you might need to figure out how to allocate a buffer inside a component. Not sure if there's any convenient functions to do so.
You could do
public struct TestBufferComponent : IComponentData
{
// Just need to manage this UnsafeList to free up the memory
// when you don't need it
public UnsafeList<FixedString64> fixedStringBuffer;
}
Is there a reason you can't just use an IBufferElement/DynamicBuffer?
if i've got one value (like maybe an int or float) that i use in jobs that's the same across the project, would it make sense to turn that value into a shared component or would my current approach of having a manager monobehaviour (for editability) be better?
do you think this one value would change?
if not, and it's constant, then yeah go for it. make it a shared component.
im getting
IndexOutOfRangeException for IJobParallerFor in ReadWriteBuffer
are we limited to the specified range given per batch ?
public struct ComputeNormals : IJobParallelFor
{
[ReadOnly] public NativeArray<float3> verticies;
[ReadOnly] public NativeArray<int3> triangles;
public NativeArray<float3> normals;
public void Execute( int index )
{
int3 triangle = triangles[ index ];
normals[ triangle.x ] = math.cross
(
verticies[ triangle.y ] - verticies[ triangle.x ] ,
verticies[ triangle.z ] - verticies[ triangle.x ]
);
}
}
Fyi โEnable / disable component feature is planned to land sometime in Q4 2020โ
wdym
Fyi โEnable / disable component feature is planned to land sometime in Q4 2020โ
@amber flicker hope it's true! I need that in my life!
i added [NativeDisableParallelForRestriction] and it seemed to solve the error , anyone knows what is it and how does it impact the performance ?
I really dislike the most that we don't have any kind of dots roadmap, even for things that are actually on their way already
I can see that they don't really have a solid plan they can share and things change all the time but they do know what's coming up in near future
would be nice for users to get heads up on these so they don't create complicated workarounds for things that are about to get fixed on next release
what are the downsides of using NativeDisableParallelForRestriction ?
@hollow jolt mostly that if you write to the same index from multiple threads, it's not guaranteed what data you'll end up with. So you only use that attribute when you are sure you're not writing to the same index from different threads.
i see
IJobParallelFor shouldn't call the same index twice , doesn't it ?
When a worker has finished all its work, it looks at the other workersโ queues and tries to process some of the items assigned to another worker.
^ IJobParallelFor
is that what u meant ?
@hollow jolt when you pass in those NativeArrays, you could write vertices[0] = 3f; and it'd set that index in multiple jobs, possibly at the same time, so unity's safety check prevents you from that possible scenario
if you only use the index of parallelfor it's not gonna set the same twice, but unity doesn't know that, so that's why you have to disable it manually
brilliant , thanks
was looking at mathematics source and there is a bunch of aggressive inlining, any advantage of using that over inlining the same thing directly ?
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator / (float3 lhs, float rhs) { return new float3 (lhs.x / rhs, lhs.y / rhs, lhs.z / rhs); }
Hi,
Is it possible to make entities using Unity Physic collide with object having collider in an Hybrid System ?
A bit more of an explanation.
I'm using Mixed Reality Toolkit (MRTK) and I play with Unity DOTS.
MRTK provide a spatial mesh with a collider, but this is not Unity Physics. I have some characters and want them to walk on this spatial mesh, but they are using Unity Physic.
Is it possible to make the characters walk on the spatial mesh ?
@quaint niche you'd have to convert the collider to a unity physics collider
Is it possible (or does it even make sense) to reference other components in a component or is it only possible to reference other entities?
For example if I collect a Dynamic Buffer of enemies I guess it would have to be a list of Entities or can I somehow reference e.g. Health components directly
I feel that components referencing other components is creeping into OOP, imo
then again, it IS convinient
IComponentDatas are value types... bit weird to think of a float referencing a float (in a general sense) for example
@hollow jolt afaik AggressiveInlining means at compilation time the content of the method is copied in place - avoiding the overhead of the function call. For heavily reused methods this can add up. One downside is it can confuse VisualStudio line number navigation.
Hi all. What the right way today to authoring IBufferElementData with Entity field (1 field)? I thought GameObjectConversionSystem.GetPrimaryEntity(UnityObject) will work. And it works if converted entity was with option Convert and Destroy. But it won't work with option Convert and Inject GameObject. What a black magic?
So you have a GO you're converting
And you want to grab the entity struct from the converted GO...
And save it on that same entity?
Or am I misunderstanding here?
I have some GOs in scene that will be converted. One of them need to grab others and save on himself. I tryed to play with it and find out that it problem happens only if linked entities are childs of converted gameobject
The conversion workflow in general does not like hierarchies, IIRC
I'd rather know this beforehand๐
I don't really understand subscenes it seems like I can't use them to get access to the entities converted in them ๐
@deft stump @amber flicker thx makes sense. Just wanted to make sure that Im not missing something
want little page in dots docs with just one string "And remember NO HIERARCHIES"
that's not particularly true about hierarchies and conversion workflow. That said, it certainly isn't seamless. In particular, Convert & Inject has some quite unintuitive behaviour imo - I would always try and avoid specifically that mode myself.
@pliant pike wdym?
I think I get it I cant have an empty object and then have a bunch of scene items within that
Don't really understand that.. but ideally you don't want to be creating a hierarchy if you don't need one
yeah I didn't realise that
its just easier to put a bunch of your scene objects into an empty object and then right click create subscene
I understand it can be useful for grouping. FYI you can right-click a selection of gameobjects and create a subscene from everything selected.
Regarding hierarchies I found that having them for debugging reasons while developing helps. The hierarchy in the new entity window helped me a lot compared to the entity debugger
It would just be great if it could also show a hierarchy by linked entity groups and not just parent/child relationship
yeah its confusing when the converted entities don't appear in the entity debugger
I want to ask some questions regarding Hybrid Renderer V2
In particular about the giant computebuffer
I understand the basic gig: fill that giant compute buffer and then sample per-object/entity data from it.
Kinda a bit like SRP Batcher's per-object cbuffers that are being bound with offsets.
Correct me if I'm wrong.
However, I don't understand how it works exactly.
Imagine this: we're in a vertex shader and we wanna get an L2W matrix. Nice of, say, URP to define those for us, right?
But it's sampled as a macro and the whole way through there is not a single variable that determines the address offset nor strides
Finally, I don't understand how the computebuffer is laid out internally.
Let's imagine a hypothetical situation that we have 9000 materials that just use per-object data (say, 7 float4 for ambient probes and an L2W matrix)
Now, let's create (or better yet, load from an assetbundle) a material that has one per-object override for material's color/secondary color/normal scale/etc. What happens now?
Would you rather use extensions, component methods or some sort of ecs events to modify a certain entity/component ?
My case : Working on an inventory mechanic, when an item gets removed, added or updated i need to mark that entity and the inventory entity itself. I need this quite often so im not sure if i simply should duplicate that code, put it into a extension, component method or create a ecs event for this operation
By "quite often" I assume you mean done from several places in the code?
How often does it happen in terms of perf, though? (max and average) Several times per frame? Once a frame? Once every few frames? A couple times a sec? Once a sec? Every few secs?
Using an event sounds like it might be the most "correct" way to do it, but also like probably the most PITA way to do it. You should most definitely not duplicate the code, if nothing else make it (a) static method(s) (possibly extension). Component method also sounds like it might make sense, but that sounds closer to OOP than you might want to go. I'd say it's probably fine if a utility kind of function, but would prefer it in some outside function, and write it as functional code (meaning, no state change, just data in/out)
question: is Jobs and/or Burst Compiler a part of DOTS and therefor in development-stage or is it production-ready?
i think Jobs and Burst is production ready
@fringe sinew I'm curious as well actually. Maybe let's ask in DOTS forums
I'm currently looking at the code. With pain and the help of a rubber duck I could peace quite a bit of it.
it's a bit convoluted, I'm still trying to figure out how memory is managed (specifically with entity archetype chunks).
On GPU, this whole thing is extremely simple if you get past the macro-filled hell of an hlsl file for DOTS Instancing
Your shader gets a CBuffer that contains metadata about properties. You also get an instance id (this one seems to be set up under Unity's hood).
Metadata describes the start memory address of properties block and if it's overridden with a component data (if not then tries to point to default data).
By using metadata info and the instance id you can look up the address of the final data in the giant ComputeBuffer.
are there any good up-to-date tutorials/resources for learning dots ECS aside from the entities package documentation? the ones I've found so far seem to use deprecated APIs so I'm not sure if they're still relevant
Anyone know how to get a terrainMesh into an ECS system? I need the bounds and a few heights. Mega appreciate any direction here!!!
Hello, i need GetHashCode at parallel jobs or Random function. I have tested unity mathematics random , but it is not working correctly when i set different seed on each job of parallel scheduled job.
Can i generate random number base on perline noise?
Mathematics random, always generating 0 between 0 and 2. But the seed is different.
@radiant sentinel as far, as i can see Unity.math has some kind of Perlin noise, but don't know how to set a seed for it. only thing I've tried on dots is this tutorial:
https://www.raywenderlich.com/7880445-unity-job-system-and-burst-compiler-getting-started#toc-anchor-001
you have to set the random number back to itself for it to work correctly I believe
like in this tutorial https://reeseschultz.com/random-number-generation-with-unity-dots/
How to idiomatically generate random numbers in Burst-compilable jobs with Unity DOTS.
this code snippet seems to be for the perlin noise private float Noise(float x, float y) { float2 pos = math.float2(x, y); return noise.snoise(pos); }
@pliant pike thx.
hm, so the jobs system can also be used for stuff that does not run between update and lateupdate, right? like to split terrain generation on multiple cores, which happens when you move on and the code needs to generate new chunks
hello. I tried asking this netcode question in #archived-networking and it was recommended that I post my question here instead.
any help would be appreciated
Hello, I'm following this doc about writing shader in URP (https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@10.0/manual/writing-shaders-urp-unlit-normals.html) and this specific shader is to visualise normal vectors. I've created a material with this shader.
The sphere on the left is a game object with a ConvertToEntity component and the sphere on the right is created in code with the following:
var entity = entityManager.CreateEntity(typeof(Translation),
typeof(Rotation),
typeof(RenderMesh),
typeof(RenderBounds),
typeof(LocalToWorld));
entityManager.AddSharedComponentData(entity, new RenderMesh { mesh = mesh, material = mat, });
Assume that the mesh is the same primitive sphere mesh and the material is the same material. Any idea why I'm getting different results?
so i.e. I want to draw some chunks of a mesh (lets say 27 meshes), i could use a ParallelFor job with Execute (int i) and this execute, i put the code to draw one chunk, right? (i is the index of that chunk)
i is the entity index (in a ParallelFor job)
or rather, the index of the iteration you're currently in
it can be the entity index, if you set it up that way
if you want Chunk based jobs, look at IJobChunk
what's the best alternative to dynamically sized lists when using Jobs ?
im guessing using Linq's Append on NativeArrays* would slow it down too much
NativeStream should be what you want
when using writer.BeginForEachIndex( index ); then writing data into it there is no need to keep element size consistent per index , is that true ? ( ie performing different amount of write calls per index )
Looks like stream can't read/write from the same index multiple times , is there anything else i can use similar to a List that can be resized ?
What's the use case? Is this data on entities, or collections of unknown size to be used within the job(s)?
Just gonna point out that NativeList<T> is a thing. If it is not default, you can find it in the collections package.
[unity.netcode] What's the best way to get the prefab for a specific ghost. Should I create an enum for the indexes that reflect the ghost collection?
I will award 10,000 e-peen points to the one who answers my question
uhh, don't understand, what's the differnence between iterating through single objects (or blocks) or chunks of them. it should be quite the same, from code.
i really have to check, what this is all about
my understanding of chunks is that it's a mechanism to support optimization by letting multiple systems run on the same chunk
but if every system is using a unique chunk then it doesn't really do anything
if i iterate through each block by index or through each chunk of blocks, each has an index i - and some code to execute then inbetween serially.
(but I'm kinda a newb so take that with a grain of salt)
oh, that I don't know sorry
hmm
so you mean, IJobChunk could split up the sub-indices to different trheads, so normally think of entity and chunk. so it can split up the entities in addition to the chunks?
the point in my case, i need to have each calculalte each block after the other, otherwise the shared vertices won't work.
that's why i want to have like 5x5x5 chunks and each chunk should be done serially, but the chunks can be done in parallel. that's the idea.
a chunk is a block of memory. A chunk can only store entities of one particular Archetype.
Archetype: An entity with a Component A has a different archetype then e.g. an entity with a Component A and a Component B.
This (chunk) block of memory is filled with as many entities as will fit, contiguously. The more components your entity has (and the bigger they are), the fewer can fit in a chunk.
Now you have all the data packed together, the cpu can load the whole chunk into L1 cache at once - so it's now able to operate on those entities very fast. This is really important.
An added bonus is that it gives nice sized chunks of memory for each worker thread to work on separately. E.g. thread 1: process chunks 1-4, thread 2: process chunks 5-8.
ok, what try to do is marching cubes, so by block i did not mean, memory, but visual block.
atm it is just a regular C# script, serially optimized so that it calculates each vertex only once, but it has to run block by block, otherwise it would get messed up.
if you depend on a particular order then I'm afraid neither IJobParallelFor nor IJobChunk are going to help you @steady blaze
youll have to find some way to break your dependency on order
alternatively, you could make each block its own job that depends on the output of the previous job. they wouldn't be run in parallel, but at least you could keep moving on the main thread
if you do that, you just need IJob
I meant, the chunks (areas of i.e. 16x16x16) can be processed in parallel, but the inside of each chunk serial.
hahaha, @steady blaze youre going to need to come up with some new vocabulary for your internal organization of entities. if you keep referring to them as chunks, youre going to drive everyone here crazy ๐
so, i have i.e. 5x5x5 chunks and want to calculate 125 chunks, each inside serially, but all of them parallel
"chunks" are a very, very specific thing in Unity ECS land
it's voxel landscape, they are typcially divided in chunks
right, I know minecraft calls them chunks
the trouble is, in Unity ECS, chunks refers to the way things are arranged in memory, not a spatial partitioning scheme like in minecraft
well, blocks is a little better, actually. I see in the stuff above they got interchanged. I mean theres no one forcing you, but I'd use "spatial partition" if I were you. thats a term that people on the forums use
but anyway, back to your question
but I could use IJobsParallel to calculate each chunk of voxels serially but have the chunks calculate in parallel, if I give each chunk an index i?
lol, im so sorry to do this to you, but Im immediately confused by the dual use of the word chunks again
which of those uses were referring to the spatial partition, which were referring to ECS chunks?
forget the chunks, just the IJobParallel will calculate each index serially?
nope. in parallel
i mean what needs to be done at index 0 serially, at index 1, โฆ serially, but all indices in parallel
oh, I see. it depends on how you code it but yea
or will it mix stuff up within one index?
nah, theres no magic. its not going to rip apart your forloop and hand some of it off to another job lol
I don't blame you for asking though. theres a lot of places where there is magic
ok, then it should be fine. i am just a bit confused, as it's new to me.
yeah, I hear you
i feel bad for you because that was a really easy question for anyone here to answer, but we all got confused by the use of "chunks" ๐
just a little tutorial yesterday, first contact with the Jobs system
ah, well, welcome. Its a bit of a mess in the dots world right now, but we'll do our best to help where we can
thank you anyway ๐
anyone here familiar with netcode? I just have a small "best practice" question. plz
if you depend on a particular order then I'm afraid neither IJobParallelFor nor IJobChunk are going to help you @steady blaze
@tight blade IJobChunk will only be processed in parallel if you use ScheduleParallel, you can process the chunks linearly in another thread by using ScheduleSingle instead
@rancid geode as far, as i unterstood, IJobParallelFor should work, as the code that is in Execute (int index) should run normally (so step by step) for each index, so i.e. all code for index 0 should run serially, all code for index 1 too, etc. โฆ
but there can run many indices in parallel.
or did i misunderstand something?
btw. what is meant to be a chunk in the ECS system? some kind of group of entities? only tried the jobs so for (and very basically) - will now have a look at the ECS system.
@steady blaze correct, IJobParallelFor gives you much more control over that
ok, fine then!
or did i misunderstand something?
btw. what is meant to be a chunk in the ECS system? some kind of group of entities? only tried the jobs so for (and very basically) - will now have a look at the ECS system.
@steady blaze a chunk รฉ a block of memory with entities that belong to the same archetype and have the exact same shared components (compared by values)
@slim nebula what kind of netcode? did some sockets long time ago and later unet, which is now deprecated.
unity.netcode
I want to know what's the best way to get the prefab for a specific ghost. Should I create an enum for the indexes that reflect the ghost collection?
@rancid geode ah ok, thx.
it used to create a class per ghost, but I assume that was removed to prevent chicken and egg bullshit regarding code generation
but I dunno what's supposed to replace that mechanism
in netcode 0.4
sorry, don't even know a ghost. Is the unity.netcode finally a new system or still the old?
yeah it's a dots based networking thing
I got told in #archived-networking that it's better to ask about it here
but nobody seems to use it? I dunno
I guess I'll just create an enum for now. Seems like less overhead than a tag component per ghost
if it's part of the new dots system, then it is of course interesting, as it should be future proof then
but I guess I still want to ask someone who knows. I'd prefer to use best practices
@slim nebula Do you have a link to the new networking system?
thanks! that sounds very interesting
so in 0.2 you could do var ghostId = NetCubeGhostSerializerCollection.FindGhostType<CubeSnapshotData>();
where CubeSnapshotData is the generated type for your ghost
but in 3 and up it looks like they are using a tag component?
for (int ghostId = 0; ghostId < serverPrefabs.Length; ++ghostId)
{
if (EntityManager.HasComponent<MovableCubeComponent>(serverPrefabs[ghostId].Value))
prefab = serverPrefabs[ghostId].Value;
}```
MovableCubeComponent
to identify the ghost
but
sadly i don't even know what a ghost is, but hopefully in a few days โฆ
a tag component is 2 words and 3 punctuation, then add it in the unity editor to the ghost. An enum would be one word and 1 punctuation with no addition to the editor.
ghost is a entity
that uh
has data
that gets synced between server and client
so I need to instantiate this ghost prefab, so that it's data can be synced accross the network or w/e
just trying to get the right prefab out of the collection I guess. Not sure what the intention is I guess
the FindGhostType function was not mentioned in any of the netcode changelogs so it's unclear
if i am using .ScheduleParallel() with a dependency, is it necessary to call job.Complete() on the job being used as a dependency?
in theory, if i call secondJob.Complete(), and firstJob is its dependency wouldn't it be better not to call firstJob.Complete() to give the scheduler more wiggle room?
@rancid geode yeah, but unfortunately even though its in serial the order is not deterministic. chunks could get merged at any point, thereby changing the entity order in processing
@slim nebula I'm not sure what's "best" way is, but I just created a component and attached it to my player, then checked for the existence of that component on my ghost prefabs
ok. that seems to be what they do in the sample too
it's just different than 0.2 suddenly with no explaination I guess
but I appreciate hearing your experience!
thank you
yeah I've had some bumps when upping versions and having things break as well
yeah I still got a bunch of stuff to fix I assume but just needed to get over that hurdle before I could continue
gotta delete all my serialization thingers I think?
I've also found myself wanting some additional clarity WRT the player spawning, so I've done some stuff to identify when a player is spawning "locally" on the client machine vs. the server which was helpful
yeah there was a fair amount of deletion involved in the latest bump IIRC
which I'm all for. love it
but it was nice because yeah, I believe a lot of the boiler plate we had to do before is now generated
yeah and this chicken and egg crap is gone (re code generation)
there's also no more "generate code" buttons in the ghost components, which is scary and nice
"it just happens"
"magic"
but I've not had issue yet
I'm still gaining my footing with ECS, but the last bump for netcode was a good step
by chance, have you had any issues with flickering objects when they're in your server world? and are you using ecs subscenes or the old convert components?
those are two hairy areas I've still not resolved
I'm using convert components. subscenes weren't a full solution when I last worked on it. I guess I should convert everything to use subscene stuff
I'd recommend not to yet as I ran into issues when I tried
I have not seen flickering objects myself unless I've effed up the position on random frames in my own code
I don't think they're ready to take over
ok
which is odd to me (unless I'm wrong) because the convert components are deprecated now
(still work, but have deprecation warnings)
the flickering I'm talking about is rendering flickering -- not positional
no I dunno
particularly, when something is not in shadow, it flickers between black and lit
now you got me on a roll (I've not had an in-depth convo with anyone using netcode yet!) -- how are you doing your movement code? manually adjusting the translation value?
on the server I'm using physics, on the client I'm manually doing movement to a predicted invisible object, then I'm rubberbanding to that object as it jumps due to prediction errors
my plan is to rewrite the unity.physics layer between havok and my code to handle physics prediction
the dots sample has physics prediction, but their physics are completly custom, written in the sample code
so if the player tries to walk on a moving object it'll be all messed up, but that can't happen in the demo without modifying it
anyway, then the idea would be to run physics for each prediction step
so that there's less visual rubberbanding (only due to other clients inserting commands between predicted and server frames in the client)
well, you're clearly more advanced than I in this area lol
I tried using unity physics in conjunction with netcode, and it resulted in incredibly choppy movement
and my understanding of how it all works is too basic at this point to meaningfully understand why on my own, let alone how to resolve it
but my googling pointed me to a forum post where unity devs said the two won't place nicely right now, but they hope to make them do so in the future
i mean the dots sample uses both together
but yeah there's stuff regarding physics steps etc
like
by default the server used constant physics time steps
and the client doesn't
so
if the client is pressing "move forwards"
the server might process 10 frames in a second (it's way higher, but just for sake of discussion)
but maybe the client FPS is low and they only get 5 frames
the ghost prediction system will only run 5 times on the client
so you need to do fancy things with input to ensure that things are accounted for
if the client lets go at frame 7
when do you stop processing it on the client?
the solution I did was to just have the same physics steps on the server as the client
there's some hacks you can do to get the physics and netcode to behave that way
but yeah it's not pretty
accellerating forwards for 1 second, then left for 1 second, is not the same thing as accellerating forwards and left for 2 seconds
hmm, perhaps you're referring to a different sample than I tried (it's been a while) but the one I tried to get up and running wouldn't compile for me, and I hadn't messed with dots much nor netcode at all yet, so the code was meaningless to me at the point... but IIRC the sample I used (maybe it was the FPS sample) didn't use unity physics -- it did raycasts
Is anyone really familiar with the Physics Debug Display in Unity.Physics? I am getting weird results when I calculate collision details from: collisionEvent.CalculateDetails(ref physicsWorld); but the debugger has the exact impact spot marked with an emblem, so I am curious where it is getting the data for collisions. When I run ICollisionEventsJob it doesn't trigger on fast projectiles and the impact spot is calculated to be behind the object, hiding the vfx. Does anyone know where the collision events are stored or pulled from for the debugger?
yeah. it used havok I think and custom physics. collider casts and raycasts you're right
I think it references the unity.physics package, but yeah it's not like using it
(sorry I dunno about physics debug)
oh okay, so the sample you're referencing isn't using the physics collision resolution out of the box and whatnot
if i am using .ScheduleParallel() with a dependency, is it necessary to call job.Complete() on the job being used as a dependency?
@timber ginkgo It kind of depends on what's being read/written in the jobs, but generally if they're structured nicely you don't need to call the firstjob.Complete()
So you can have your first job, do some data writing, and your second job, read that written data, and just have those jobs chained.
var job1 = new Job1().ScheduleParallel(...);
var job2 = new Job2().ScheduleParallel(..., job1);
// Maybe some other logic here
job2.Complete();
what do you mean by chained? @coarse turtle
By chained, I just mean passing in the JobHandle returned from scheduling your first job, into your subsequent job(s)
no worries
my mind inserted a "dont"
lol, thank you so much
i cant explain it lol
late onset dyslexia
brain be like
ship it!
lol no worries
i just find it hilarious that brains are so falliable
perception rather
(or maybe its just me lol)
The brain is stupid, fallible, and fallacious...
This is exactly why we have code reviews (and part of why pair programming).
"Of course it works, I made it, made sure it built, and tested it!"
"...did you really test it?"
"Yeah!"
"...cus' you forget the exclamation mark in the if, so it does literally the opposite of what it's supposed to."
"What? Huh, I guess you're right..."
vison is super bandwidth limited apparently, read this good post on HN a few days ago https://news.ycombinator.com/item?id=24821389
Also, I know what you mean but for completeness, random noise is learnable, we do this all the time.You are absolutely correct. The fact that brains learn randomness is mind blowing, and it has immense implications for our perception of reality.Let me take fellow HNers on...
// populate native array
for (int i = 0; i < gridCount; i++)
{
gridBlocksNative[i] = grids[i];
}
// create job, passing our populated array in job construction, along with other crap
GridUpdateJobOneWay job = new GridUpdateJobOneWay()
{
GridDatas = gridBlocksNative,
gridBlockSize = gridBlockSize,
stepDuration = stepDuration,
o2Viscosity = o2Viscosity,
o2ConductionFactor = o2ConductionFactor,
gridDimensions = gridDimensions
};
// schedule the job...
JobHandle jobHandle = job.ScheduleParallel(gridCount, 16, **what_goes_here?**);
jobHandle.Complete();```
I read the answer to this somewhere but i cant seem to find it again. what do i use as a dependency for the first job that I am scheduling?
just an empty job handle?
JobHandle sheduleJobDependency = new JobHandle();
ah yes, i think that's right
probable newb question here, but high level, if I have an entity existing in the world that over time will need to track certain "things" (by maybe just getting new data provided to it via a struct) -- what would be the best approach?
I've tried creating a component ThingTracker which has a DynamicBuffer<MyThing> and attaching it to my entity, but it's not coming together how I'd have anticipated it to
anyone seen this? any ideas? There's not much info go to on in the details....
hmm I guess I have some scale issue
@low tangle how can mirrors be real if our eyes aren't real
that was an interesting read
makes me think of seperated sim/render in games
none of what the player sees is 'real', it's just a small subset of what goes on in the simulation, frustum culled etc
and even that is not always accurate, like when you're rendering interpolated positions instead of their 'true' physics position
the render world is just making stuff up
exactly
it just needs to look plausible, good enough
in vr I've got to get that perfectly smooth framerate, because any stutters is obvious when its your actual vision
the actual visuals can be less detailed, but making sure the world is smooth is what tricks the eyes
yeah tru, goes even more so for vr
like with foveated rendering
player only gets like 10% of the actual information that the screen can display, rest is blurry
but that's good enough to fabricate the rest
If anyone could look over this method briefly for signs of blatant malpractice, I would be very grateful
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
it's 5 jobs being scheduled in a chain. Specifically im concerned if i am mis-ordering things in a way that will harm performance, and I'm wondering if i can parallelize things better instead of having one big chain of jobs. (I am updating results and disposing of 5 separate arrays at the very end of the method because im not sure when and where it might be safe to dispose of them sooner)
looks fine at a glance, for disposing NativeContainers you can also try chaining them like so:
someNativeArray.Dispose(prevJob);
someOtherNativeArray.Dispose(prevJob);
so you dispose those tempjob arrays at the end of a scheduled job
another thing that I've done when just using Job structs, is just complete the jobs structs at the start of the next frame.
so in the Update call:
JobHandle prevJobHandle;
void Update()
{
// Complete the jobs from the prev frame at the start of the call
prevJobHandle.Complete();
// Maybe take the data from the jobs and apply them to w/e
...
// Schedule all the jobs
// Schedule Job1 and 2 to run indpedently
var handle1 = new Job1().Schedule();
var handle2 = new Job2().Schedule();
var combinedHandle = JobHandle.CombineDependencies(handle1, handle2);
// Let Job3 wait on Job1 and 2
prevJobHandle = new Job3().Schedule(combinedHandle);
}
very interesting
In the profiler, you'll see the jobs scheduled while the main thread is running so it's not a blocking call
i am doing this in fixedupdate, could i still gain from that strategy?
afaik, i could still see a benefit right?
yeah - believe so (I haven't tried directly with fixed update)
but I don't see a reason on why it wouldn't work
i can see it being hugely useful in Update()
as far as i understand the unity loop, still will be useful to me
thanks so much for the guidance! I'm going to implement this
np
yeah that main thread looks like it's waiting for the jobs to finish
quick question
where should i declare my native arrays?
does this imply a persistent allocation?
It depends on the allocation type, for persistent allocation in a monobehavior, I put it in Start/OnEnable and release them in OnDisable
For TempJob, i usually just declare them before my job structs
oh ok i see. i can use the results, dispose them, and then re allocate them again
and if I want to deallocate them in TempJob, usually a DeallocateOnJobCompletion attribute in my final job struct or I do prevJobHandle = someNativeArray.Dispose(JobHandle);
im actually wondering about allocation: i am running these jobs over and over again every tick; they're technically persistent
but i was told using tempJob should still be superior
I believe there were a few blogs lying around on the performance of the different allocations by jackston durnst, but I haven't done direct tests. So it kinda depends, I've used persistent allocations and ptrs if I needed to share that data outside the MonoBehaviour
all of the jobs are using shared data to some extend, and i do have a crap ton of other monos accessing these data...
is this possibly the kind of situation where accepting a persistent allocation makes sense?
probably
i am declaring and populating huge arrays every tick afterall
this has felt very wrong lol
yeah might make sense, to use a persistent allocation ๐
jobs are fun lol
@timber ginkgo one thing with TempJob is that they automatically deallocate after 4 frames, so hypothetically if someone has your game running at a uncapped/high framerate to the point theres more than 4 between fixedupdates, it will throw errors
yea its a big pain, i dont get why they tie allocations to render frames, its used in a couple unity systems too like entitycommandbuffers, very annoying
started running into those errors after getting a 240hz monitor
poor unloved physics nerds lol
hopefully that won't be a thing forever (https://forum.unity.com/threads/how-to-survive-without-smart-pointers.990608/#post-6436235https://forum.unity.com/threads/how-to-survive-without-smart-pointers.990608/#post-6436235) but I'm not smart enough to understand full implications of that post
ah smart ptrs ๐
not sure if this is related, but i am wondering if i really need to apply results and cannot just try and expose the native array to other monos lol
pretty sure unity will whack me on the head or that
like, if i have this dedicated persistent array stored in memory, do i really need to keep and constantly update a managed copy for normal code to access?
I guess the question is: do you need the managed array?
my only worry is about parallel access conflicts that i dont yet fully understand
i think i get the gist when it comes to jobs
not sure what will happen when stuff starts reading from broader parts of the unity loop
yeah you might run into a case where MonoBehaviourB accesses the persistent NativeArray<T> but Job1 is still writing into it
if the native array can act as a readable and writable public array, then i wont need managed
or at least modifiable
hmm, well you can always try double buffering but im not sure how big your data set is
so you always have a complete copy that you can always read on, but it means you end up having 2x your allocation
one for read, one for write
right now im at like 50MB i think
i would probably be crazy to go 10x that
(given what it would reflect in terms of rigidbodies)
I might need to double buffer in any case; the grid update job has internal buffers that it is using presently to make the update logic be order independent , and i am forced to complete this job first so that other jobs can read or work on the data
If i am really careful, i should be able to use one array as the buffer being updated, and then switch to updating the other one on the next tick
after making the arrays persistent
this isn't crazy right?
{
materialPositionsNative.Dispose();
windDatasNative.Dispose();
heatDatasNative.Dispose();
gradientDatasNative.Dispose();
gridBlocksNative.Dispose();
}```
(i mean, i should handle this on scene transitions, but this is the basic idea right?)
otherwise it would cause a small leak?
Yeah that should be the idea
though if you disable the gameObject, would you end up reallocating when you re-enable your gameObject?
that might throw an error or warning
@timber ginkgo I've always had better perf with persistent arrays when I need it on constant basis
it does make sense too
so guys
i'm a bit confused
i've been following codemonkey's quadrant systems tutorial for dots
and he uses a NativeMultiHashMap
but wouldn't it be much easier to use a normal NativeHashMap<NativeList>?
is there something obvious i'm missing?
You cant have a native collection of a native collection
is there a way to being trying to understand the Burst Inspector without knowing ASM, or should i start to learn ASM a bit? i have (what i thought to be) a medium complexity job, but the Burst Inspector shows hundreds of lines of stuff. afaik, less is better, right?
Asm is always more lines than the higher level code
https://forum.unity.com/threads/hybrid-renderer-v2-0-4-0.847546/page-9#post-6444188 - hybrid renderer 0.10 due 27th, 0.11 due 3 weeks after that
I added physics bodies and shapes to my tiles and now I get this error: "InvalidOperationException: The BlobAssetReference is not valid. Likely it has already been unloaded or released."
Are you converting at runtime?
yes
No idea if that's supported. It might be but it might be why... if you're not doing any blob manipulation yourself.
is this connected to the BlobAssetStore I use to create the conversion settings?
because I just use it for instatiation via: using (var blobAssetStore = new BlobAssetStore())
so it gets released directly after prefab conversion
No idea how BlobAssetStore is supposed to work outside the context of a subscene (if at all) - should be easy for you to test. e.g. do you still get that error if you remove your code?
well if I remove that part of the code there will be no instances at all
as long as there are no instantiated tiles it does not have errors
wrong channel @spare flare (if there is a right channel for this) - my suggestion would be to pay someone to make it for you
I am trying to build a simple repro case
I just found out that the Prefab int the public field gets destroyed on conversion. Is this expected behavior?
Entity entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(this.Prefab, settings);
It makes sense for scene objects but prefabs?
Guys, I'm a bit confused. Can I use jobs to spawn normal gameObjects as part of a pooling system or do they need to be entities ?
Guys, I'm a bit confused. Can I use jobs to spawn normal gameObjects as part of a pooling system or do they need to be entities ?
@mild ledge I think jobs wont help you with that as the standard Unity API is not thread safe
Even entities cannot be created in jobs. You can only fill a command buffer that is executed later
I just found out that the Prefab int the public field gets destroyed on conversion. Is this expected behavior?
@pulsar jay Ok that was just a stupid mistake. Accidentally selected the scene instance instead of the prefab which gets converted and destroyed as expected
hello i have this link to know about random generation
https://reeseschultz.com/random-number-generation-with-unity-dots/
but there is some problems.
- i have different len of entities at each frame.
- i have not random seed and i should change seed every frame.
can you help me? i want know how to generate random numbers at my jobs.
I'm looking at 2021.1.0a2 release notes, a bunch of these items were already in 2020.2 betas so it's pretty hard to tell without direct comparison to the notes which all items existed before
there are bunch of Burst improvements listed though
like... Burst: Add support for try/finally and using/foreach for IDisposable patterns.
Burst: A new option [BurstCompile(DisableSafetyChecks = true)] that allows per job or function-pointer disabling of safety checks. This allows users to have blessed code run fast always.
This is more of a general ecs problem im struggling with... How do we insert transfer data from one component into another one once ? Lets say we clone a "Tower-Building"-Entity, it comes along as a prefab and is filled with data already. Now our database loads a component "Structure" from the database and attaches it to the "Tower". When a player clicks on the "Tower" a system uses the already filled "OnClickPopUp" component from it and creates a popup. The problem here is that the component from the database should transfer some its data into the "OnClickPopUp", for example the structures name. Any idea how we could do that in an clean way ?
"blessed code" what, sounds like 40k shenanigans
Who know about randoms at Job system?
@radiant sentinel Here's what I do: 1. Outside the Entities.ForEach:var random = new Unity.Mathematics.Random((uint) UnityEngine.Random.Range(1, int.MaxValue));2. Inside the ForEach pass in the entityInQueryIndex:random.InitState((uint)(random.state + entityInQueryIndex));3. Get values as usual after that inside the ForEach:var randomDirection = random.NextFloat3Direction();I hope that gets you going.
Just found where I got it from: https://forum.unity.com/threads/mathmatics-random-returns-the-same-value.935318/#post-6111692 (so, thanks to Tertle ๐)
@radiant sentinel Here's what I do: 1. Outside the Entities.ForEach:
var random = new Unity.Mathematics.Random((uint) UnityEngine.Random.Range(1, int.MaxValue));2. Inside the ForEach pass in the entityInQueryIndex:random.InitState((uint)(random.state + entityInQueryIndex));3. Get values as usual after that inside the ForEach:var randomDirection = random.NextFloat3Direction();I hope that gets you going.
@glacial berry
I cant define random outside of job, because i have many entities and my seed is not a random number.
For example i want generate random number base on index of entities at each frame
@radiant sentinel if you always seed the same number each frame you will receive the same result each frame
you will need to initialize the seeds once and reuse it over-frames
@radiant sentinel if you always seed the same number each frame you will receive the same result each frame
@rancid geode
Each fram has different seed but the seed is calculated and is not random
@radiant sentinel then just use: var random = new Unity.Mathematics.Random(myCalculatedSeed)
Yes it always get me 0 from 0 to 2.
does your calculated seed gives you 2 predictable results?
I want same result on multiple devices
@deft stump @rancid geode
@radiant sentinel everytime you use a seed X you will recevive a result Y, so if your calculated seed has a predictable range (like 1 or 2) you will always have the very same result range (like X or Y)
if I understood correctly, you are using the index of entities to calculate your seed, if you are doing that all entities on index 1 will always generate the very same result X every frame
you can create one random instance for each index (at the very begining) and just keep that random instance updated, instead of re-feeding the seed every frame
as long that the initial seed is the same for all devices, the results should be the same across all devices
@radiant sentinel everytime you use a seed X you will recevive a result Y, so if your calculated seed has a predictable range (like 1 or 2) you will always have the very same result range (like X or Y)
if I understood correctly, you are using the index of entities to calculate your seed, if you are doing that all entities on index 1 will always generate the very same result X every frame
@rancid geode
I understand this, i got Y as 0 for random seeds too. My range is 0 - 2
Thank you i should change core of algorithm
Are the physics body and shape calculations supposed to be a lot more expensive than the standard rigidbody calculations? When i test with just 200 cubes with a box collider and rigidbody, i get 218 fps vs when I convert them to entities I get 125 fps
Did you use the profiler to confirm its the physics?
The FPS stats indicator in the editor is extremely useless for performance comparison
yes, the added time is in the physics step
(Not saying you're wrong btw)
i know, no worries
What do the profiles look like?
I noticed that ECS physics has a higher base cost, but scales nicer
ill grab them, one sec
And the most recent version has a useless sync point in it, which you can remove if you "fork" it
with everything else it has been great, but with rigidbodies for some reason it takes forever
hmm , i did not know that
also, isn't it supposed to ignore items at rest? the velocities are jumping all over the place at rest
ecs:
2.32 ms is the heavy piece
Non-Ecs
and actually , when turning off entities and using regular cubes/rb, the floor is still an entity so the physics engine is still cycling:
And this is with burst and jobs enabled?
What does the timeline look like (instead of the hierarchy) for the ecs one?
only 200
Thats a LOT of jobs for 200 cubes
Could you check what jobs those are? And possibly check the entity debugger to see how your chunk utilization is?
I cant remember if thats 45 chunks with 4 entities, or 4 chunks with 45 entities...
By scale it looks like one chunk of 1, and 45 of 4
I think the latter, considering it matches 5 chunks
@olive kite job system kinda fails on high core count cpu's
Job system scheduler is pretty bad
Or the opposite... that graph could have clearer UX...
I only have 12 so 24 hw threads and that means job system automatically sets 23 workers for me but physics will choke on that worker amount already
But it shouldn't be scheduling that many jobs though?
oh really
Yeah but it should split it to minimum 1 chunk a job, and there are only 5 chunks
is there a way to limit the available
you can only limit the total worker amount
2020.1+ only
I've found 4-6 workers to perform the best for me
meaning, I can't stress the cpu 100% with this setup either
interesting
Seems its in 2019.4 as well
there's also a commandline parameter
basically profiler is useless if you just cap the worker amount with that line on the docs
I think its also in the boot.config for build out players
because you'll still see 63 workers on that cpu even if you only use 4
only limiting the worker amount via command line parameter will make profiler only show the same amount of workers
i set the worker threads to 6
oh course your use case could have different results
yeah it's kinda broken on modern high core count cpu's atm
step physics world went from 2.5 to .6
oh wow
ms
yes, that's in line with what I've seen
geez, thanks so much
it was killing me
youtube guys getting 150,000 and i cant get 1000 at 60fps
I mean I haven't seen that dramatic change but since we know how much it splits to workers, it has to be so much worse on that high core count chip
yeah , that makes sense knowing it isn't optimized for high counts
what sucks here is that you are essentially restricting the cpu from it's full potential
right
I've complained a lot of this and hope that some day they let you just limit individual schedulers or systems worker amount
might be good anyways , going to port to console eventually
because you could still totally run different systems parallel
something like that, yes
yeah that would be ideal to limit ind schedulers
welp, I wasted about 3 hours on that haha
anyway, I've done a script that lets me use keyboard at runtime to set the worker amount that also reports different systems cpu time in ms, it's been helpful for me to see where it starts to get bad
different systems have different ideal worker amount so need to balance that atm
yeah you're right, you could limit systems to like 6 each and it could run multiple on different threads
some systems run fastest even on 0-1 workers atm with DOTS
yikes, going to have to keep an eye on it
and now I'm talking about Unity's framework, DOTS physics, Hybrid Renderer v2, not about my own code
so today, it's not really "performance by default"
actually , higher at 1
so, you are essentially not getting any benefits from job system at that point
only from burst and bit from ecs
must be nice sitting on 32 core cpu with this setup ๐
it's nice when baking
3970x is awesome, I wish I had it
their cpus are awesome now, the new line is even better
yup
RIP parallel
I'm sure Unity figures this out eventually
some things still benefit from more workers
it's just their current stock systems really don't do that much, and where you get gains totally depends on your use case
typical gameplay scenario is not getting any gains
it shouldn't be too hard to estimate jumping workers time vs time of operation and schedule based on that
what's that term called.. i forgot
I've been meaning to post a sample project to the forums to demonstrate all this to get more attention over this but I then got other things on my plate and I haven't really gotten back to it
ill probably post on it, considering my needs
@olive kite context switching?
yeah it does
it's not mine, a* pathfinding project. wrote a few lines to attach it to the entities and it works perfect
can I have something like a NativeList on a component?
@hollow mist nope unfortunately
Hi, everyone!
does ComponentObject produce garbage as well as the class version of IComponentData?
And is there a way I can prevent garbage allocations using class based components (maybe an interface to release component members)
@amber flicker do you happen to have a recommendation for a way to track things over time? consider a situation where my player will encounter certain things as it progresses through the world, and I want to keep a running tally of those things that they encounter
@hollow mist there are a few options - the most straight forward might be a DynamicBuffer - it's the equivalent of an array of IComponentData's
yeah I've taken some initial stabs at using that, but haven't succeeded yet
I'd have to add that to my entity via code after player instantiation, yeah? and from there, are there any limitations to how I can add to it? like can I do do via EntityManager or must I do so via PostUpdateCommands? (I'm still mentally working through understanding the differences between ComponentSystem, JobSystem, SystemBase systems... EntityCommandBuffer... etc. ๐ so many things!
@hollow mist only around for a min but:
- Forget PostUpdateCommands, ComponentSystem & JobSystem - pretend they don't exist
- I think you can add an IBufferElement as part of an archetype exactly the same as an ICD (doesn't need to be after instantiation)
- Make sure you get the buffer:
var buffer = EntityManager.GetBuffer<MyBuffer>(entity);before then adding to it:buffer.Add() - I'd get used to EntityCommandBuffers (ecb) over PostUpdateCommands - it's creating a buffer of commands and then executing them later - hence this can come with it's own timing-related issues
hm, okay, I'll see what I can figure out
@amber flicker as for #2 -- what if I'm doing a hybrid player with the convert workflow?
also, thank you for your responses!
np - you can't use the [GenerateAuthoringComponent] attribute for buffers but you can do it by creating a custom conversion script - it's much more straight-forward than it might sound. If that answers your q.
gives me a jumping off point -- thanks!
๐ good luck!
@hollow mist iirc you can have nativelist on class icomponentdata, limited to mainthread though
@safe lintel oh, thanks -- I'll look into that!
Thatโs a really good point. Never really crosses my mind that that would be something someone wanted to do but youโre totally right.
why are angular impulses weird in unity/havok physics?
that doesn't really tell anything
weird how? how you set them? how they move things? something else?
https://forum.unity.com/threads/how-do-i-properly-apply-angular-impulses-to-physics-bodies.992802/ here's the thread i made
ok that explanation didn't really tell much either and video is just confusing, I have no idea what I'm looking at
I can imagine that's one reason why nobody has replied yet
i attached my code
only way to figure out anything out of that is to look at the code itself
WRCarPhysicsSystem.cs (which is responsible for most physics of my car and all physics demonstrated in the video) is attached
it's just, if you don't even understand the person's problem from video and description, there's quite high bar to even open the code snippet as you don't have a clue what to look for
the angular impulse/velocity stuff
i calculate it on lines 101-106 (with lines 48 and 50 related) and apply it on line 111
I did look at the code and there's no way I'm going to decipher this ๐ You need simpler example if you want people to be able to help you
you are now asking people to actually first learn your implementation and then fix it for you, rather than help on angular impulses
jeez
thats gonna be really hard
the question is, how do apply angular impulse to a physics body similar to unity physx's Rigidbody.AddRelativeTorque? because when i do that, extra forces get in the way for some reason
the car in the video is supposed to only rotate on y axis when not affected by any other forces
and i only apply the angular impulse to local y axis, but it still makes the car rotate on other axes too
might be worth setting up the most simple ApplyAngularImpulse example you can and verify it doesn't work as expected. I could believe integration errors mean it eventually does spin wildly though.
yeah, that's what I usually do when trying to figure things out, setup most simple scenario rather than trying to port whole codebase at once
basically, just put a cube there, disable gravity and try to spin it with angular impulse on it's local axis
anyone knows how to do multidimensional array in DOTS jobs systems ?
@hollow jolt what i would do: use the index to calculate x, y, z from it.
sure but i don't know in advance what size each portion would occupy
im looking to distribute 3d data points into a grid data structure to reduce the search space for local collisions in large meshes
so, my issue works only when the physics shape is a convex hull or a mesh
the angular impulse one
Hi! I am trying to access an Entity converted by an authouring monobehaviour in a system. the monobehaviour runs after the system OnCreate() and im unsure how to setup dependancies for it
any advice would be golden
So you want to access the entity after it's converted and brought into the world?
Well for starters, what are you trying to do with the entity? Do you only need it once or are you trying to cache it for something?
Yes Im making a spawn grid component on the entity [using getbounds monobehaviour functions] and then using a system on the grid. does that make sense?
you're trying to make a grid?
hrmmmm
for me, I would just tag the entity, then do an entities.foreach, querying the tagged entity, in OnStartRunning()
leave the OnUpdate() blank.
@amber flicker well holy hell, you can put [GenerateAuthoringComponent] on a buffer item!
oh can you? sorry I didn't realise ๐
no problem -- happy surprise!
wait, but you can run systems on buffer components right?
I mean like natively without using the entity manager
if you mean lambdas or systems, sure
okay, extreme example, if I made a "feather" component and each feather was added as a buffer component to an entity, I couldnt have, say, a system that processed feathers, right?
im trying to get at the one to many nature of buffer components. can I do an Entities.ForEach on feathers?
buffers work fine in the lambdas - i.e. you'd just do e.g. ..in DynamicBuffer<Feather> feathers...
ah, yeah, thats not what I meant. Like I know I can process an array of data
I was just wondering if I could do
Entities.ForEach((Entity entity, Feather feather)=> {...})
see cause that would be weird, because in theory multiple of those iterations would be with the same entity
because feather is many to one
correct, that'd be odd - you'd instead do Entities.ForEach((in DynamicBuffer<Feather> feathers) => for(int i = 0; i < feathers.Length; ++i) { //smth }..
oh thats interesting, I didnt know that was a thing you could do
hows that arranged in memory? seems like that couldnt be linear memory, right?
it is linear if your buffer is below the allocated capacity
i.e. the [InternalBufferCapacity(n)] attribute
oh huh, thats cool
when you add an IBufferElementData with e.g. [InternalBufferCapacity(10)] you are declaring you basically want to add a 10 element array to every entity that has that buffer (at least, the capacity for 10 elements). If your array/buffer exceeds this capacity, I believe the whole array gets moved to the heap (so rand access) but it's still pretty quick. This is obviously a trade-off as the more elements you set to allocate, the fewer entities can fit in a chunk.
thats pretty cool. lol i've been homerolling that
I made a struct with a number of slots and an integer to say how many of the slots were used, etc
yea, that's why DynamicBuffers are really nice - have linear access but then work just the same if and when the capacity is exceeded.
@amber flicker looks like there's a very specific way the generateauthoring stuff works on buffer items ๐
yeah, if you add more than one property to the struct, it chokes... had to go with a custom conversion script (first one I've used!)
I got my whole system I was working on all functioning properly now though!
thanks for the nudge in the right direction ๐
pretty happy with it -- made a custom set of systems/components for setting up "trigger emitters" on objects, "trigger listeners" on other objects, and made it function so when a listener enters an emitter it'll track the interaction (enter/stay/leave) and delegate to the appropriate handling system depending on the type of the trigger as configured on the emitter ๐
Hey what was the battle simulation called that they showed during Unite Austin that spawned 10,000 arrows in one frame?
nordeus tech demo
awesome thank you @safe lintel
https://github.com/Unity-Technologies/UniteAustinTechnicalPresentation repo in case you were looking for it
oh awesome didn't know they had it available
I'm trying to assign to a Dynamic Buffer and I keep getting DC0033: Parameter 'buffer' is not a IComponentData / ISharedComponentData and is therefore not a supported parameter type for Entities.ForEach. Allthough i have copied verbatum ForEach lambdas to do this. Does ForEach not work with DynamicBuffer anymore?
it should work. is the type of the buffer element IBufferElementData and the lambda type is DynamicBuffer<MyElementStruct>?
the type of the buffer element is IBufferElementData and it holds a float, and im passing DynamicBuffer<nameofthestruct>. just pasted from the manual and that failed
this fails
need to pass it in with either in or ref
i tried both. maybe it's having two ForEaches in one file? I tried the commandbuffer too
no that should be fine
Fixed it. lameful noob error which you need not know the details of. I will waste no more of your time.
hey no worries my friend. I couldn't see it at first glance and I've been on the dots train since it came out
sometimes you just overlook the most simple things
tnx meng
okay
what does this error mean
A Hybrid Renderer V2 batch is using the shader "Shader Graphs/Red Panel Graph", but the shader is either not compatible with Hybrid Renderer V2, is missing the DOTS_INSTANCING_ON variant, or there is a problem with the DOTS_INSTANCING_ON variant.
welp it was just unity editor upgrade problems
Anyone else experienced crazy compilation times with dots lately?
@north bay try out https://github.com/needle-tools/compilation-visualizer to pinpoint what's taking so long
i could imagine a full project recompile could take that long, but most of the time it should only be recompiling assemblies that changed so if that's the time you always get then sounds something weird going on
There were some versions lately that had a regression causing extremely poor compile times, so upgrading Unity could also fix it
I just tried 2020.1.10 but i still have the same issue. My project is pretty big with +500 systems. @hollow sorrel I'll check that out thanks
my other guess would be if you don't use assemblydefinitions for your own code then making changes there will trigger a recompile of everything since the default assembly depends on everything automatically i think
Noob question. Instantiating with the entity manager, what's going wrong here? Also this does not allow for burst compilation??
you can't use EntityManager w/ burst in Entities.ForEach
use EntityCommandBuffer instead
ah ok
basic question but what's the current best way to get two lists of the same component?, like I need to compare translations between two different sets of entities
would ToComponentDataArray help you?
NativeArray<myComp> set1 = query1.ToComponentDataArray
NativeArray<myComp> set2 = query2.ToComponentDataArray
@pliant pike
hmm you wont get a conflicts error will you? Like I remember I got errors if you tried to get the same component twice in a job
well, now the answer divides up a lot going into the implementation
like I was going to use this Entities.WithAll<TestObjectAuthoring>().ForEach((Entity inty, ref Translation trundle) => {
to iterate through the primary bunch and then compare each one of them against the target translation entities
so, in that case youre only comparing one entity (at a time) to a list of entities, right?
yep
where does that target entities list come from?
they have their own component tags, thats what I'm trying to figure out
I need to maybe get the entities reference attached to the component tag
so, youre saying they originate from the results of a completely different entity query?
@hollow sorrel It looks like it's compiling once for 30 seconds than reloading and compiling again for 60 seconds or am i evaluating that wrong?
no I'm thinking maybe I should just do an entityquery for translation instead
and then use GetComponentData etc to get the correct entities
Im not sure. Im still having trouble visualizing the approach and the problem
yeah maybe I'm not explaining it that well sorry ๐
it sounds potentially like youre trying to solve the problem of having 2 different entity types interact with each other in a system
and unfortunately, pretty much all of the creativity in ECS design is about moving laterally around that problem.
say I have two groups of entities obstacles and movers which are both tagged differently
when you say tagged differently
I need to compare the movers distances to the obstacles
you mean they are different archetypes?
@north bay yeah seems like, no idea why it does 2 iterations, didn't see that before
also oooof that reload time
yeah its just the tag that is different currently though
for most purposes it doesnt matter how different they are, just that they have any difference at all between their component makeup
if one set has components the other doesnt, then they arent the same set or subsets of each other
okay, so yeah, I guess it depends on how many of these obstacles and movers there are
you're basically talking about doing a combinatorial lookup between 2 different sets of entities
yeah I'm sure I did something like it before I just can't remember and not sure if anything had changed recently or what the best way of doing it was
I dont think there will be a global way of doing it for quite a while. the problem space is pretty dependent on what guarantees your situation has available to it
lol, I wonder if you could just give those 2 types of entities an infinitely large collider and then just use the ITriggerEntitiesJob to process all pairs
yeah and the docs arent particularly great
like I need to get only the translation entities with a tag and it doesn't seem clear how to do that
anyway, yeah. there are lots of ways to do this kind of thing. I have an example of one particular, rather complicated way of doing this in gist form on the wiki
there are a lot of complications that approach doesnt address, and my current implementation doesnt even calculate draft at all
in fact, thats kind of terrible. maybe dont even look at that, except to triangulate against other things youve seen
struggling with Commandbuffer. can't seem to assign a component with it
um... i think it's because you disposed the commandbuffer.
hold on, I have an example script to show you
ok!
here
thanks! not sure how to the job handle dependancy, i was disposing of the buffer wrongly
struggling with Commandbuffer. can't seem to assign a component with it
@brazen storm You use Visual studio or code here?
I use VS code
oh thx
struggling with Commandbuffer. can't seem to assign a component with it
@brazen storm https://docs.unity3d.com/Packages/com.unity.entities@0.14/changelog/CHANGELOG.html "Ensure that patched component access methods (GetComponent/SetComponent/HasComponent) don't break Entities.ForEach when there are a lot of them (due to short branch IL instructions)." Hasn't this problem been fixed yet?
Fix from [0.10.0] - 2020-04-28
it has.
he was just implementing is ecb wrong
ok I'm hoping this is a simple yes/no question: Is it possible to add/remove entities/components from subscenes during runtime? Or are they basically static?
Once a subscene has been loaded into the game, the entities within become normal entities, if that's what you ask. The subscene itself no longer really exists.
but there's no way to save changes back to the subscene right?
then close it and open it later and see those changes
@hollow sorrel Yo, that compilation visualization package is AMAZING!!!!
I wish that was default Unity
How can I execute a raycast inside a Job? AFAIK, RaycastCommand can't be scheduled inside a Job, but I don't know which raycast I must do prior the creation of this job.
And the normal physic class doesn't work in jobs
Hello everyone! Quick question... what would be good to use for a backend database for DOTs? For games that manage your inventory authoritatively from the server. (Destiny, Diablo etc.)
Any good databases that play nice with DOTS?
@lean raptor ecs physics or physx?
@rare umbra i don't think the DOTS part is relevant if you're talking about backend, it's not like you're gonna store entity chunks directly
any database you'd otherwise use would apply the same to DOTS
@lean raptor ecs physics or physx?
@hollow sorrel Sorry, not sure what you means. Any physics is okay with me if I can do raycast-related stuff with it XD
I just one to use a Job to do some stuff, I asked in #archived-code-general and they send me here
you can schedule the raycastcommands on main thread tho and await result
you can schedule the raycastcommands on main thread tho and await result
@hollow sorrel But I don't know which raycastcommands I need until I'm inside the job
then you'd need to schedule them after your job
so something like
- create commands/results nativearrays and pass them to first job
- schedule a raycastcommand with those same nativearrays with a dependency on first job (combine jobhandles)
should work i think
My code looks like:
void Execute() {
InitializeStuf();
if (Work(x))
Other();
}
bool Work(x)
{
if (Process(DoOneRaycast()))
return false;
DoOtherStuff();
if (Work(x+y) && Work(x+z))
{
DoAnotherStuff();
return false;
}
return true;
}
Due the recursive nature of my code, I'm not sure how can I go back and forth between the main thread and the job to get the raycast done
anything recursive can be turned into iterative
Also, the execution of Work is very lightweight, so I think the overhead of one job per Work will be too high. (each Work is very fast, but I need to execute hundred of thousands of them, which is slow)
@hollow sorrel Iโd need a good way to serialized and unserialize the data and keep them in sync though. Was wondering if there was anything off the shelf for that
I'll try
maybe you could bundle the work to all be done in a single job
just wanted to celebrate some progress. I've had a hard time procrastinating on an IL weaving project I've been slowly cranking out. Today and last night I overcame much of that procrastination, and finally have simple structs generated from C# lambdas. Next is replacing references to lambdas to the codegen-ed structs.
I'm trying to make a API for converting C# delegates to structs. The goal is to have a Burst-compatible delegate that doesn't have the same limitations as FunctionPointer.
Not super far along, but just one step closer to finding all the issues of my IL weaving hahaha
is it possible to have a dynamicbuffer of fixedstrings?
I believe strings aren't blittablr
yeah you can @shy pilot
strings (class strings) arent blittable, but fixedstrings are
i generally used fixedstring32
ok thanks :)
can anyone tell me what is going on here
i get this error
*among many others
InvalidOperationException: CreatureComponent used in NativeArray<CreatureComponent> must be unmanaged (contain no managed types) and cannot itself be a native container type.
[GenerateAuthoringComponent]
public struct CreatureComponent : IComponentData
{
public float health; //Current health of the creature
public float age; //The age of the creature (in seconds)
public CreatureState state; //The state of the creature
public bool gregnant; //Is the creature pregnant
public float gestationFinish; //When will the creature give birth (Live Birth Only)
public GenderBase gender; //What is the creature's gender
//public bool asexual; //Can the creature reproduce with the same gender
public float food; //Hunger-bar for the creature
public float water; //Thirst-bar for the creature
public Entity attacker;
}
[System.Serializable]
public struct GenderBase
{
public FixedString64 name; //Name of the gender
public bool givesBirth; //Is the creature capable of giving birth/laying eggs
public bool seekMate; //Should the creature actively seek a mate
public DynamicBuffer<FixedString64> compatableGenders; //List of genders that the creature can mate with
}
side note: is there a way to run complete on an entities.foreach that was called with schedule?
public DynamicBuffer<FixedString64> compatableGenders;
I believe this is your problem
That's, to my knowledge, not a properway to make a DB
and maybe also the
public GenderBase gender;
I've never tried a struct within a struct ICD.
and I believe it's crawling into OOP land
Hi. Trying to check one entity component values against several entity components. I'm thinking do an entity query for one and a .foreach for the others when component value changed.
