#archived-dots
1 messages ยท Page 145 of 1
close entity debugger window and reopen most likely
Things like that make me wonder when Dots will finally stop being a preview package
But yeah, thanks for help
yeah I've been avoiding dots for that reason, but I am using jobs+burst which are nice
By the way I am making a Dots simulation, which will let me combine different particle behaviors. I have created far too many individual projects around gravity, electromagnetics, relativistics and other stuff, that I think it's time for me to unify them into one.
nice
Sure is
Disregard my earlier question.. managed to make it work using activeBuffer.RemoveAt + activeBuffer.Insert...
Just want to make sure its the correct approach?
can anyone help me deletre an entity with some specific attributes? ๐ Im going insane trying all sorts of stuff. https://pastebin.com/rKfKHmKs
ugh, why not add a component called PendingDestroy or something to the entity inside the job, and then have a system that deletes entities by query that contain that component.
I think I just use entitycommandbuffer maybe ๐
I dont get why the docs dont show how to use it for us newbs ๐ ill look for a sample
Uh
Now I experience crashes from something, that haven't caused any crashes so far
To be precise, EntityManager.CreateEntity causes the crash
Okay, found the issue.
The method itself is bugged
You can call variation, that spawns a single entity, but you cannot fill a list with entities - it causes instacrash.
Can anyone reproduce it?
I am not 100% sure if it is really a bug
@storm ravine Wow thanks, I'll add updating my conversion/loading stuff to my TODO list
Doesn't even look that hard :P
Thanks again
Hey, does anyone know, given a random Entity, how does the System know which archetype the entity is from? Systems access Entities from diferent archetypes depending on how many components are queried for.
So when collecting all possible Entitiy ID's(Index) there are bound to be some duplicates, right? Since a new archetype starts at 0
@formal scaffold the entity id dosnt start at 0 again between archetypes
Is the id continuous throughout the engine?
Hmm maybe I have read it wrong in the manual then
kinda
Ids get reused when you destroy and create entities, thats what the version number is for
What is ECS/DOTS not good for atm
@west furnace Tough question, I'm so far in my bubble of my game I haven't really considered anything else
I think its best when you have lots of something(s) but I think you could make any game in DOTS
in general someone said that I shouldn't use it for everything
because it's not ready
but what's the actual real world problem
thats probably true around certain tech bits, like animations are preview, haven't seen anything with Particles or VFX, netcode is coming but looks targeted for FPS
the core ECS/JOBS/BURST is really solid, but those other bits...
but there's intergation flows now with older Monobehaviours and Components, so worst case you can use those
I think I want to use dots because I want a traffic system, but I want to know what I'm getting into
traffic would work well, you dont need animations (do you??) you can use the new Physics for collisions
worst part would probably be getting your road data into ECS, would need to break it down into points and connections i guess and then structure that somehow
I do actually
what are the animations?
Well I was thinking about having both cars and people
yea that makes sense
there is a preview animation package
but to start with i recommend just geting all the data in and working, and leaving your people unanimated (as T pose) thats what im doing
after i have it all solid and working i plan to integrate the new animation package
but ive just seen Kinematica has a preview package and has DOTS support... might play with that
this might just be a bit too experimental for me to use...
maybe for a future project
yea its all very experimental
if you want the performance and scale tho, no other way
Any tips on how to find these allocation warnings?
Internal: deleting an allocation that is older than its permitted lifetime of 4 frames
@west furnace I'd say it's not good for quick prototyping, or when there are only one (or few) objects of each type which have lots of interactions. That's a tradeoff with the whole philosophy, so that probably isn't going to change.
As for things that are just not good right now, the authoring/editor workflow could definitely be better. Also overall support for more advanced features and tools. Networking, animation, pathfinding etc etc. Physics is really good though, but still not perfect.
The general advice I've heard is to use normal Unity unless you can't. For example, ECS is very good when you have many of the same entity, and allows you to have way more entities in general (10.000+) without too big performance hits.
Hey, is there any way to instantly terminate a job? I do not care about the results of that job as they will no longer be valid. Optionally, I could just edit an array the job is using and then reschedule the job after it has finished, but I can't. Or is there a way to disable the lock the job places on the nativearray so I could edit it?
@dusk relic You could call Complete() on the jobHandle.
You may find reordering systems or just waiting until the next frame to be easier.
Calling complete() freezes the main thread as it waits for the job to finish, I wan't to terminate the job, not wait for it
I could wait for the next frame, but it would be really convenient to just edit the same array as it would not create any memory overhead
Waiting for the job to finish would require me to store the changes somewhere else, which is not ideal
What I'm saying is, since the results of that job will be invalid no matter what happens, why not just edit the array used by the job?
if the job is across workers, short answer is there isn't a way to do it - and even if you could, it probably wouldn't be quicker than early out-ing - you can do is early out on a chunk level using IJobChunk if necessary. To disable the 'lock' on NativeArray - if you know for sure you're not writing to the same index multiple times, you can use e.g. .WithNativeParallelDisable I think it's called
since the results of that job will be invalid no matter what happens - I may not be understanding your problem very well
I'm trying to edit the noise map for the terrain from the main thread, but since it's being used by a job started on previous terrain modification I can't
noisemap is the nativearray
Ok I think I see - I think what I said stands in that the best you can do is early out
Could you elaborate?
For each chunk I'm using IJobParallelFor
And the meshes you see are not entities
I don't understand why I can't just edit the nativearray
Can I not disable the safety checks?
Or can I use GetUnsafeBufferPointerWithoutChecks to get the pointer and edit the data, or will it also throw an error
.WithNativeDisableParallelForRestriction(myDynamicBuffer)
????.WithNativeDisableParallelForRestriction(myDynamicBuffer)
that's for the lambdas. In your case you should be able to add an attribute to your nativearray if you want to disable safety checks
e.g. [NativeDisableParallelForRestriction]
Yeah that disables it from inside the job
I still can't write to it from the main thread
but... wouldn't your jobs potentially still be writing to it even if you could?
Afaik there's no way to 'cancel' a job once it's been scheduled. The thing I'm not sure about is if you can e.g. write to a shared static that a job checks whilst the job is running to help early out.
No, the mesh job is only reading the noise map
so my understanding (which could well be wrong) is that if you try to write while something's reading from it, the read can certainly get either the old or a new value but potentially even something invalid/crashy?
Yeah it doesn't matter what reader reads from it, since when the job is done a new job will immediatly start
updating the potentially invalid data produced by the job before
[NativeDisableParallelForRestriction] - Allow buffer read write in parallel jobs
Use at you own risk only when you sure that other jobs can't write to same entity, at the same time.
I need to write to a nativearray in use by a job from the main thread
I guess you'd need to create the array outside of the job, add the attribute and then pass it in? Not attempted something like this myself and have no idea if it should be safe.
Array is created outside of the job
How do I add the attribute to it without it being in the job though?
if you sure that you never going to write to the same position that any job writes to, you can disable safety check and do it on your own risk, but if you not sure this may cause race conditions and crashes
are you saying you can't add that attribute where your array is declared outside the job or that when you do, it still doesn't let you write to it?
Doesn't let me write to it
Even NativeDisableContainerSafetyRestriction doesn't change anything
yes safety system prevents you from writing while job is running, but you can disable that check on you own risk if you need
How?
[NativeDisableContainerSafetyRestriction] public NativeArray<int> myArray;
Ahhhh I was doing it outside the job that's why it was not working , thanks @dry dune @amber flicker
I didn't know that existed though.. just found out about it when you said it
Groovy, I have my own question now :)
What are peoples thoughts on an ideal syntax for tweening entities/ICDs? Currently I have entity.TweenRotation(), entity.TweenTranslation() etc but I'm concerned that with all the variations this could lead to polluting the auto-complete for an Entity with hundreds of entries.
Tween.Rotation(entity) ?
Or a similar builder pattern to what ForEach, Tween.With(entity).Rotation().Translation()?
Fluent API +1
For the case where there are multiple properties per component, any preferences?
Why not go with the ECS way and use components to specify the tween?
User adds a "Translation tween" component
Which has the different variables needed for all the information on the tween
I may support that at some point for a more 'pure' workflow. At the moment there's similar functionality to DOTween so you can chain methods which is quite convenient. Tween.With(entity).Rotation(..).SetLoops().OnComplete etc.
User adds a "Translation tween" component
this is how i have structured my ECS tween engine. a Tweener core that evaluates curve based transitions. and ForEach after that just applies the interpolated values for to/from values provided by ColorTween/RotationTween/ScaleTween etc components.
But why have it another way? That is the ECS way, so writing non-idiomatic code shouldn't be what you're striving for, especially when writing APIs that other people should use
Trying to juggle multiple aspects. You might be right. Monobehaviour land currently looks like e.g. transform.TweenLocalPositionX(..) - I want to perhaps converge on a more unified API between the two.
Well the whole point, to me at least, is that MB and ECS are two completely different architectures - Object oriented and data oriented.
Trying to unify them is just going to cause you more trouble
I would be sad to mix the two types of writing code if some tool forced me to do that
I've only just gotten used to ECS-idiomatic code, and having to mix it with that would be horrible imo
been on this route. agree with @bright sentinel i started out trying to have a ECS DOTween basically and the blocker was trying to retain the OOP oriented API. plus MB will never be able to reasonably utilize the scale i was aiming to offer with my Tween Engine. pivoted to ECS only eventually.
@stiff skiff any thoughts on components? Does E.g. Tween.With(entity).RotationValue() work? I also currently have all single axis variants for convenience - e.g. RotationY() - bit concerned that .With(entity) will still contain hundreds of entries though I want to utilise autocomplete
for my needs i made it so
Tween<Translation>().target().by(float3).delay().duration().ease();
Tween<Translation>().target().from(float3).to(float3).delay().duration().ease();
Sequence.append(t).append(t).append(t).whenDoneAddTag<Done>.start();```
@bright sentinel & @naive parrot I don't disagree with either of you - I've been working with dots heavily for the past couple years now. That said, I don't think the verbosity is nice as soon as you do something slightly more involved. SetLoops(LoopType.YoYo, 3) avoids the repetitive nature of if(hascomponent)setcomponent(new blah{ settingICareAbout, maybeSettingIDont} for every configuration aspect.
also I do want to make it easy for people to migrate from monobehaviour to dots as they want to
if(hascomponent)setcomponent(new blah{ settingICareAbout, maybeSettingIDont}
For the first part, I'm not sure how you would avoid the if statement. Secondly, when creating a struct with the initializer you don't have to set all the variables
I assume the builder does nothing but create an ECB to setup the components to add to/for the entity
So if someone wants to do that manually, they can do that
The Flow API would just be there for people that don't want to deal with that
Yes good point
This has been my approach for most API's we've been building onto the ECS
Lowest level first, then 1 or 2 layers on top
Our Monobehaviour integration is also simply a layer on top of ECS
What I'm proposing is that users just slap a component on the entity that describes the tweening. You can have multiple types of IComponentData depending on what kind of tweening it should be. A linear movement could be:
public struct LinearTranslationTweenData : IComponentData
{
public float3 from;
public float3 to;
public float time;
}
Then you could have some system state component or whatever to handle the actual tweening with time and whatnot
Users would then just add that component to whatever entity
the problem is, that's the data that ends up on an entity anyway... like zero says, you can add all that manually but it's a chore to remember what to add under what conditions and fill in defaults etc
internally my tweener uses components like this
but for convenience of configuring creation of tween properties entity is made using chain interface
Why would it be a chore over function calls/lambda? Either way you have autocomplete, it's just whether it is a function call or a component
You still have to remember what the functions do and under what condition to call them in
I don't get why AddComponent(new Tween.LinearTranslationData{...}) is so much worse than Tween.LinearTranslation(...)
tricky part was a generic job system that can tween various data types ๐
I just know that I'll be having a hard time using a non-ECS API in an ECS architecture
The whole basis of ECS are the components, and by not utilizing it, you're going to be making the architecture a lot more complex
When you could make it a whole lot simpler
that's ok - in your case you'll be able to add the components yourself no problem
Um
Why my build crashes when I divide double3 by a double?
Both are non-zero
I see. Apparently now I can't divide vector itself. I have to divide each coordinate in a new double3.
I can't believe how buggy 0.10 is
I'm trying to instantiate some prefabs as entites. I'm getting a reference to the prefab and instantiating like this:
Entity spawnedEntity = entityManager.Instantiate(goPrefab);
in debugging goPrefab is the correct GameObject.
The enties are created but they are missing all components. Is there an extra step I'm missing?
goPrefab should be an entity not a GameObject
Instantiate has an overload for a gameobject though
Oh i think I need to impliment IDeclareReferencedPrefabs and declare the prefabs
Can I somehow scale my entity?
there should be a scale component/nonuniform scale component, but I don't remember if it affects the transform/rendering data yet
you can also set the scale directly in the float4x4 across the diagonal ๐ค
there are 2 components on for uniform scale and one for nonuniform
Scale(){Value = 1} and NonUniformScale(){Value = new float3(1,1,1)}
Thanks
Also, stupid question, how do I set up my RenderMesh?
As an example, I have entities, that use same mesh and same material
Should I add RenderMesh type to entity's archetype and then Set or Add SharedComponentData to each entity?
Pretty much. You'll need the following components to render an entity:
LocalToWorld, RenderMesh, RenderBounds, Translation, Rotation
By the way, does anyone know why an entity which has a sprite shader (cull off), when flipped (rotation.Value = quaternion.Euler(float(0,3,0)), only shows Half of the sprite when flipped?
I'm using 2020.1 right now, but in my earlier project, on 19.3.3 i can see the entire sprite
That is why we are currently working on adding Enabled state to all components. This way you can enable / disable components from any job safely without changing the structure. ``` - Joachim https://forum.unity.com/threads/entites-foreach-on-icomponentdata-class.894007/#post-5875804 ๐ฒ ๐ฅณ
that's huge
I wonder if they'll repurpose the EntityQueryOption.IncludeDisabled filter ๐
Now you can actually code ECS idiomatically without it hitting framerate ๐
(Now as in when this lands)
Hello, I was wondering how the data layout looks like inside the cache when accessing an index of an array. I was watching https://www.youtube.com/watch?v=0_Byw9UMn9g and at ~7:30 the commentator starts talking on how the data layout looks like when using OOP design and then later DOD design. However, I was wondering, when you access an index inside an array, does the whole array get loaded into the cache or is it that one value which you're accessing?
Unity's new ECS features enable huge performance improvements over traditional object-oriented ways of designing game systems, but data-oriented design is a much different way of thinking. Watch to learn how to think in a data-oriented way so you can take advantage of these ne...
(Ooh, neat video, I'll watch it too)
@thorny halo I may not be 100% accurate about this, so take it with a grain of salt.
There are multiple types of caches on the CPU. The L3 cache is the largest and slowest, but is the one that talks with RAM. L1 and L2 caches are only available to one core (or maybe it's two cores). Whenever you reference the whole array on one of those cores, then the whole array is loaded into each of their caches.
Now, ECS has one thread per core, and this is exactly the reason - you can work on the caches pretty much one to one. So to fully utilize this, you want to use NativeSlice, and pass that to each job. That way, only the specific part of the array is loaded.
The biggest caveat here is that I don't really know whether Burst does anything smart about this. Maybe the Entities.ForEach statement is already compiled down into this. But now you know that you can at least do it manually.
@bright sentinel thanks
@gusty comet Actually, it doesn't seem to work for me. Things crash when render system updates
Just what on Earth am I doing wrong?
In one of previous Entities versions I used PostUpdateCommands.AddSharedComponent, but nowadays I can't understand where did PUC go
And it's not like it is running within a job.
first off, entity manager needs to be called like this:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Second, try creating and rendering a single entity as a starter in a simplified way
I don't suppose others have run into this issue with burst on Linux, but does the editor continuously have a pop up saying the version of burst has changed, please restart the editor? Seems to continously happen no matter how often I restart the editor ๐ค
You'll need to setcomponent with data to rendermesh, translation etc..
I'm not sure how you are even trying to spawn an entity, so check this for reference:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/HelloCube
will entityCommandBuffer.AddComponent() fall over if there is already a component of this type on an entity, and/or how do I check for this first to set its data rather than adding?
and/or if I call remove when there isn't a component, will that fall over? ๐
nice, apparently it doesn't fail by removing first, not sure that that's the right way to go though, info on this is sketchy in the docs AFAICT at the minute
@gusty comet Thanks for help, but it still crashes
I am thinking of downgrading my Entities version
0.10 is super unstable
Everything I do leads to crash, unless I discover a work-around
show us error logsโข๏ธ
Loaded scene 'Temp/__Backupscenes/0.backup'
Deserialize: 1.773 ms
Integration: 321.497 ms
Integration of assets: 0.005 ms
Thread Wait Time: 17.017 ms
Total Operation Time: 340.292 ms
Stacktrace:
=================================================================
Got a SIGILL while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Crash!!!
huuuuh yikes D:
Previously I had render system's "OnUpdate" in stacktrace
isn't that more of a Burst problem than a Entities problem ?
what happens if you disable burst ?
Will entities work without it tho?
ye
Okay, I'll try
don't uninstall it, just tick off the burst compile option
๐
Turns out my mesh was null... for some weird reason
eizenhorn is typing
Ack, actually, nvm, I am in the wrong scene rn
?
I already told you :)
First what you should to do when you got crash - disable Burst, usually it crashes only with burst, with disabled burst compilation you'll see clear errors.
This is because burst has troubles with exceptions handling
Depends on hardware
I thought Burst only compiles job stuff
We on 0.10 in huge and complex project and all works fine, it crashes only in rare cases when you have errors in your code. In 90% is user error.
Can you also divide double3 by double?
And does instantiating entities by a list work?
should be the case - you would get a double3 as the result, but you might be get a divide by zero error
To me those two things are completely bugged
by a list ?
Yes it woks without problems
Yeah, by specifying an archetype and a native list you want to fill
Instantiating entities with NativeArray overload if I remember your previous messages
Yeah, Archetype + NativeArray args
We using all overloads for instantiating in different places and all of them works fine
Maybe it had to do with using wrong EntityManager idk
For the past 2 days I've had probably 50 crashes
turn off burst and see 
Fhew, finally everything works
...without burst compiler
I probably need to play around with it's versions
But for today - I'm done
Everyone, thanks
Any idea why the following would happen?
- An entity has two components that other similar entities don't.
- EntityManager.SetSharedComponentData sets its RenderMesh to a new() one, and the mesh is set to a different mesh.
- The DisableRendering tag is on the entity.
- It renders anyway.
- Every single similar entity NOT sharing a chunk with it also has its rendermesh changed.
This is driving me insane. I just want procedural geometry. Will I need a different quad prefab for every single unique shape? It's described like we can instantiate a prefab, and change the instances. Then change the prefab and instantiate for different geometry.
Instead, it's like prefabs are permanently bound to everything instanced from them.
I really hate this workflow.
Some code snippets?
This sounds super bad
The functionality is spread over several systems. I'd have to provide my entire project's scripts.
Here's what happens, in a nutshell:
- A quad prefab is made.
- It's instantiated several times, to make grids.
- The grid quads are all tagged gridQuad. The prefab isn't.
- The prefab is tagged Progenitor. The gridQuads aren't.
- I try to change the vertices for the Progenitor, so I can instantiate it for billboards.
- All of the gridQuads have their vertices changed too.
I also can't prevent the Progenitor from rendering. The DisableRendering tag is just ignored.
The prefab has the Prefab tag on it?
Does it need that?
yup
I'll try adding that.
and when you query for it you need to do something like WithOptions(include prefab)
or something like that
Prefab is a super special component
Okay, so it's something getting hung up in the conversion procedure. When I instantiate, will the prefab tag automatically not pass on to the instances?
no
when you convert to a entity, if its already a prefab it will have the Prefab tag added
when you convert a gameobject it dosnt get that
but you can add it yourself
i do
but also loop over the linked entity group and add it to everything in there
And then remove the prefab tag, instantiate, and add it back to the progenitor
Wait. Everything? As in, every gridQuad and every billboard?
im not sure about your prefab setup
linkedentitygroup is what groups together children entityis
its added automatcily as part of the convertion flow
so your flow should be something like this i think
GameObject => Convert => Prefab
then if you want to modify the prefab
Instaniate it, modify, then add Prefab again
So it won't automatically instantiate the prefab tag to the clone?
no
just like in normal unity
when you Instantiate a prefab its not still a prefab
my flow is similar,
Unity GO Prefab => Instantiate GO => Modify it => Convert => Add Prefab to entity
This is causing all kinds of chaos. I got the gridQuads to render ... without their material, and until I added the prefab tag to them
So, basically, absolutely everything procedurally generated will need the prefab tag
nooo that cant be right
entitys with the Prefab tag are excluded from almost every entity query
how are you rendereing?
hybrid renderer v1 or v2
v2
If I don't add the prefab tag, they automatically get the TerrainLit material (do not want), and if I add the prefab tag then even if I include prefabs in every related query, they don't render at all.
The prefab already has a material in its rendermesh
yea a Prefab wont be renderd
you should just have 1 prefab
and Instantiate that a ton of times
That makes more sense. But what's up with the material getting changed?
no clue yet
break it down real small
with like 5 entities
so you can quickly compare the Prefab and the instances
I don't see a need to go smaller. When they all render, they're in a perfect grid, named, and their parent grids are tagged for direction relative to the player camera. All the debugging stuff is there. It's just guessing what's happening under the hood.
They render perfectly if the first one has no prefab tag. I just can't reuse it then.
you can still Instantiate a existing entity, it dosnt have to be a prefab
Yep. Looks like maybe the prefab gets no rendermesh in the conversion process. Nothing I set up sticks with it, except the vertices.
mesh name is gone, default material used
Leaving it as a non-prefab, I'll need a different base entity for every single quad shape (the problems I first mentioned). Such a strange requirement
well that sucks
It's the instantiate method causing the weirdness. Has to be. It's causing entities to share memory in an unexpected way.
at a guess something is cleaning up the mesh
so a sharedcomponent is shared
so they are all the same instance
Yes, but these should be in different chunks, since they have different components.
And if I set a new rendermesh by value, it should move that entity to a new chunk, rather than change everything in the chunk. So, there's some unexpected behavior here.
I have no idea if this is related to your issue but mentioning in case: https://discordapp.com/channels/489222168727519232/497874303463850004/710035148967641088
Checking it out; thank you
yea that looks super useful
Oh, I've seen that! That's a different bug. When you press play, nothing is rendered. Stop, and press play again, and it works.
Got it! There was a query I forgot about. Build a system, optimize, repeat. It had been a few weeks.
๐
you can see what systems are using the entity, its right at the bottom of the selected entity
I knew about the system though lmao It's the one where the mesh and material are set. It couldn't have been more obvious. Time for coffee I think smfh
Thank you
Hi, is a Vector3Int not compatible with burst?
what are you procedural generating?
@graceful mason nope, use int3
also use the new math library
First, a grid. Then, my UI. I developed this neat effect where billboards have inertia when the camera moves. Finally, terrain and structures once the UI is in place.
Everything after that is effects, animations, and logic
@gusty comet I cant visualize that, billboards like for trees?
Quads as entities that are manually kept facing the camera, in a system. There's a slight delay when the camera moves, before the quad follows. So, it feels like the UI quads have weight.
I'm not sure if I'll keep it in the long run, but it happened accidentally and I hadn't seen it before. So, I fixed it, and then deleted the fix.
@gusty comet sounds cool, so ui just takes a second when moving??
What type of game?
Sort of a RTS + RPG mashup, but probably starting as a TTRP aide to get it right
Tabletop RPG
argh, Entities.ForEach uses ISharedComponentType ChunkCoord. This is only supported when using .WithoutBurst() and .Run()
is it the shared type, or my basic public struct chunkcoord int3
@graceful mason Share the chunk coord type?
See if the compiler will let you use IComponentType instead of shared, now that you're using int3.
So long as your struct has non-blittable types, it'll make you declare it as shared for thread-safety
public struct ChunkCoord : ISharedComponentData {public int3 coord;}
I wanted to be able to qqueryt for particular coords
Alternately, you can cache your data from threads in a SharedStatic (Burst safe), and then move it to your shared component using EntityManager.
that looks fine
public struct ChunkCoord : IComponentData {public int3 coord;}
another option is you use a HashMap instead of a shared component
Making it a shared component, it's automatically in managed memory (so, no Burst)
I had IComponentData but could never work out how to query a coord and get the entity
I guess that makes sense sort of ๐
EntityQuery(typeof(ChunkCoord)).GetSingletonEntity() should do it
yea so i think make a native hash map in some system and share that
<int3,entity>
another option
if you know the max size of your wolrd
you can convert x,y,z into a index in a single dimension array
that would be even faster then a hash map
theres a discussion about these wayy up in the chat
i was asking about fog of war
Im thinking hard ๐
im just using the things wrong ๐
I have an entity, a "chunk" it has a coord, and a terrainbuffer
fiunnally i try to loop those entities
int hash1 = math.floor(math.pow(x, 2.0f) + (double)y);
int hash2 = math.floor(math.pow(z, 2.0f) + (double)hash1);
That will give you a unique double for any x, y, z, so long as you don't commute them.
you probably want a uniquie int tho.. dont want to risk rounding issues
tho floor should be to a int right?
Whoops. That's what the floor is for
for now, i will try using componentdata
as before it took 0.4 seconds to generate each entity
but with burst maybe i can make it fast enough
whats commuting?
oh
Yeah its gone from 48 FPS to 1800FPD
burst is a beast
Commuting is changing their order. Say, if you wrote that into a method that takes x, y, z as parameters, and then somewhere you passed y, x, z, then that couldn't be guaranteed unique as compared with all the x, y, z hashes.
haha ok that sounds like some schrodinger type stuff a little over my head. I always keep X as X always so hopefully im ok ๐
Is there currently any way to do skinned mesh animations in URP+DOTS
one day I will discover what is causing a bug in my code, and I will remember this convo ๐
Is there currently any way to do skinned mesh animations in URP+DOTS
@golden elk write your own GPU skinning shader and system, it's simple.
Well yes I was wanting to avoid that. Unfortunately Unity's GPU skinning is HDRP only, and GPU Crowd Instancer doesn't support mobile.
And I feel like this must already exist somewhere, unless everyone using DOTS is only using HDRP or making 2D games
We using built-in and wrote own renderer and systems.
@golden elk theres the Unity.Animation Package
doesn't support URP it says
argh, so say I generated 5 chunks. (0,1,2 3,4) , when I do EntitiesForEach(chunk) I get a chunk .. say it was number 2, its job needs chunk1 and chunk3 data too
This is where I make a static list of those entities?
feels insane theres no query by component value function to me, but I guess it all makes sense too work., I will try ๐
@graceful mason you can filter queries by shared component
but filter by component is astonishingly slow and you should not do it
yeah it doesnt work with burst then
if you have multiple entities holding the same value on purpose, make it a shared component
wdym ?
Entities.ForEach uses ISharedComponentType ChunkCoord. This is only supported when using .WithoutBurst() and .Run()
I got that
sure, its super basic mosly
Behind scenes, I only make the //and populate there "TerrainOther Buffers" job for entities where all surrounding terrains are made
so now, how to get hold of there data ๐
so the issue is the bottom comment?? how to get chunk 2 and 4's terrain map?
yeah
ok cool
I think the advice above, make a static list sounds ok
so in my system
you could have another buffer
inssrtead of just for x generate chunk entity..... I make it ....for x generate entity and save in list
like otherMapElement
but instead of int you have the Entity
and populate that during gen
and stick to some rules like 0 = left, 1 = up ect
or you can do that
during generation
save the entity and cord into a NativeHashMap<int3, Entity>
and make that accessable
also this might be worth a read for u https://gametorrahod.com/everything-about-isharedcomponentdata/
Is there currently any way to do skinned mesh animations in URP+DOTS
@golden elk Sorry in advance if Google translator translated poorly.
I have a script adapted from GitHub + shader for GPU animations.
The requirement for the device was ES 3.0+ (to extract Vertex ID: SV_VertexID) and animations must be of type "Generic"
A bit dirty code, in a hurry, removed the part of custom rendering...
The shader has 2 uv channels, a color map is stored in the second channel.
"_BaseColor" - the color of the repainted part is superimposed on the second channel, you can delete it if you do not need to.
In the comments I tried to note this
Shader - https://pastebin.com/yfx4RsMc
Animation asset - https://pastebin.com/QD9U7Nn6
AnimMapBaker (EditorWindow) - https://pastebin.com/UP3M3Xan
AnimMapBaker (Main part) - https://pastebin.com/Kz51pkfh
Although it seems to work on 2 ES, but for sure, I donโt remember if in 2 ES SV_VertexID support.
But on all sorts of specific ES 3 exactly works
@eternal ice Thanks for that ๐ save for later
I can't find the posts talking about Unity.Animation working on URP but now I'm thinking I got Hybrid Renderer and Animations swapped around
Thanks I will give it a shot โค๏ธ
what's the proper way to instantiate an entity from a monobehaviour? I looked at the ECS samples, and in it they use GameObjectConversionUtility.ConvertGameObjectHierearchy, and pass in null for a BlobAssetStore, which does not work on my end. Manually creating a BlobAssetStore with new BlobAssetStore seems to like crashing Unity. what do?
i make a blobassetstore and keep it round, then in the monobehaviour destory i clean it up
@eternal ice Thanks for that ๐ save for later
I can't find the posts talking about Unity.Animation working on URP but now I'm thinking I got Hybrid Renderer and Animations swapped around
@ocean tundra I am waiting for the Unity 2020 release because the Hybrid Renderer V1 does not work well ... I wrote a custom render pass and job system. From the Hybrid Renderer I extracted the culling task and on updating Job systems I select the necessary units, affter sorted by teams and write to batches. In the pass, I draw these units with CommandBuffer.DrawMeshInstanced. It turned out pretty well ~ 600 animated units of different colors (5 commands) on the iPhone 6 with a stable 60 fps. Prior to this, GameObject + RenderMesh gave the same process only 30 (iPhone either 60 or 30 can only). And 30-45 fps on the Nexus 5 on which before that it was 18-24.
@eternal ice Yea I'm using the 2020 beta, but I havnt turned on V2 rendering yet
I'm not fussing with performance, still too many core gameplay things i need to implement, after I have them all in ill start reviewing and optimizing, 100% sure that Rendering will be a big one
@ocean tundra when you instantiated it, did it have any physics related stuff on it? I think the issue with mine might be it creates physics stuff while the broadphase is executing or somethng. As sometimes it crashes on instantiation, other times it doesn't.
okay, the issue was I disposed the blob asset store too early, which made it crash when using entities with physics components attached specifically
ty
@eternal ice Got the GPU skinning stuff working, thanks again
10,000 animated models, 250+ FPS. Nice :)
Is there a particular UpdateGroup it's best to create MeshColliders in? I'm currently just kind of creating them whenever, but I'm running into weird issues like some collision meshes occasionally don't exist, and I haven't been able to find any logic on my end that could explain it, so I'm wondering if there's some threading shenanigans going on
@golden elk Wow amazing
@opaque escarp Create them on entity spawn?
or if you can as part of the prefab
it's procedural, so can't do it as part of the prefab
at the moment I have it get created at some time after the data for the mesh is generated in the normal update group
so if its all procedural could you have it all in a separate world and then load it into the main world when all ready?
I could do that, but I'm not sure if that would do anything different
its more of a end state i guess
at the moment this is the code I have for generating the meshcolliders
BlobAssetReference<Collider> thing = MeshCollider.Create(vertices.Reinterpret<float3>().AsNativeArray(), tris.Reinterpret<int3>().AsNativeArray());
col = new PhysicsCollider { Value = thing };
where col is a PhysicsCollider passed by reference
I guess my question is if there's any way a collider could end up corrupted with this
I've also noticed some other weird issues, like I move the camera and the collision mesh suddenly works, which makes me think that it's an issue with my stuff, but nothing else points to that
does the entity have a PhysicsCollider on it from spawn
yes
all right
yea
you could try turning on physics debugging
add a PhysicsDebugDisplayData
a singleton entity
I'm a little hazy on singletons, would on do that in the OnCreate of the System?
yea you can
just create a entity
and add that component
as long as you dont make more then 1
crashed unity so hard task manager couldn't end it lol
oh lordy the degu is slow as snot though
and runs my computer out of memory
that's why it crashed so hard
well I'm certain I'll be able to figure out the issue with this eventually, ty
huh, the colliders are there in the debug, they just don't respond to queries or actual collisions
then I move the camera and they start responding. I don't even...
all right it's almost definitely an issue caused by my stuff. Might be rebuilding the mesh every frame or something, as disabling my generator script magically made them react to collisions.
@opaque escarp sweet, glad you figured it out
Unfortunately I'm no closer to the solution. My hunch at this point is that collision pairs aren't being generated properly, maybe due to bounding boxes not being aligned, and adding a new entity to the chunk triggers an update with the builtin stuff that resolves the issue. Is there anything other than Translation/Rotation/LocalToWorld that the collision system uses to generate the collision pairs that may have not been set?
After a lot of hard decisions I rewrote my project in good old Unity rather than ECS, and for the first time ever I ran my whole project in editor play mode without crashing.
I really like ECS and look forward to it when it's more mature, but for now it's really not ready for production yet, even for a project as small and simple as mine.
indeed, it is in "Preview"
@lusty otter What is your project?
@opaque escarp I dont think so. when the Physics Sim runs it does a bunch of stuff internally but i dont think it does anything to any other components
I think all the components are listed here:
https://docs.unity3d.com/Packages/com.unity.physics@0.3/manual/core_components.html
I'm glad I've had refrain from using it a year ago, and now I've just started a new project but I won't even consider using it. Hope it will be finished in 2021/2022/2023...
It's a scriptable mobile rhythm game, it really isn't complicated compare to the stuffs you guys working on in here.
Before I went back to the old ways, build works on fine on actual devices but in play mode it crashes once the scripting engine is in a few levels of call stack deep.
On iOS there are plenty of issue with Job system/Burst crashing the app.
I went from the initial full DOTS setup, to slowly one by one removing components, starting from removing ECS, then Burst, and now finally I've removed Jobs, it's basically just good old Unity now ๐
I don't trust any of the the 'new' packages anymore unless there are lots of people confirming it's actually usable in production. Even with those packages out of 'preview'. It's really a mess now
If good old stuff works, long live the old days
@ocean tundra Thanks I'll read up on that tomorrow
I think this is a really 'audacious' move. if the hardware is improving dramatically,then this is goona fail because what DOTS what to solve is to force Programmers to code in the hardware-cache friendly way (data-oriented). But if that's no longer the problem, say 3 years later, we have huge-cache hardeware when coding this way doesn't really bring 'siginificant' performance gains, then I think it won't be adopted by much people. For example, in the old days we have lots of GPU tricks to code in a specific way to 'conform' to the GPU, but now they are all gone. and see the latest ad by Unreal5, now we can even ditch normal map in circumstances. Hardware v.s. Software ๐ด
I guess it's more relevant to my project, which is targeted at mobile (low to mid end devices as well) so performance is indeed a big concern.
For a more complicated project yeah I can imagine the headaches, but my logic is very simple (everything is scripted by the user anyways) and transitioning between the two isn't too bad.
If DOTS things worked, even to a semi stable degree, I would still be going with it. But sadly that's not really the case for me.
The most bizarre issue I've had over the course of the project has to be that, by having more than 15 cases in the script executor's switch statement in a job, somehow causes editor to always crash, even if the extra cases aren't even being executed, or I have Burst turned off completely. I was never able to resolve this issue by the way, and had been working on the project without being able to editor play mode that part of the game.
@dusk relic Yes I do have Burst safety checks enabled
Ok I donโt know how to help you
Does the unity physics mesh collider require a rendermesh or can I set the collider mesh separately?
Also if I can, is it sharedcomponentdata
@dusk relic It does not require a RenderMesh
OK
How do I pass component data array (indexed by integers) into a job?
I need to make a simple n-body system, where each particle attracts every other particle
In previous DOTS versions I used IJobForEach into which I passed readonly native array parameters
But nowadays it seems to be deprecated
In addition to that we are currently working on an overhaul of the workflows for creating ghosts and generating code, but that change still needs a bit more time and will not be in the next release. This was a change required for two of the game productions we are using to verify that the netcode is production ready.```
@dusk relic I'll just confirm the earlier, unity physics doesn't even need hybrid rendering package to work
Alright, but how does the collider know what it represents then
just buffer of vertices and indices?
well, depends on collision type
box, sphere, capsule, cylider you can just define yourself
for convex and mesh collision you just ref the mesh on the collision authoring component
easiest way to author these is to just place them on mesh itself
you can sync physics objects to meshes manually if you want to
like if you want to use nonhybrid renderer and dots physics
there are bunch of ways to do this
like, easiest is to just use convert and inject and put copytransformtogameobject component to conversion script
@dusk relic
@lusty otter i made a rythm game in Entitas
but you can also store the GO tranform to entity on authoring stage and keep them on totally different objects, like have DOTS physics objects that get fully converted to entities but still hold GO transform for rendering part
if you want to use something that works but miss the ECS paradigm, maybe check that out
unlike DOTS, it actually works well in hybrid
I'm researchin this for marching cubes collision
so the object doesnt move
I found that traditional rendering is better for performance
but mesh colliders suc
for obvious reasons
Yeah I'm rolling with my own ECS paradigm now, it's really simple but more than enough for what I'm working on.
I'm not sure if physx mesh collisions are that bad
like, I wouldn't expect major wins on dots physics
The things I want the most from DOTS are Burst and Jobs, which sadly don't work very reliably yet.
it could do even worse
Simulation isn't that bad, but baking the colliders lags real bad
which unity version have you used?
there's been a lot of work on making the bakes faster
2019.3.something
I did set the bake option to be faster for generation instead of simulation, but no noticeable impact as far as i can see
Exposing a thread-safe Physics.BakePhysicsMesh(meshInstanceId, isConvex) function to bake the data for MeshCollider on-demand from any thread. Usage example with C# job system (generate N meshes and bake off the main thread): https://t.co/vWIQ64yVqG
that lets you bake off the main thread
of course if you need to apply it instantly, that will not fix the whole issue
Alright will have a look, thanks
I'm not quite sure what's happening here. It's like it's baking the mesh both on the main thread and on the jobs ๐ค orange is mesh baking
Turns out Physics.BakeMesh is broken and got fixed in 2019.3.10
I wouldn't expect major wins on dots physics i was looking at the collision code a couple weeks ago and it really doesn't seem very optimized. Im sure the bvh traverse and stuff is fine but most things just go through the same full hull-hull tests and its littered with branches, no simd etc.
Dear community, here again I need help from you guys. I have some basic questions, not sure if it is possible or not. So basically, I have lots of entities in my scene. They all are doing some calculation. While I am going around with my player, I noticed, that it doesn't matter if the entities are nearby to my player or not. The systems still do its calculation on each entities. I find it not really performant to be honest. So I want some kind of filtering, where depending on the distance, the systems doesn't need to iterate through all entities, but only those who are nearby the player. I have now queried all entities and put it to a job, where I put nearby entities to a nativelist. So my question now: How do I iterate only through the entities inside the list with the foreach lambda expression? Here is my code example: https://hastebin.com/hagiqinoli.cs
If you want to use a query (or indirectly by using ForEach args) then you'd have to have a tag component on the entities that are within range of the player. So you'd have a process to apply/remove tags, and then you can simple WithAll<NearPlayerTag>() in your ForEach chain.
Alternatively you can maintain a collection of some sort for the entities within range of the player, and then iterate your collection using Job.WithBurst()
Since this is using ForEach in SystemBase, you can use GetComponent instead and iterate over your list of entities
It will compile down to a GetComponentDataFromEntity
@mint iron tagging the entities nearby is a good idea. I have to test it, how performant it will be. The other option with Job.WithBurst(). Is it something that I can also parallel schedule?
Note that tagging will temporary change the archetype of the tagged entities, making them move chunk. And then later when removing the tag, doing the whole move again
Hello, i recently got into learning about caches/temporal locality/spatial locality and was wondering if i understand things correctly about it. I need a way to store data into a NativeArray for a quadtree. I was wondering which of the 2 ways of storing nodes is more efficient for spatial locality, by depth or by parent -> node hierarchy. Presumably for the purposes of traversing the tree in a "parent -> children -> deeper children fashion". I presume it's the latter since there's less jumping around inside the array, but am not sure. https://i.imgur.com/ZxTPa8l.png
@stiff skiff I am not sure how GetComponentDataFromEntity would help my cause. I mean Of course I can get lets say a nativearray from the position of the entities. But than I still have to compare it to my player position and than sort out the entities, that are far away. Maybe I am missunderstanding something ๐
If I understand correctly, you want a first pass grabbing all nearby entities
@stiff skiff yeah tagging will change the archetype. thats a good point. I have to test it, if this way is expensive
and then a second pass of logic with ONLY those nearby entities
yes I want grabb all nearby entities. and than I want all systems only running through the nearby entities and ignore basically the others
When you say "all systems"
you mean systems that run after that filter step?
Or a few methods
ideally all my systems. I also dont want the entities to get rendered for example.
Right, then the tag component is the way to go
@thorny halo you want to maximize the possibility of reading data right next to each other, i did something similar recently and the octree would scan all 8 at a certain depth together, the Aabb were layed out all right next to each other in memory, so it could be done in two sets of 4 bounds (the bounds (aabb4 was restructured so all the x's were together, all the y's together etc so they can be hit at the same time with SIMD)
also checkout this vid https://youtu.be/WDIkqP4JbkE?t=81
code::dive conference 2014 - Nokia Wrocลaw
http://codedive.pl/
Do we actually have any tools for C# / Unity to profile cache / branch misses?
Its something I miss from my C++ projects
@humble falcon why not just list all entities nearby in a dynamicbuffer?
there's a Code Monkey actually has a video about it.
โ
Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=XC84bc95heI
Let's learn about Dynamic Buffers so we can store multiple values inside our Unity DOTS ECS Components. (Array, List)
Unity DOTS ECS Playlist
https://www.youtube.com/playlist?list=PLz...
the example project he used later in the vid lists all entities nearby
im still going insane trying to work out how to use an ECB, please can anytone show me there init code? Something like?
EntityCommandBuffer entityCommandBuffer = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
Cannot implicitly convert type 'Unity.Entities.EndSimulationEntityCommandBufferSystem' to 'Unity.Entities.EntityCommandBuffer'
Argh, I been reading version 0.0 docs ๐
Im so damn dumb
I am having some problems with Unity DOTS:
โช UI
โช Animation
โช Sprite sheet
โช MonoBehaviour accesses Components inside Entities
How can I implement these things?
@deft stump I am aware of that video. I used dynamicbuffer for other stuff. For my usecase this approach is only possible if I have multiple bufferelements, because I am using multiple archetypes.
@wide fiber Regarding your fourth point, not sure what your usecase ist, but you can simply write some kind of HybridConversionSystem. Lets say you want a monobehavior to be aware of the position of an entity. In OnUpdate you than have to access the monobehavior object and pass the position from the entity.
does anyone know what the ScheduleTimeInitialize is all about and why it's so high?
@humble falcon thanks I'll try your solution :D
I don't suppose anyone has any idea how I would move something at a constant speed, by using the total distance(calculated) with a variable frame rate
@pliant pike So you want to move your object from one position to another position with a given time?
yeah basically I want to move something along a spline with a constant speed
I can calculate the length of the spline roughly enough
If you know the length of the path you can get the speed, then you should use Time.DeltaTime to make it frame indipendent
yeah I just need to move it a specific distance each frame
I guess I could divide the total length into parts and then move it a certain amount to each of these over time
@humble falcon so inside a system base I should get a reference to the MonoBehaviour and set the values based on the component of an entity? How can I get the MonoBehaviour reference
thanks for the help guys ๐
I guess I could divide the total length into parts and then move it a certain amount to each of these over time
@pliant pike I can't understand the problem, is this a math problem? Do you have a time value and a target position and you need to get the speed needed to reach the target?
@humble falcon so inside a system base I should get a reference to the MonoBehaviour and set the values based on the component of an entity? How can I get the MonoBehaviour reference
@wide fiber Assuming you're using ConvertAndInject, you can access the MonoBehavior as the first param like soEntities.ForEach((Animator anim) => {})
yeah I think I'm getting it now just divide time by distance to get the speed, then use that to move it like speed * time.deltatime etc
@wide fiber Assuming you're using ConvertAndInject, you can access the MonoBehavior as the first param like so
Entities.ForEach((Animator anim) => {})
@coarse turtle ok thanks, but if I don't convert the MB GameObject to an entity what can I do? (I can't convert UI to entity because it wouldn't work)
You could try doing a "hybrid component"
which I believe is EntityManager.AddHybridComponent(Component component)
you still attach a ConvertAndDestroy
Ok
and the entity associated with the gameobject is hooked via a CompanianLink component
so CompanionLink.Value -> should return the associated gameObject
๐
The UI doesn't work, I've added all the hybrid components to my text GameObject (TextMeshProUGUI, CanvasRenderer and RectTransform) but it is invisible
o dang ๐ค
anyone have any tips for handling ui input? I'm thinking of having a controller singleton component and having the ui monobehavior make changes to the singleton component's properties, and having a inputHandlerSystem process the changes. However I cant work out how to guarantee the ui will make the changes before the inputHandlerSystem runs
what about using a flag field (something like isDirty) in the component, then having the monobehaviour set the dirty flag to true, then let the handler system run only if the flag is true and then reset it after execution ?
does anyone know how to get an instance of a system in a system?
World.GetOrCreateSystem<T>() ?
Ah sweeet thanks so much
was using GetExistingSystem ๐
why would you ever need that one
I use get all the time
dont want to risk creating a system
as i have my own system init flow
and in the latest entities they made it safe to use Get in OnCreate of a system
is there any way to draw debug lines from inside a system's ForEach loop?
i'm on the 2020.1 beta
@craggy hinge Only without burst and no threading
So use .WithoutBurst().Run()
instead of schedule...
yea
i really want a new debug tool, that will work in dots and in builds
but dont want to build it
๐
hahaha very relatable mood
they're too thin. they slice your gpu all up
haha yup thats it
Only without burst and no threading
@ocean tundra @craggy hinge You can now draw line in bursted job without any problems. Only limitation is amount of lines. And it can be expanded by Unity run arguments.
oh sweet, thats good
Dear community. I have got a small question. Maybe I missed something, but where in Entities.ForEach do I get the jobindex. ECB.AddComponent needs three argument the jobindex, the entity and the component. The manual doesnt really help either.
ah there it is. well I was reading only the section about the entitycommandbuffer. So basically I have to use the EntityInQueryIndex as jobIndex. Thx @storm ravine
I have a weird behavior in Dots Physics :
When moving a character (via PhysicsVelocity), it get bumped like crazy.
This happen even using a basic sphere on a basic Plane, but not if its moving on a same-sized Box.
It seems to happen only with MeshCollider, and behave kinda like if the engine was considering every polygon ridge as a different collider or something.
Is this the intended behavior and/or what do I need to tweak to be able to walk smoothly on anything else than Sphere&BoxColliders ?
how do I use the new input system in ecs?
You need to install it from the package manager first.
And it will completly disable the standard input system, so make sure you are ready to update everything.
@scenic oracle I'm familiar.
What I'm more concerned is implementation.
Implementing New Input System in Mono is quite easy (given that there's plethora of tutorials on it)
as for implementing it in ECS. there's none.
Not sure what you mean.
Just extract all the values at the start of your "OnUpdate(JobHandle JobHandle)", so you have them as local variable before the "Entities.ForEach".
So currently my world is just a large texture that the player flies across, it can currently handle 1,048,576โฌ tiles. Do you guys think it would be worth changing this to using Entities? Would there be any benefit and would Entities be able to handle that amount of tiles (and more)?
I'm pretty sure it wont be able to handle over 1,048,576โฌ entities correct?
the overhead of a million entities would be about 16+ megabytes
and slow everything else down a bit
if you do it smart tho
1 entity every 8x8 tiles or similar
then it could be alright
Yeah but I could do that with gameobjects. I don't think there would be a big difference
Hello, I am looking for a way to destroy child entities automatically when the parent is destroyed. The Forum posts I found are extremely outdated. Does anyone has a more current solution?
@odd cipher ah sure, entities have much lower overhead than gameobjects
having a million of them isnt good, but miles better than a million gameobjects
which i dont even know how it even ran
I don't have one gameobject per tile that would be insane, I have one gameobject that has 1,048,576 tiles in it, through a texture.
using a texture means that I have a max of 8192x8192 pixels but I could fix that by just having more than 1 texture for the map.
Hello, I am looking for a way to destroy child entities automatically when the parent is destroyed. The Forum posts I found are extremely outdated. Does anyone has a more current solution?
@storm current LinkedEntityGroup. Should include entity itself and every entity which should be destroyed\created as group. Nothing changed. If you converting prefabs - it's already have LinkedEntityGroup. Otherwise - create it by yourself
@vagrant surge ^^
@odd cipher i would assume loading and accessing data as entities would be slower than a simple 2d array access like you have now. Should you do it? probably comes down to if it provides some kind of acceleration for your accessing needs.
For example say you're primarily accessing a specific index pair and iterating from that point, entities would be problematic - because its split into chunks you can no longer access it by array index on the whole.
If you used SharedComponentData for grouping entities into spatial chunks you could then find the right data and iterate within that region. Then if your systems work over a subset of spatial chunks (like the current + nearest edges where they might overlap) and add components to specific entities so that they can be quickly found in ForEach queries, it could be quite clean and tidy.
But a million is still a lot..... maybe consider making larger buckets and dynamic buffers to hold whatever is inside, or use a dynamic/sparse grid approach so you don't have a fixed overhead even in areas of the world that are not being used.
@storm current LinkedEntityGroup. Should include entity itself and every entity which should be destroyed\created as group. Nothing changed. If you converting prefabs - it's already have LinkedEntityGroup. Otherwise - create it by yourself
@storm ravine Thanks, I will look into it ๐
Hmm, I feel like the system I currently have is good enough, All I have to do if I want to support more tiles is to divide the texture into multiple textures. For example if I have 4 textures and each go up to its maximum 8192x8192 size and the terrain sprite size is 8x8 then if my math is correct I should be able to handle 16,777,216 tiles with just 4 gameobjects. And so on
think about the data, thats the gist of data oriented design
don't try to morph your requirements to fit into entities or gameobjects etc
consider your access patterns and choose the simplest approach
although unity says it is performance by default, simply switching to entities won't give you any benefit if you don't think about the data
the big difference though, would be burst and the job system
which can be used outside of ecs
I would recommend that you try to use that to its fullest potential
Yeah, most of my game is data oriented, Everything visual with the map is essentially done with one class
And yes, I do use Burst and Jobs. With that I am able to generate a 1024x1024 (67,108,864 pixels) world in 1200ms. And a 200x200 world in 13ms
when it comes to processing data, say in an Entities.ForEach
If I have an unlimited amount of data, you think I could just say
if delta/time > X return // inside loop
and it can pick those jobs up another frame
@deft stump this is how i based my own usage of the new inputsystem with dots https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/d616c1b077c306e6f31b41a3970799e4b132139b/UnityPhysicsSamples/Assets/Common/Scripts/DemoInputGatheringSystem.cs
When inside a job (Job.WithCode) and I'm using a concurrent entity command buffer where/how do i get Job Index?
just include.... int entityInQueryIndex
as a parameter in the foreach
ah sorry I probs gfot that wrong for jobs.withCode
Why you using concurrent entity command buffer with Job.WithCode in first place
It's single threaded codepath (main thread if Run and any worker thread if Schedule)
any idea how to make this dang buffer readonly: https://pastebin.com/SE65Q3rJ
and burstable
soemthing to do with[NativeDisableParallelForRestriction]
the blockTypes?
You could try blockTypes.AsNativeArray() and pass it to the lambda using WithReadOnly(...)
to the foreach statement
Sounds good, you got an example of that? in here? .ForEach((Entity entity, int entityInQueryIndex, WithReadOnly(var blockTypes.AsNativeArray())
var blockArray = blockTypes.AsNativeArray();
Entities.WithReadOnly(blockArray).ForEach(...);
ah okiess
noice
Thanksa
argh WithReadOnly requires its argument to be a local variable that is captured by the lambda expression.
well blockArray would be a local variable
is there a dots equivalent to the CharacterController component?
@gusty comet I am not aware of an already written charactercontroller component in dots. But why didn't you just write one for yourself. There are lots of tutorials out there. ๐
But why didn't you just write one for yourself.
@humble falcon i don't want to, that's why
also, all these tutorials make use of physics, which i don't want
i just want the vanilla charactercontroller in the non-dots unity
Doesn't that make writing one even easier if you dont want your character interact with physics? Well in that case I would just rewrite the standard character controller in ecs. It will not take much time anyway. Regardless you will have to write your own character controller. But maybe I am missing something and there is a prewritten component.
@gusty comet I can totally understand not wanting to write your own implementations of everything - but fair warning - working with ECS at the moment is a lot of that.
@gusty comet What is the usecase for why you want to use the standard one in ecs? You dont have to. Use ecs only if it is really usefull for your scenario. You can also only use the one from unity and if you have entities in the scene that need to track the player position, you can just do that by having an playerentity that is only tracking the position of the player gameobject.
guess i'll just use physics since there's no other way
people seem to forget that the reason you use a ready made engine is so you don't have to build all of this yourself...
How do I iterate through entities within foreach job?
https://hatebin.com/zpqsqcrqeq
D:\Gamedev\Dots\Assets\_Game\Scripts\Systems\MouseLookSystem.cs(13,9): error DC0023: Entities.ForEach uses managed IComponentData MouseLook&. This is only supported when using .WithoutBurst() and .Run().
oh it doesn't want it if I put in MouseLook in the for each lambda
I doubt the in modifier does anything for burst
welp turns out i was wrong with tying camera to dots anyway
it seems i do need to put camera into dots because the physics will just overwrite the rotation i assign
@frail seal Please specify. I mean Entities.ForEach is already iterating through entities. Or do you mean within. If that is the case. You have to put the entities in an native container and inside the job you go through the native container.
Dear community, I am currently facing performance problems right now cause by the RenderMeshSystemV2. As you can see in the picture. Even though I am not facing any entities at all, the RenderMeshSystem seems still to go through my entities. Looking at Hybrid Renderer it should get culled, but somehow its not. The only option I have right now is removing the RenderMesh component from the entities altogether. But I am not sure if that is the right approach... I am kinda stuck right now.
downgrading is always an option. i've gone back and forth multiple times within the same project
Yeah there is no automatic culling afaik, you have to do it manually
@opaque ledge yeah I even made LOD Group, and the entities got culled visually, but not performance wise... it really sucks right now...
Itโs not true. They culled. Frustrum culling on the place and works as expected, depends on pivot and bounding box. You can see that render thread just near to idle state. System process entities of course, because it should check if they inside frustum pyramid or not, it not happens magically, itโs obvious frustum planes check. Moreover matching entities doesnโt mean they all will be processed, because it not show your change/order filters. Also, side note, I guess you not enabled hybrid renderer v2 define?
@storm ravine what do you mean by hybrid renderer v2 define? Well I am using hybrid renderer v1 because my project is running on version 2019.9f
Then v2 not enabled and you using HRv1 which wasnโt so good in performance. Unity improved performance on CPU (and GPU) with V2 version (require SRP 9+ and 2020.1b8+)
Oh ok so basically, It would be wise to switch to version 2020+ so that I get the performance benefits from V2 ... I was thinking about another approach. Is it possible for RendererMeshSystem to only interate through a filltered entities. So that it is not checking for all entities.
Because I am using a Tag right now called InvisibleTag and I put the tag to entities that are not visible. But I dont know how to access the renderermeshsystem
In v2 they added DisableRendering
Before with that tag I used to remove the RenderMesh component of an entity. Which really helps cutting performance, but I had trouble to add back the rendermesh component
You can use that for fully exclude some entities from rendering and processing temporarily
yeah I saw that component in Unity.Rendering.Hybrid. I add that component before instead of my invisibletag. But if you say it only affects v2. Than it is not working for V1
Yes
Well you can override render mesh, just made it local package (for prevent resetting on every editor restart) and change rm system code, itโs implementation simple and editing pretty straightforward.
is there an example how to do that. Because I had trouble doing something with rendermesh.
ah you mean replacing rendermesh altogether. ok I will try it than.
Not replace, edit
hello! I'm quite new to ECS, still trying to wrap my head around some basics. say I've got a system like this:
foreach_pseudocode((in FakeComponent1 comp_1, ref FakeComponent2 comp_2) => {
int c = comp_1.a + comp_1.b;
comp_2.value = c;
}).schedule
``` my instinct here would be to pull c out into a higher scope so I can avoid a ton of allocations, but then I can't run this threaded since I keep modifying it (makes sense). what's the smart way to do this? do I really reallocate it every loop?
structs typically aren't heap allocations so you don't have to worry about it. also, for simple statements the compiler will usually re-write it as comp_2.value = comp_1.a + comp_1.b so it literally doesn't matter if you want to separate it out for readability reasons.
I think int c would be allocated on top of the stack and not the heap
so I have a new input system with dots problem.
Entities.WithoutBurst().ForEach((ref PlayerMovementData movedata) =>
{
//this code here doesn't work
movedata.direction.y = (upMovementControl != null &&
upMovementControl.wasPressedThisFrame) ? 1 : 0;
movedata.direction.x = (rightMovementControl != null &&
rightMovementControl.wasPressedThisFrame) ? 1 : 0;
//while this code here works
movedata.direction.y = (downMovementControl != null &&
downMovementControl.wasPressedThisFrame) ? -1 : 0;
movedata.direction.x = (leftMovementControl != null &&
leftMovementControl.wasPressedThisFrame) ? -1 : 0;
//why?
}).Run();
for context.
I'm trying to emulate the GetKeyDown() in the old input system using the directional keys with the new input system.
So I made this hacky code smell way of doing it. Where assigning the value of 1 in the component gets assigned on that frame, and then goes back to 0 on the next frame and waits for input.
In any case, the bottom pair works. but the upper pair doesn't.
Your bottom rows override top rows always, you didn't see that? No matter what values you set on top, bottom always override it to -1 or 0
it works...
frick...
you're right.
I just commented the bottom pair
@storm ravine thanks 
looks like Entites.ForEach do not support generics :|
error DC0025: Entities.ForEach cannot be used in system MySys as Entities.ForEach in generic system types are not supported.
and IJobForEachWithEntity which does support generics is marked as Obsolete
Please use Entities.ForEach or IJobChunk to schedule jobs that work on Entities. (RemovedAfter 2020-06-20)
so looks like the only way to do a generic job that iterates over entitles is to use IJobChunk or to use manual iteration
I'm not sure what I did but unity keeps crashing from one of my jobs (I think) is there a way to know what happened?
Yeah.. I don't think I can figure it out from that
turn off burst and set a breakpoint in the job, if there's no issue and its only occuring in burst... then... yeah
also try load up the .dmp file from crash logs dir run debug as native and check the callstack
Right I think one problem is that I use somenativearray.GetSubArray(start, length). it seems to be really slow
maybe not actually.. idk
I cannot figure out why its crashing..
Actually. Got this "IndexOutOfRangeException: Index 640000 is out of range of '640000' Length"
I don't get why thats an error though
@odd cipher max index is length - 1 >.>
I havn't had that problem before..
Still havn't been able to figure it out.. it might have to do with this csharp for (int x = 0; x < spriteSize; x++) { int pixelX = (t.x * spriteSize) + x; for (int y = 0; y < spriteSize; y++) { int pixelY = (t.y * spriteSize) + y; colors[pixelX * textureHeight + pixelY] = c[x * spriteSize + y]; } }
it only sets half of the texture
What you trying to do. Show full code. Because pixelX and puxelY very questionable.
If I can, should I seperate my entity, into multiple entitys? (Adding I guess overhead) e.g. BuildingMeshEntity, BuildingMeshVertsBufferEntity, BuildingMeshTrisEntity. Or I can just add all these buffers to one entity without any issues?
there >16032kb or whatever it is
@storm ravine alright so that loop is done per tile in a job. Itโs supposed to set the tileโs color array (c) onto the worlds color array (colors) but it doesnโt really work correctly
Should I use Mono or IL2CPP as script backend for building burst projects?
Just made an IL2CPP build and it performs worse than in editor
Leading me to believe it's not burst compiled
๐
Strange. Because it is slower
Probably isn't getting compiled with Burst after all
Profiling time!
Heh:
42 milliseconds waiting for something
But hey at least it's being burst compiled!
looks like vsync waiting for frame to keep target fps
Yep, but I haven't set any target FPS
Just vsync to every vblank
Let's try to set the target fps to 60, then
That made it worse ๐
what is the issue though, you can basically ignore it, its going to sleep because it doesnt need to work...
@storm ravine alright so that loop is done per tile in a job. Itโs supposed to set the tileโs color array (c) onto the worlds color array (colors) but it doesnโt really work correctly
@odd cipher show code. That loop looks fine, your t.x/y is your tile offset in global โcolorโ array and you set it, need to see your setup, and exact error from console
what is the issue though, you can basically ignore it, its going to sleep because it doesnt need to work...
@mint iron not when it become 15fps and 60ms ๐
help me understand here ๐
if your frame is taking 15ms, then its going to wait for 45ms doing nothing.
why is that bad?
if your frame is taking 15ms, then its going to wait for 45ms doing nothing.
@mint iron look at his profiler, if it 30-60fps limit that fine, but as you can see - it drop frame-rate to 15FPS and that absolutely not fine ๐
ahh yep. thnx, i see now.
@outer swift that build profiling? In editor all works fine?
@storm ravine That's build profiling, editor looks fine to me. 10ms idle until render, which looks about right
Itโs not idle itโs editor overhead, your frame timing ~4ms which is ~250fps
If you disable vsync for build does it change fps?
Because in build your PlayerLoop timing definitely should be better than editor
Hey all, I worked through the NetCode "Getting Started" example and am having issues getting things to display. When I open the Entity Debugger I see that there are two worlds, DefaultWorld and ClientWorld0. There are no entities in DefaultWorld, they're all in ClientWorld0. The thing is... I don't see any entities in the game view. I have a top-down camera for testing right now. Am I missing something?
Does this have something to do with the camera rendering DefaultWorld instead of ClientWorld0 or something?
@storm ravine I tried with vsync and no target framerate, I tried with vsync and target framerate of 60 and finally no vsync and unlocked framerate. All performed equally bad. The worst was no vsync and unlocked framerate, which would occasionally take 100ms per frame
Twitter thread with screens: https://twitter.com/Slaktus/status/1264579258074177539
@sebify I haven't set any target framerate at all, just set vsync to every vblank. Let's see what happens if I set target framerate to 60 ...
Looking for screenshots from thread it feels like you GPU bound... what happens on screen which give you this profiling data?
Not much. 100,000 cubes with unlit material.
I have no problem rendering scenes with millions of polygons across throusands of objects in other projects.
102 batches, 99898 saved
My specs:
- Ryzen 2600x
- 16GB DDR4 PC-3200
- AMD RX580 8GB
- Project running off Samsung 970Pro M2 SSD in a 4x M2 slot
Guys I am trying to create a game using Unity Tiny, I have installed the package (0.25.0) but I don't have a create tiny project button
@wide fiber its not possible to create a unity tiny project easily
the recomended workflow is that you clone one of the samples and start from there
@outer swift does the gpu profiling section say anything during build version?
turn on the 2nd one if you haven't already
@hollow sorrel Looks like Hybrid Renderer V2 doesn't like GPU profiling
@outer swift try disabling graphics jobs in player settings
i think it only works without
But how come it works fine in editor?
Are builds and editor literally running different code?
I'm getting above 300 fps on windows platform but, when I test my game on a phone I'm getting max 10 fps does anyone know why?
@vagrant surge ok ty
what's the best approach to do gird movement (like Megaman Battle Network) in dots?
@deft stump I would probably make a int3 position component which then updates the Translation component with int3Pos.x * tile size
then all your position changes go into the int3 one
but translation and all dependant systems continue to work fine
Where do i put the check if the tile is for the player to move in or not?
Do i make a component for that?
probably do that before you update int3 position
so you will need some sort of Map representation for now lets say your using the 2d native collection from (https://github.com/jacksondunstan/NativeCollections)
which is <int2, bool> (position, walkable)
then you just need to check if map point is walkable
Does anyone know the right and updated approach to do animations? So I have a 3D Model which has an Idle animation. Obviously in dots I can't simply use the Animator. How do I than achieve my goal, just making my entity doing its idle animation.
so theres 2 approaches I've seen
1 is use Unity.Animation, its still VERY alpha but had a update recently
- Do it yourself ๐
i've copied this from someone a few days ago:
I have a script adapted from GitHub + shader for GPU animations.
The requirement for the device was ES 3.0+ (to extract Vertex ID: SV_VertexID) and animations must be of type "Generic"
A bit dirty code, in a hurry, removed the part of custom rendering...
The shader has 2 uv channels, a color map is stored in the second channel.
"_BaseColor" - the color of the repainted part is superimposed on the second channel, you can delete it if you do not need to.
In the comments I tried to note this
Shader - https://pastebin.com/yfx4RsMc
Animation asset - https://pastebin.com/QD9U7Nn6
AnimMapBaker (EditorWindow) - https://pastebin.com/UP3M3Xan
AnimMapBaker (Main part) - https://pastebin.com/Kz51pkfh
personally when i start with animations im going to try to use Unity.Animation
mhm so there is really no straightforward simple solution to do that... Ok I will look into Unity.Animation than.
Extremely stealing that code
ugh those are the ones I hate the most. No docs. So basically error and trial than ๐ซ
heres some examples but theres a new animation update
I'm already having fun writing physics, collision and camera code from scratch ๐
@outer swift Theres Unity.Physics which also has collision bits
I know, but last I checked it was slower than my implementation.
I don't need anything complicated.
yea makes sense
all i need is the collisions bit
i eventually plan to rip that out from the sim bit
Then again, I haven't checked in a very long time, so it might have picked up. But I remember it having some ridiculously uneven performance even on a small number of bodies.
Anyway my experimental DOTS game is essentially a 2D top-down game using 3D art, so I can use 2D colliders and that's what I intend to do.
yea smart
It definitely doesn't look like DOTS is ready for anything complex, so to avoid snagging on obvious missing bits and being able to focus on learning design patterns and figuring out an architecture for handling a game in DOTS, I'm just aiming way low.
Especially since I suffer from a serious case of I don't like this API
Which inevitably leads to me implementing my own
Like Unity's filthy goddamn event-based collision
yea i have decided no reimplementing things unless i 150% need it
I value my sanity, so instead of wrapping Unity's collisions I just wrote my own simple SAT implementation
After I realized that "oh I can't actually rely on collision events to fire" I decided that nope
"Why isn't OnColliderStay firing?"
"Why isn't the collider interacting with the trigger?"
"Why does the rigidbody change the behaviour of the collider?"
rabbit holes ahoy, and I prefer to fly rather than dig
yea all those were so annoying
i think thats why i like DOTS so much, all the code is there for us to look at, and change if we really need to
So the idea of doing the things I need doing (procedural IK and soft body physics) with Unity's PhysX implementation constantly acting up ...
... nahhh
Yes, it really cuts to the bone of why I like Unity: It's a Make Your Own Engine framework
After upgrading my project's ECS package from preview 15 0.9.1 to preview.6 0.10.0, I've been having this error pop up once for every GameObjectEntity in a scene after performing scene reload or level change. It doesn't seem to be breaking anything. Rolling back to preview 15 0.9.1 fixed this, is there a better way to go about scene reloading that will avoid this issue? If not, how/where should I report this issue?
//This is the code used to reload the scene
public static void ReloadScene()
{
instance.StartCoroutine(RestartEntityWorld());
Debug.Log("Loading scene");
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
Debug.Log("Scene loaded");
}
private static IEnumerator RestartEntityWorld()
{
Debug.Log("Wating for end of frame");
yield return new WaitForEndOfFrame();
Debug.Log("Frame complete");
World.DisposeAllWorlds();
Debug.Log("Worlds disposed");
DefaultWorldInitialization.Initialize("Default World", false);
Debug.Log("Worlds reinitialized");
}
so.... wont that reload code load the scene first then dispose and recreate worlds
idea 1, dont dispose all worlds, just save and dispose the main world
as theres some magic worlds created via unity for loading/conversion
idea 2, dont use scenes and instead use sub scenes
i will add i dont feel subscenes are ready yet
i've tried to use them and hated it
Yeah in theory it should destroy and then reload all systems. I think your first idea for saving the worlds initial state as a seperate world would work well with my current set up (better atleast then sub scenes lol)
yea thats what i do
i manually create my worlds
do some custom init stuff
and update / destroy them as needed
Ahh does that let you add and modify individual systems?
yea
that DefaultWorldInitialization has a get all systems method
or something like that
2 sec ill find the code
Interesting! I would love to see that actually haha
I imagine that that would be how I would copy the starting state
how do you post code :/
ty
var world = new World("Server");
var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default, false);
var filteredSystems =
systems.Where(x =>
{ //CUSTOM FILTERING!!!!
DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, filteredSystems.ToArray());
Oooo
the catch with this approch is i dont have my world auto added to the update loop
so i have to call world.update manually
but thats something i want
Huh where do you call it from?
a monobehaviour Update
I've been wondering when the main Update is being call compared to the Mono update
๐
Oh cool lol
I think that will work!
One last question
When are GameObjectEntities loaded into the world? and how do I make sure they get loaded into the startingWorld?
Oooo interesting question...
so i dont use those
but that new world you could set to World.Default injection world
then load your scene
that has all the GameObjectEntities
Aw dang, do you use authored components?
Ooh yeah and then just copy from default without running any systems
i use the conversion flow hard, all my prefabs are converted just after that world creation code and i create them as needed
I should be doing that but I'm too lazy lol
I'll go with copying from the default world
if you replace world.Default.... the GameObejctEntities should go right into your world
ye?
custom worlds that are manually updated DONT show in the DOTS tools correctly
the systems dont show ๐ฆ
its annoying but i can work around it
the entities still show
Oh shoot, like in the analysis tool?
yea
Oh phew, thats not too big of a deal for my current workflow
but still kinda annoying
I swear there was a drop down to select the monitored world at some point
yea its just annoying
they are working on it
there is
and it works with the custom world
but the systems just dont show unless you use the default update
but you can grab that from the DefaultWorldInitialization somewhere
Mm okay yeah that makes sense
but if you do that dont manually update
This might sound weird, but could you use the default world Update to update system from another world?
probably
i kinda do that too
i make a few extra system groups
and update those at different frequencys compared to the main default groups
you just call Group.Update
Ooo intresting like a LowPriorityUpdateGroup that's only called X amount of frames or something?
Damn thats clever haha
thanks
and i have things like my server only updating in FixedUpdate
and some systems updating in normal update at X frames
ect
Heh I might need to steal that thats great lol
also adding a custom world to default update is super easy ( ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); )
I wonder if it would be better to update your server on a seperate thread instead of fixedupdate because of the jankyness that is how untiy handles fixedupdates lol
Oh sweet!
i read up on ity
havnt tried yet
but looks like there are issues with that
something around job scheduling from another thread
but a persistent thread or something, thats well above my head lol
yea
lower frequency is good enough for me for now
if running a whole world completly in a background thread becomes stable ill jump at it
but i expect it to be way down the todo list
if at all

