#archived-dots
1 messages · Page 146 of 1
Hehe time to get stealing I suppose!
I think this should work, if I get stuck can I ping you?
sure
Anyone experienced or know what this error might come from?
@mystic mountain are you using NetCode?
Yes
i saw something about a max size for packets/rpcs somewhere
that would be my guess
but im not using NetCode and havnt seen anything else that could give any hints
it might have been related to the number of rpcs... but i could me making things up :/
Hmm ok, I pinned down it to come from send system, but you might be right, I wonder what is causing it though, because I'm not really sending much.
lots of RPCS? or maybe lots of data
Not really... I haven't even connected yet.
@mystic mountain maybe its building up a buffer of data for some reason, but cant send it as its not connected?
Can't tell yet. I've pinned it down to be from my CharacterGhost by disabling it in the collection. But I don't even get into the OnUpdate of the SendSystem, so I'm a bit confused x)
So, I've at least pinned down that something here, or the amount of components used here, is causing it... https://pastebin.com/Jfm8Nk0T
in unity's guide for using entities.foreach they give an example of modifying a native array in entities.foreach and then reading the array in a job.with code. surely you'd have to pass the entities.foreach's job handle into the job.withcode for this work?
private EntityQuery query;
protected override void OnUpdate()
{
int dataCount = query.CalculateEntityCount();
NativeArray<float> dataSquared
= new NativeArray<float>(dataCount, Allocator.Temp);
Entities
.WithStoreEntityQueryInField(ref query)
.ForEach((int entityInQueryIndex, in Data data) =>
{
dataSquared[entityInQueryIndex] = data.Value * data.Value;
})
.ScheduleParallel();
Job
.WithCode(() =>
{
//Use dataSquared array...
var v = dataSquared[dataSquared.Length - 1];
})
.WithDeallocateOnJobCompletion(dataSquared)
.Schedule();
}
Ok, so removing the duplicates of ComponentDataFromEntity<AbilityStateData> solved it for now.
it says in the job dependencies section: "If you write a NativeArray in one job, and read that array in another, you must manually add the JobHandle of the first job as a dependency of the second"
dunno if ithis is a mistake or I'm misunderstanding job handles
@leaden hatch It's in SystemBase?
If yes - SystemBase track it automatically. It has Dependency property and if you not specify different behaviour, it will put all ForEach\WithCode in dependency chain
so they will depend on each other in order top to bottom if you dont specify a dependency? @storm ravine
Yes
Ok thankyou
is it too late to float the idea that implicit dependency management is a really, really bad idea
considering the frequency of this particular question
Yeah I'm not a fan of all the hand holding
I rather have to do it myself, and have tools to help me understand it, and debug any issues
crap like this is why statics are such a problem too
I'm not a fan of all the recently added "Magic"
For example, trying to use a NativeQueue<T>.ParallelWriter in a job, and using the WithDeallocateAfterJob thingy.
Only to have it complain that you aren't using the thing you're trying to deallocate. Even though the use case is fine, and it will work fine, but the "magic" wont let me
anyone familiar with a custom ComponentSystemGroup used for command buffers? it's slow and I'm not sure why
So i am getting error about native list being disposed
Debug.Log(attackerFleet.Length);
Debug.Log(defenderFleet.Length);
Debug.Log(currentFightStatistics.attackerShipsStart.Length);
Debug.Log(currentFightStatistics.defenderShipsStart.Length);
currentFightStatistics.attackerShipsStart.AddRange(attackerFleet);
currentFightStatistics.defenderShipsStart.AddRange(defenderFleet);
Debug.Logs works fine but at first AddRange it gives that error
These are being called from monobehaviour
all of them are native lists
must be being disposed elsewhere, the logs reading the length wouldnt trigger the error since its just reading a field.
Hi guys. Have you ever encountered flickering problem in dots. I have a very strange problem. Up until now everything is working fine. I did than only change the texture size and suddenly the entities are still being rendered but it flickers. So I went back to an older version, where I have not done any changes at all, but the flickering problem remains... Any ideas?
okay so, instead of Temp allocation i did Persistent and dispose them later on
Hi guys. Have you ever encountered flickering problem in dots. I have a very strange problem. Up until now everything is working fine. I did than only change the texture size and suddenly the entities are still being rendered but it flickers. So I went back to an older version, where I have not done any changes at all, but the flickering problem remains... Any ideas?
@humble falcon explain further, what flickering? Rendering itself or shadows or something else?
ah new packages!
not the biggest of updates(notes dont appear online yet)
## [0.11.0] - 2020-05-25
### Added
* Added `ArchetypeChunkComponentObjects<T>.Length`
### Changed
* Updated package `com.unity.burst` to version `1.3.0-preview.12`.
* Improved `ComponentType.ToString` names in DOTS Runtime to provide the full type name when available, and if not, default to the StableTypeHash.
* Updated minimum Unity Editor version to 2019.3.12f1 (84b23722532d)
* `EntityManager.Version` and `EntityManager.GlobalSystemVersion` will throw if the manager is not valid instead of returning 0.
also new hybrid package
i wont spam chat further than that more notes under deprecated, removed and fixed
hrmmmmmm let's see if they made any breaking changes

me: making an actual game in dots.
also me: breaks my game because dots is still in preview. thus making dev time longer
ah hybrid is one of those updates 🙃
## [0.5.1] - 2020-05-25
### Changed
* Updated dependencies of this package.
* Updated minimum Unity Editor version to 2019.3.12f1 (84b23722532d)
so it's just the entities package
@safe lintel any link to the changes?
thank you
‘Deprecated system sorting via virtual functions and direct modification of system list’ hmm
it will be replaced to better thing for bursted systems.
And as you can see [UpdateXXX] extended
I'm wondering what the implications are (if any) for creating system that run at edit-time without a subscene being open.
Is the performance in any way dependent on the order of shared component filters when I have multiple of them? For example, if I have an entity query and want to apply one filter that I expect to return most of my entities and a second that will only return a smaller fraction, should I expect a difference in performance based on which I do first or nah?
Or doe queries/filters not work like that at all
supposedly, there shouldn't.
although doing a query within a query to get a subset from the first set is a code smell imo.
why can't you query the entities that you really want the first time?
There's no reason I can't, I suppose. I wasn't sure if SetFilter/WithSharedComponentFilter allow multiple arguments
supposedly, there shouldn't.
although doing a query within a query to get a subset from the first set is a code smell imo.
why can't you query the entities that you really want the first time?
@deft stump Not at all. It's absolutely valid, useful and recommended approach if your data divided by SCD. Moreover, you can't query by EntityQuery values with exact SCD. And this EQ can contain a different count of subsets which divided by SCD. The only way for that is SCD filter (or manual chunk iteration with SCD index).
Oh so it's a valid approach.
@timber rivet why you decided order affect performance in your case? What profiler told you?
I haven't tried either way yet, I was just wondering as I'm figuring out how to iterate over these entities the way I want to
I have otherwise identical entities of which some need slightly different calculations, so I gave them a type component that differentiates them, and I'm also filtering so that only a fraction is updated every frame and each individual entity basically updates every N frames... but at that point, come to think of it, it's probably easier to just give them different components in the first place and have only one query filter each
oh, full Burst 1.3.0 (no more preview)
any new stuff ?
What changed in the .12 patch that made it a requirement?
Is it the PerformanceTracker api?
Engine Internals. Also entities .11 is latest version which will officially support 2019.3 all next packages will require 2020.1+
Fine for us, using it from alpha releases.
Yeah
@stiff skiff I guess this questions to me? 🙂
.. I have no idea why it tagged wrongly, sorry
But yes, if you could
I've been trying to keep up with the entities stuff, but packages releases are not announced, bintray is no longer updated, and there is very little information about the future of the package. Which is making it very hard to work with
It's what guys from DOTS team told me (not only to me) about 2020.1. About .12 - patch also change internals and usually fix something (in this case it fix some issues which allow .11 use 2019.3.12 I guess)
Is there a communication channel with this information that I could join?
Well, I was invited to Unity slack and got access to dots internal repo (but of course I can't and wouldn't speak about something in that repo because of NDA) because of my forum and beta test activity and our project, thus I don't know with whom you should speak about that, because I did not ask anyone. Mostly in that channels are influencers (YouTubers, ambassadors), Unity partners, and different studios.
Hey everyone, I was going to ask how to have a container that I can iterate on in order to remove duplicates but also use it as a Queue (order needs to be preserved) but then I saw this:
- Added RemoveAt and RemoveRange to list containers in collections. These methods remove elements in a list container while preserving the order of the list. These methods are slower than RemoveSwapBack methods and as shuch, you should use RemoveSwapBack if you don't want to preserve the order inside *List container.
It was added today to the Collections package
@storm ravine Thanks for the info. I'll just hope they make their public communication a little better in the future.
Well current communication good IMO. DOTS team very often check forum and answer the questions.
@stiff skiff I guess that question was not for me? 🙂
Haha sorry, it seems @eize auto completes to you
@storm ravine Maybe, I'd still like to have a better way of following package updates then keeping an eye on the discord, of refreshing the package manager 😉
Okay... I've been pulling my hair out... and I'm probably suffering some short sightedness right now.
So i'm trying to make make a grid movement system similar to megaman battle network in dots.
right now though, I've had the movement completely independent from the grid. (but i dont like this approach, since what if there's 1 cell that's missing? I'll simply float over it)
can someone suggest me another approach I can do?
I dont know if this would help @deft stump
a guy made an open source rogue like https://github.com/sarkahn/rltk_unity_roguelike
i have a rather peculiar problem right now. i have 3 jobs in a system. with the 3 jobs it takes a long time 100ms (relatively speaking). with those 3 jobs isolated they need 1ms, 2ms and 12ms for each. I'm not sure how this accumulates to 100ms. the system also runs twice as fast when i use Run instead of Schedule. is dependency breaking or something? here's the code: https://pastebin.com/zdbXbJ7J
@viral sonnet I got nothing but that does sound like your jobs are getting in one another's way. You could try handling the dependencies manually and see if that helps?
Speaking of grid movement, I have a large number of entities in an evenly spaced rectangular grid with known coordinates and another set of entities moving freely within that grid, so that whatever my moving entity's position is, I can calculate which four grid entities are closest to it just from its position relative to origin.
Is there a good way to get exactly those four grid entities out of a native array or something, if I want to be able to loop over my mobile entities in a job, get the closest four grid entities, and update the mobile entity based on those without having to iterate over all the grid entities?
@timber rivet Grid map entities seem to be a very common thing, and there are a few different ways 😛
Like saying each "cell" of the grid bounded by four grid point entities is an entity itself? I was thinking of that, but having trouble figuring out how I get from there to the four entities that make up a cell
My preferred way is using a native collection of some sort, native hash map can be <int3, entity> or even just a native array (you need a fixed world size) and you can take your int3 pos and do some maths (i can never remember this sorry) to turn a x,y,z into a index in the array
and build up that collection 1ce at start, and then perferably never change it
but theres tones of options
each cell entity could have a buffer set at 4, with each index being a direction (0= north, 1 = left ect)
you could have a component actually instead of a buffer
the map to array is to round the position to int coords
Yeah, the math to get from world position to grid coordinates is easy, I already have that figured out
Just need to get from the grid coordinates to the entities
https://docs.unity3d.com/Packages/com.unity.collections@0.0/api/Unity.Collections.NativeHashMap-2.html
So I would define a native hash map with integer coordinates as my TKey and entities as my TValue, and then when I want an entity with given int coordinates, I just get entity = Item[Tkey]?
if you're using int coords you'd want just a NativeArray<Entity> or struct with Entity + whatever else you need.? then you use the int as array index with map 2D or 3D >> 1D indexing. If you're using a hasmap your key could be anything.. but it will be slower than a direct access.
Fair enough, yeah, integer coords can map to just a single integer too. In fact I have a native array of the entities already when I instantiate them, but I'm not sure if it's possible to pass that array to a system that needs it?
you can have a public member and save the system as a field, i mean its not great but its fast.
if you feel purest you can stuff it in a singleton entity as a dynamic buffer
and then retrieve it and reformat back into your array in whatever system needs it
Good point. I wasn't sure if it's possible to have an array of entities as a component value
If I did that, I could just make the entity, then in my job get that one entity and just grab the correct entities from the array in its component
Does it need to be a dynamic buffer even if I know I won't be adding or removing any entities?
there's a few ways, you can use GetSingletonEntity<SomeTagComponent>() and then grab a dynamic buffer from it. or use a component with a pointer in it, or an UnsafeList etc.
the advantage of a dynamic buffer is that Unity will take care of deallocation.
ah
you could just have whatever system that created it, dispose it in OnDisable() or whatever the method name is for systems.
i've found a cleaner way to do it, is to have a system that manages such data, it owns and destroys what its created, and then add an extension to world to make a class wrapper accessor for them. So like. World.GetOrCreateProvider<MyStuff>(); which returns a class storing a ptr or whatever exposing "Value" property for MyStuff. At least that is if you want to be passing custom native objects (databases etc) into burst jobs and share them between systems.
@mint iron that sounds usefull, but you can share native containers already
but i guess thats a nicer API for it
rather then go GetExistingSystem.....().listofstuff??
yeah pretty much; isolates it from the other things you might do with the system and is a little clearer on its intention, forces consistency when you have a lot of them to use the same interface.
sounds useful
@mint iron would you mind sharing any of that? currently my "database" of reference stuff is a ugly scriptable object i inject into systems after loading
sure, i can find it in an hour so when i get off work
i want to clean it up lots but unsure exactly what to do with it
as i have tons of managed refereces to things (strings, unity game object prefabs (used during conversion then never again) references to other bits
That might be a bit overkill for my usecase where I only anticipate having to do this with this one grid, but maybe worth looking into anyway
https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/dynamic_buffers.html
So if I read this right, I would define my buffer value as public Entity gridEntity, rather than as an array of entities, and the InternalBufferCapacity needs to be set to... the number of entities in my grid?
depends on how big your grid is, unity will try to keep the DynamicBuffer within the chunk until it exceeds InternalBufferCapacity, then it moves it to a new heap allocation. If you have a massive grid, you probably wouldn't want that in the chunk, especially if its just a singleton sitting in its own chunk - its not like you're gaining anything there.
It's going to be very big, which is a reason I want to go out of my way to just find the specific entities I'm looking for as much as possible
So if I set it to a number less than the number of entities in the grid, it will just allocate extra memory in different chunks and it won't make much of a difference?
it effects performance
but thats such a tough thing to worry about so early
i think go with what ever gets you going quickly, and when you have more gameplay in watch the profiler for a bit
see if its actually causing issues
Fair
it won't split it between chunks, its either inside or elsewhere in some malloc'd space.
dynamicBuffer just has a ptr in it, it goes either relative space within chunk or somewhere else entirely
The last thing I'm not clear on is how I set the individual buffers to my entities. I assume it's not with SetComponentData, since the buffer isn't a ComponentData. Do I just go like
Entity entity = entityArray[i];
MyBufferElement buffer = entityManager.AddBuffer<MyBufferElement>(bufferEntity);
buffer.gridEntity = entity;
ah
or if you already have the data for some reason you can GetUnsafePtr and memcpy it
how are people handeling prefabs these days?
Currently i have a bunch of addressables, i load them at runtime and then call GameObjectConversionUtility....
but i've learnt that thats not really a good idea, performance wise so im thinking some sort of sub scene prefab setup but have no idea
do i just dump all my prefabs into subscenes and then load those?
i was doing something similar to you, addressables download, instantiate a GO, triggers a conversion, that conversion creates all the referenced entity prefabs. But it turned out to be a nightmare when instantiating parent/child setups that also needed to run conversion scripts, and we were told runtime conversion like that isn't supported.
you can still use IConvertEntityToWhatever script, but it should be used within a SubScene. Better yet is to write a conversion system for your MB type (and use in SubScene).
But the catch is that many people have experienced a lot of bugs with working with SubScenes
yup the one time i tried it i hated it
but also arnt subscenes for spawning things in directly, not prefabs
no, a subscene is compiled into a big blob, so it can be efficiently put into a world, you don't spawn things into subscenes. Its like a container for stuff that needs to be converted and you want to load together. There is livelink but thats a whole nother thing.
drag the prefab into the subscene
but that will spawn it when i load the subscene
if you slap a Prefab component on it, then it disapears and becomes a prefab
hopefully they intend something easier to use than all these hacks lol
hmm
looks like a good start
just need a new way to link my data to a entity
instead of a gameobject
So I've successfully made a buffer entity and added a dynamic buffer of all my grid entities to it and now I've got the buffer in my job like
DynamicBuffer<GridBuffer> buffer = lookup[gridEntity];```If I'm reading the documentation right, now I just get the entities I want with `buffer[index].gridEntity`?
Looks like it
Huh, my biggest optimization in DOTS now is creating different ComponentSystemGroups and updating them manually. Seems dependencies can go very very very wrong. I was hunting a performance problem and an unrelated system had a dependency on many other systems, forcing them to wait for completion and screwing scheduling totally up.
I'm still puzzled how this system ever entered the dependency chain of those other systems
since I've implemented the fast-forward feature it's clear that getting data isn't a trivial task and in most cases takes longer than the actual job itself. data layout, chunk utilization and occurance of structural changes is rarely talked about, but right now, it's more important than the code itself
what i find amusing is 99% of my code runs faster with Run() or Jobs.WithCode, i dont even bother scheduling anymore, wouldn't even consider parallel unless i had a really good reason. The scheduling overhead is just too high.
@ocean tundra i think this is the most recent version (although just noticed a leak there on dispose :() https://github.com/jeffvella/UnityEcsEvents.Example/blob/develop/EventsExample/Assets/Game.Scripts/Providers/ProviderSystem.cs
Same, basically all my simulation code uses run. The overhead is very noticeable when you have to run the same system multiple times a frame, in my case mostly rollback/prediction.
And i try to structure my systems to be very small and have a distinct purpose which is not helping.
yeah, same here .... Run > Schedule. quite a problem when the system is only operating on a few entities. what's funny is that ECS screams when you use an ECB and Run.
Entities 0.11 throws an error in a build. Does anyone else have this problem? MethodAccessException: Method Unity.Jobs.IJobBurstScheduableExtensions+JobStruct21[Unity.Entities.EntityDataAccess+DestroyChunks].Initialize()' is inaccessible from method `__JobReflectionRegistrationOutput__2052323622..cctor()'
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
at __JobReflectionRegistrationOutput__2052323622..cctor () [0x00000] in <029ebe95a77f49b7900bcf94cb43398a>:0
Rethrow as TypeInitializationException: The type initializer for '__JobReflectionRegistrationOutput__2052323622' threw an exception.
don't upgrade to 0.11 yet - still works fine with 0.10
@viral sonnet theres 0.11???
its only really bug fixes
i was hoping the component enableing stuff would be in this one
Hi all, wheres the best place to have all my custom world and system creating (also includeds loading a bunch of data (json) loading subscenes and gameobjects) currenty its in a monobhaviour start method
Also I would prefer it if its bound to a scene but the more I research the more i think i cant
It has lots of internal changes for some sort of struct based Systems
hey I noticed that doing GetEntityQuery(SomeComponent) in OnCreate of one system makes it run Update every frame no matter what. Is that expected behaviour?
(if there is at least one SomeComponent somewhere)
how does calling RequireForUpdate or not calling it is different?
how are you guys handling sounds within your ECS projects?
There's a new way to enable preview packages.
I think it's in project settings iirc. (my laptop is in the middle of a repair)
oh right ok thanks I'll take a look
they hid that on 2020.1 already?
I thought it was 2020.2 change only 🙂
but I admit I haven't used 2020.1 in a while
Yeah I found it in project settings thanks 🙂
I just use the search functionality on project settings for this
How is .2 in alpha when .1 isn't even released haha
I never remember where it is there
the roadmap for .2 is just like "A new UI thing"
just write "preview" on the search and it lists like 2 things
well, my logic is that 2020.1 is going to be unsupported once 2020.2 gets released, so it's existance is totally pointless, I couldn't care less of x.1 now
and 2020.2 will become 2020.3 LTS
I kinda feel that Unity did fail a bit on TECH releases, mainly because the support period is so tiny for anything but last tech release (and this year there's only two)
LTS thing is nice but with current model, it's the only actual "full" release
.2 could get into beta while .1 is still in beta? 😄
I expect 2020.1 to release soon
I don't get it... but the roadmap for .2 had like nothing on it so what's in .2??
for me, faster DX12 and most importantly rock solid deltatimes
right now the DT fix is only for DX11 but next alpha should support DX12 as well
similar what is in visual studio for prevew things
hmm maybe I should skip .1, I'm trying to choose between them but the roadmap was missing all the info haha
I don't even have 2020.1 installed here 😄
as for the roadmap, they mostly cover packages there and I don't think there's specifically that many new package related things for 2020.2
how long is .1 expected to be released before .2 comes out
like, sure, there will be improvements that only work on 2020.2 API, just like there are things for most Unity versions on currently evolving packages, but I can't remember any major thing
I've never seen this kind of alpha/beta overlap before
this years situation is new and it makes it harder to predict
what is the latest unity presentation talk thing with ecs content?
I read they were going to be at GDC but pulled out
like, they now removed one TECH stream, so there's only two TECH streams, which could mean they launch first one later or 2020.1 is just delayed because of covid-19
hmm
I'd expect 2020.2 to be out in fall/winter like 20xx.3 used to be
looking at last year, they really struggled to keep up with the releases on 3 TECH release setup, which I can imagine being partly a reason why they stripped one out
I personally feel they could just have gone with one tech release for whole year
current tech releases are problematic as many now just stick with 2018.2 and 2019.2 and get left out of all support
2018.2 -> 2018.3 update amount was absurd
many just had to skip it because the way prefabs changed
also PhysX 3.4 update brought some changes for physics side
Well I'm downloading it now haha
almost forgot... there's one major change on latest 2020.2 alpha: new splash screen (I dunno if they updated it to latest 2020.1 betas too)
editor splash screen or build splash screen?
I saw a new editor splash screen, but I wouldn't consider that a feature haha
editor
20.1 as a new one too
yep they both have it
I have a completely new project, just importing packages and already having trouble with versions lol. DOTS Editor is complaining when I import it
I figured they'd have a slightly better handle on packages by now 😄
So I'm creating 2 jobs per chunk generation, all 100 chunks are generated at once. thats 200 jobs, and I'm guessing creating that many jobs could become a problem?
I would think it could be
im doing similar, after all my equations and populating all my arrays and loading meshes, I think I can do 2-4 15x15x15 chunks per freame
Some of the jobs are being put on the Main Thread aswell
whjilst keeping like 600 fps or more
I spent a month messing with my code to get it all off that, thjink im nearly there but not yet 😄
Im also very slow and procrastinator master ;
Yeah.. my world generation takes around 26ms, a 200x200 world. 200 * 200 * 64 (2,560,000 pixels)
Its a 2D game
so its able to set 2,560.000 pixels in 26ms. Though before I added chunks it took around 13ms
Burst ParallellFor is insane if you can get it over to that, but it is taking me much longer than hoped for me to get fully into it. Hopefully I get my terrain rendering working finally today after far too long doing the wrong approach 😄
If its a onetime thing with known size, Id probs try to code a loading screen.
Yeah, I use Burst IJobParallelFor for all of my world generation.
creatring 200 jobs is no problem, you would see the bad FPS as they run or whatnot if you have issues. I creating 1000s of jobs 😄
well processing many thousands of entities etc through many systems, not sure if thats the same.
Yeah though a lot of them are being put into the main thread
Ideas if it possible to simply disable a siystem inside its update? World.DestroySystem(this);
ah this.Enabled 😄
I'm reading project tiny's documentation and it says there that project tiny is not using the "classic" unity runtime, which is able to run in hybrid mode, but the "new DOTS runtime" instead. Am I correct to understand from this that I cannot use UI elements in projects that use project tiny?
correct - at least that's my understanding
@graceful mason Hey, with your world generation do you have some sort of chunks system?
yeah
i tried doing it like 10 different ways, finally think i getting to one that works 😄
Did you have the tiles stored within the chunks or outside? I am having a little bit of problems about that
or do you have any at all
no idea 😄 I think as I store my "Terrain" in 15x15x15 chunks, I store it as ints in a buffer, and I preallocate 3375 for this buffer, thats in chunk. Then from that, I make the Verts, Tris and Uvs, which I store in buffers, which have preallocated [0] as I know i store more than the amount you can preallocate in them
Yeah our projects are quite different then. As you have to create a mesh and so on I have to create a texture
when i sdaid chunk then, i meant ECS chunk 😄
but yeah, all my terrain is also stored in chunks, 15x15x15, as a DynamicBuffer<>
Oh right. I meant like splitting the world into chunks (like minecraft) :p
yeah I do thjat
I don't use DOTS so havn't used DynamicBuffer
I see, yeah I use that, had a lot of issues as my Mesh needs to know about the neighbours chunks
but if that wasnt the case, ECS implementation would have been a breeze
same! that's what my current issue is :P
my chunk generation needs to know its neighbors, currently it doesnt
I think I solved that finally, writing my final code now 🙂
for me, as i request way more chunks than i can process at once (aiming for redicuoluos draw distance), I have a queue system, requested= 1024chunks, queued=10 chunks
the only way I have thought of is giving it the 8 surrounding chunks tile array and working with that but it seems kinda tedious.
but anyways after all that, I then make my entities I need to know about and save them in a hashmap. https://pastebin.com/ZMcKSAZt
It grabs a chunk from the queue, when it does this, iut also create the surrouinding chunks jobs
then I have systems to run jobs on all those entities
finally my mesh making system, can check each surrounding entity to see if the job on there is finished by seeing a tag value or similar
by checking each face, and looking in the hasmap
I've never used DOTS so it's quite confusing to me, but it's gonna be a bit simpler than yours since you have to deal with a third dimension :p
Heres those 2 in more pseudo: https://pastebin.com/ZrgWApPu https://pastebin.com/PmRkj4MG
I create all entities in 1 system
then 2nd system, runs on an entity, and looks up the neuighbours
variablenames a bit mixed!
thenb i just lookup the neighbours buffers / comonents diurectly
has anyone used SerializeWorld successfully with Companion Gameobjects?
Hi all, still not sure on loading/initialization code, I'm leaning towards having a Loading world which has a bunch of systems, it can setup all my other worlds, load prefabs,data ect into them
Is anyone doing anything similar?
anyone understand this? https://forum.unity.com/threads/approaches-to-storing-entity-references-created-from-entitycommandbuffer-createentity-instantiate.668788/
just trying to get a reference to an entity created in a bufffer
😛
i didnt read it all
but basicly you have a ecb and your creating a entity then wanting to save that entity?
yeah
into a hasmap
so basicly the entity that the ecb returns only exists with that ecb
yeah
I understamnd that, but i recreate my ecb each frame so no idea how that would work
so what i do is add a new component to my entity
thats as far as i understand 😄
then have another system that looks for that entity and adds it to my list
hope it helps
they should really sort htis out 😄
got about 3 systems that exiust purely to tag data for other systems
and i still working on my 1st system
i also have places where i have 1 existing entity and then spawn another that needs to reference eachother, but as long as i use the same ECB i can add components containing the temp entity and everything gets remapped fine
its a fixed limitation of the system i belive, no way to fix that if you want threading
what would be nice is a way to get the entity remapping data after the ecb has run
yeah
then if you really need to you could manually remap any references you save
Im not sure if your way is better than my idea
my idea is, create a local var and store all my entities structures I want, adding to it inside inside a parallell for.... then just iterate that loop on main thread on entitity manager getting proper references. There just x,y, tag entities so should be light on main thread
na def stay with ECB if you can
your way would create a sync point which reduces performance
for greater speed avoid using entity manager
🙂
ah cool, yeah i never understood how somehthing like that would work
but i guess it makes sense, it would sync poiint there, outside the existing ECB Buffersystems that are define
yea that wont actually work
Hey, I'm trying to run my own PhysicsStep, BuildPhysicsWorld etc systems, but for the entity conversion workflow, I would like to use the existing components (also to make porting changes in the future easier) - so I want the original systems to be inactive.
(end goal is to run multiple physics simulations at the time scale I want to simulate them at)
My idea is to have a trio of systems that (in various jobs) process a number of physics worlds, and a ComponentData (maybe SharedComponentData?) on the Entities contains an index or id, which world the entity is supposed to be Built into in BuildPhysicsWorlds.
so the entities......forach..schedule wont run right then
it just gets scheduled
so then your foreach tries to run
I'm currently beginning to port the existing unity systems, and I am wondering:
- how do I prevent the original physics systems from running? They would still trigger for my entities, which only have an extra component..
but the list will be empty as the entities foreach hasnt run yet
ok good to know. I understand your proposed method, so I can go with that 😄
@warm panther find the existing systems with World.GetExistingSystem<TYPE>() and set Enabled to false
WorldEntityLoadingSystem worldentitysys = World.GetExistingSystem<WorldEntityLoadingSystem>();
they are something like BuildPhysicsWorld
just do somehting like
var x = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildPhysicsWorld>();
x.Enabled = false;
Ok, and where do I do that... in awake of a MBehaviour? In OnCreate of my system(s)?
wait do you not want the conversion to run or the actual systems at runtime?
I want conversion to run, but I want to add an additional componentdata that contains a "world id", i.e. which physics world this entity should belong to.
So I'd keep all of the conversion code, but the old systems still pick up the entities of course, so I just need to disable them... I guess.
I've been considering multiple Worlds (as in ECS worlds), but that's not only more of a hassle, I want to seamlessly move entities between physics worlds. The way Unity Physics currently works, all I need to do is change a few chunk change detection jobs.
And of course schedule a job for each world in the Step and Build systems.
as to where you put it, id assume it would be fine in awake or start but could also be in oncreate in a system.
I'll think about it. Probably oncreate is cleanest, because it's literally a replacement.
var replaced_system = World.GetOrCreateSystem<Unity.Physics.Systems.BuildPhysicsWorld>();
replaced_system.Enabled = false;
kind of like this.
Ok, works.
Unfortunately, all the debug systems also have a hard dependency to BuildPhysicsWorld. Not a deal-breaker, but I had wished I could do without changing these.
take it to the forums, let them know its cramping your style 🙂
hehe
i think the dots physics forums have like the highest amount of dev responses on any unity forum ive seen, its pretty cool
Sweet, wonder if it works properly with custom worlds
To keep world information manageable, we have hidden the other worlds in the world dropdown list. To enable it again, we have added a setting to show all of the available worlds in the project in the Preferences window
yup
i saw that
i was thinking more about custom worlds not showing any systems if your not using the default world update stuff
yea will check it out next time I open my project.. it's a start at least
hmm yea no idea about that - wouldn't be surprised if they didn't appear still
installing preview 7 🙂
its super annoying
argh getting handle on entity from ecb is defo something they shoulda sorted out or at least include in the docs somehow 😄
I have your plan but I fked all my codes trying to implement, gonna take a few hours a bit later to resolve lol
@graceful mason I assume some of your other systems are running on your new entities but as your native list isnt setup they are falling apart?
updated and don't see new systems ui... wtf
i don't see a button to open that new window
“Window > DOTS > System Schedule” ??
i wont be able to try untill later tonight
well i tried to rejig it so my lists should all be setup, but i moved it into the next step of the process 😄
so the processChunk system, could also add it to a list
LoadChunkEntitySystem.JobData.chunkTerrainEntities_ is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type.
Now I get that as im trying to edit my hashmap inside a paralell
so ill write the system properly like you said and it csan run on main thread single threaded
just to register the entities
but as it failed to write to the dictionary it made 100s of errors and looked scary 😄
don't know what i did but is see Systems view now, but... not all my active systems listed there...
working for me
what unitiy version you have?
Hello all. I'm just getting started with DOTS. I've got a bunch of Dynamic entites being created and once they settle, I want to turn off their physics step. Make them static or whatever it takes to make them not move and not slow the system down. So when I have 10,000 objects piled up, only the top thousand or so that are still moving matter. In my ChangeToStaticSystem, what Physics component am I looking for? I was looking for something easy like Physics.Type = PhysicsType.Static but I'm not finding it. - Should I just remove the Physics components?
Probably PhsyicsVelocity being the main one
maybe mass too
oh yea just remove the components
in a upcomming update ive see some things about each component have a Enabled flag, but thats not here yet
Ok thanks. Yeah, I didn't really think about just removing the components until I was typing it all our here. Discord is often my rubber ducky 🙂
yea it works great as that
is storing 100 buffers with l;oads of data on 1 entity any worse/better, than making an entity for each?
@graceful mason that is a super duper hard question to answer
my advice is to get it working whatever way you can and profile
everyones use case is unique
also you should look at native collections too
my understanding is there is still overhead with entities, so if making a minecraft clone 1 entity per block isnt recommened
I'm having issues over here....
This method throws an error about "Must use .Run or .Schedule" after the Entities.ForEach. However .Run and .Schedule are not available with ComponentSystem. Also I know ComponentSystem is going away...
public class ChangeToStaticSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach(
(Entity entity, ref SandPhysics sandPhysics, ref PhysicsCollider physics, ref PhysicsVelocity velocity) =>
{
{
PostUpdateCommands.RemoveComponent(entity, typeof(PhysicsVelocity));
//EntityManager.RemoveComponent(entity, typeof(PhysicsVelocity));
};
});
}
}```
So I try with SystemBase instead, which doesn't have a "PostUpdateCommands" that I see...
```CSharp
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Physics;
using UnityEngine;
public class ChangeToStaticSystem : SystemBase
{
protected override void OnUpdate()
{
Entities.ForEach(
(Entity entity, ref SandPhysics sandPhysics, ref PhysicsCollider physics, ref PhysicsVelocity velocity) =>
{
{
EntityManager.RemoveComponent(entity, typeof(PhysicsVelocity));
};
}).Run();
}
}```
Doing it this way, Unity says I can't access EntityManager static like this, and I need to use .WithoutBurst and Run but I'm not sure how to do this. I'm just trying to remove a component. How should I be doing this? Thanks All if you can help!
So with SystemBase what you want to use is an EntityCommandBuffer. In fact PostUpdateCommands is a command buffer in ComponentSystem
Theres a few extra steps with SystemBase
@ocean tundra con and @coarse turtle thanks. that link answers my question well I think.
I think a big part of my problem is google searches keep returning Unity Docs refs for older versions!
need to make sure I'm always looking at drop 6
If I use dots do I have to completely re-think my workflow or design?
@feral canopy probably 😛
they are working hard on the workflow to keep it close to normal unity
I did.. DOTS for me is crazy different. but I'm slowly getting it.
at least in the editor
Should I wait for stable release then?
depends on what you want to build
Dots will come in stable 2020 release right? Or is it mid?
I think it's unlikely it will be out of preview any time soon
does preview supersede experimental builds?
DOTS core (Entities, Jobs, Burst) may become stable in the 2020.X lifecycle, but i expect 2021
and theres TONS of other bits that arnt done, Animations/Physics/any 2d stuff
alright ill explore dots on a mini game jam project. thanks for the insight!
if you want to build something big then i recommned it, for a 2d project tho.. probably not
man, it's frustrating when a ComponentSystem only needs half the time of the same system written in Systembase
really??
that sucks
someone said something about the latest v11 containing some struct based System stuff
but def not ready yet
yeah, you really have to pick and choose right now based on data and amount
yup
struct based system stuff? not sure what's that about
I'm still very early, so still inplementing features and not worring too much about performance
so ive seen the unity dots team commenting on the performance of SystemBase, they are aware of it and are working on it. From what ive read they want to make SystemBase (or something really close to it) burst compatible
yeah i know and sadly that's the state for a long time now. i waited a long time to rewrite to SystemBase and now it's still a mess. SystemBase, IJobChunk and all that is great when you have thousands of entities to process but with only a few entities, a simple ComponentSystem is still king and for some weird reason it's considered slow when in reality it's not.
its tough
for me i dont need the performance yet, so hoping when i get most of my gameplay stuff in unity will have fixed system bases (as i already have sooooooo many)
like for every networked thing i have i need 7!! systems
and stupid generics dont work
performance issues aside, ECS is pretty great.
yea
loving it
some annoyances
like generices
but i worked around that with code gen
wise thing to do. generics in the C# way don't really work
yea i usually get too crazy with them and it all breaks down
code gen is still annoying but im building up more and more tools for it
will probably be easier in long run
how do you use those?
im using c# tt templates
i then pre process the template in rider (but vs should work)
and then the class it generated i call from a scriptable object, which makes another class
😛
the scriptable object is acting as a link to unity, so i can pass unity objects, and use the inspector
cool, sounds pretty complex.
the base setup was actually really easy
the annoying bit is when building you want to exclude all the tt and pre processed template files from the build
and the scriptable objects too
so needed to get tricky with asmdefs
which my project is awefully setup for
i really need to restructure it
@viral sonnet where do you have your setup/start logic?
for ECS or in general?
yea for ecs
i've switched to a ICustomBootstrap recently.
no, you create the worlds there, systems and groups
i can only recommend it except you'll never want to update systems manually
the most complex ICustomBootstrap is in the dots netcode
yea i already have very complex startup logic
but its all in a monobehaviour start
ive disabled the default world
and create my own
and do a TON of stuff
i should take a look at the net code one
in a built game when does it run?
before scene loading
so before even a main menu?
yep, pretty much the first thing that can happen ^^
ICustomBootstrap Initialize does that
why not?
is DOTS worth converting my entire project to?
oh i see
so ideally my core startup not in a monobehaviour
you can create an entity with some init comp
actually,.. i think i could leave the start of it in a monobehavior which can call a static method to start the server stuff, as client will always need monobehaviours
and in a dedicated server have some sort of ICustomBootstrap which only exsits there
@feral meteor probably not, unless your project really needs it and even then just add it for some small bits
or your crazy like the rest of us
so ideally my core startup not in a monobehaviour
There is a way... Lemme look at my repo...
@viral sonnet yea that init entity start is something im going to convert too
i still need something outside the worlds, to create them and do a few things
but then i want as much of my loading code eaither in my main worlds or in a loading world
any of you can build and play with newest entities 0.11? i'm getting core errors
usually i migrate after the first week a new version releases
it's just, sometimes i hope unity does actual testing
hahaha
is dots physics deterministic?
Is there a FixedUpdate() equivalent in Dots?
@gusty comet i haven't tested but i think they said it should be deterministic on same cpu architecture atm
different cpu architecture determinism depends on a future burst update
@deft stump by default simulationgroup and co runs on update but you can make your own systemgroup and check for update interval, or use FixedRateUtils to do it for you, or don't autoupdate world and update it yourself in fixedupdate
Still very new to this. Appreciate all the help. My System isn't working quite right, and an error says I need to call JobHandle.Complete(). How do I get a jobHandle from my Entities.ForEach? ```CSharp
public class ChangeToStaticSystem : SystemBase
{
EndSimulationEntityCommandBufferSystem m_EndSimulationEcbSystem;
protected override void OnCreate()
{
base.OnCreate();
m_EndSimulationEcbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
var ecb = m_EndSimulationEcbSystem.CreateCommandBuffer().ToConcurrent();
Entities.ForEach(
(Entity entity, int entityInQueryIndex, ref SandPhysics sandPhysics, ref PhysicsCollider physics, ref PhysicsVelocity velocity) =>
{
{
ecb.RemoveComponent(entityInQueryIndex, entity, typeof(PhysicsVelocity));
Debug.Log("Removed");
};
}).Schedule();
}
}
@safe mica reread that entity command buffer doc
theres a line at the end your missing, something like addproducer(Dependancy)
cant remember it exactly now
@hollow sorrel so i have to make one myself. Gotcha
Ahh I see it now. Thanks again Roycon
ye and it's weird because they've been saying simulation will be changed to run at fixedupdate by default since like a year ago
not sure why they haven't yet
lots of ppl complain about physics not running at fixed rate
by default
ohyea which reminds me making it run at fixed rate is required for determinism too @gusty comet
I made one step forward (thanks again Roycon) but now ran into another snag. I'm trying to update a RenderMesh.material.color inside a system. It's complaining at me that I can't do that... I assume this might be because all my entities share the same material? Is there an easy way to change the color/material of entities in a ForEach?
you have to use MaterialColor component for that
ahh ok. Thanks
and make sure GPU instancing enabled for that maretial
you need the hybrid renderer for that yes?
yes
V1 or V2?
both
but you need latest preview version of it
My last question for the night! - Burst error BC1025: Accessing the type `Unity.Physics.PhysicsVelocity` (e.g. using `typeof`) is not supported
...
ecb.RemoveComponent(entityInQueryIndex, entity, typeof(PhysicsVelocity));
Is there a way to make this work with Burst? Or what do I change to make this section not use Burst and get rid of the error?
awesome.
i believe they are also faster then the type variants
tho not sure if thats still true in DOTS
NetCode : when using Camera that follows spaceship i put it(system that controls camera) in GhostPredictionSystemGroup and also make it update after system that controls player ship update method executes - is this good practice and is there better way to do this and what that way should be? (for Camera i simply set up position and rotation from camera system(ComponentSystem update method) using Camera.main.transform.[position|rotation])
Anyone know if we can put a subscene inside addresables?
This PR from Jussi, he's from Unity (HybridRenderer team)
Is the "Chunk" in "IJobChunk" the same "Chunk" as in "ArchetypeChunk"?
If you know what I mean..?
Rizu just wanted to share it here in case someone interested in this fix i guess
Is the "Chunk" in "IJobChunk" the same "Chunk" as in "ArchetypeChunk"?
@warm panther IJobChunk has only ArchetypeChunk (And whole ECS data layout use ArchetypeChunks), idk which chunk you mean apart of ArchetypeChunk in this context
If your question is - "It's a chunk from core ECS data layout, where all data stores?", the answer is "Yes"
Ok, so it's not another use of the Word.
So basically each IJobChunk works on one Chunk?
Which each?
Each Execute
Or each instance
Rephrase your question better 🙂 I can't understand what you want to ask 🙂
The thing is, I don't understand how IJobChunk knows which entities it works on.
You pass EntityQuery as argument to IJobChunk schedule
And that entity query tell IJobChunk which chunks should be processed
What happens when I do this:
job1.Schedule(eq);
eq.SetSharedComponentFilter(...);
job2.Schedule(eq);
And if you schedule 2 IJobChunk on same EQ (and use ACCT with write access or one read other write) and not chain them in dependency you'll get error about memory alliasing
Well I need to schedule them on the same EQ but for a different sharedcomponentdata
("want" is better than need, I am trying to figure out a good architecture here)
I could just create an array of entity queries.
Ideally I would rather just do something like this (pseudocode):
foreach(sharedcomponentdataindex) schedule a job that works on my_datastructure[sharedcomponentdataindex.value]
(I have a sharedcomponentdata that contains a "world" id, and I want to simulate multiple physics worlds that all exist in the same ECS world, allowing entities to seamlessly move between the physics worlds by changing their sharedcomponentdata, instead of copying them to a different ECS world)
These changes happen occasionally only, but they do happen, and I don't want to build up, maintain, and tear down a new ECS world for every new physics world I create.
So I'm porting UnityPhysics's BuildPhysicsWorld, StepPhysicsWorld, ExportPhysicsWorld to operate on a $array_like_datastructure of PhysicsWorlds, instead of one.
Hmm I guess I will need to create a $array_like_datastructure of EntityQueries as well then, pity.
Probably the best approach is to fully encapsulate these systems into a facade that manages multiples of them. I just need to find a way how to have the jobs operate on the right entities. Ideally, I'd like to do this without "SetSharedComponentFilter", but as far as I understand only that has a limited overhead.
For me it's messy. Multiple worlds exist exact for this purpose of separation. You not "copy" to another world, you should "move" to another world, and cost of that moving the same as setting SCD, because it just change data location in chunks layout (memcpy to another archetype).
Yeah.
But creating the separate systems is much more work.
The only advantage is that I don't have to keep my own fork of UnityPhysics.
But I need to keep like a dozen systems running in each world, selectively.
maybe I don't understand ECS worlds at all then.
(not just that, I need to manually chain the systems so they run in the right order in the new world)
(and I haven't been able to find a way to copy an entity from one world to another, or maintain a representation in both, etc)
They'll run in same order in all worlds and if you set order by attributes it will work in every world
Hmm.
Where can I read up on this?
And how do I, for instance, enable or disable PresentationSystemgroup in one world specifically?
"They'll run in same order in all worlds and if you set order by attributes it will work in every world"
But you said the systems run in all worlds
You simulate in different worlds and presentation world just show every thing
But you said the systems run in all worlds
@warm panther read again what you quoted.
Same order not mean World will have all systems
If your worlds only have your simulation
this simulation will be in same order
Hmm. So presentation world would require me, when I enter a different simulation semantically and want to present that, to clear every entity in the presentation world, and copy over the ones I want to show?
I was going for the multiple physicsWorlds approach also because I want to (probably) in the future use the ClientWorld and ServerWorld stuff that Netcode does.
If I have a dozen ClientWorlds and ServerWorlds, I think that adds a lot of complexity.
Not to mention "entities" (I mean systems) communicating across simulation worlds.
hmm I could run one big simulation world, but physicsworlds need to feed back into it.
Hmm. So presentation world would require me, when I enter a different simulation semantically and want to present that, to clear every entity in the presentation world, and copy over the ones I want to show?
@warm panther CopyAndReplaceEntitiesFrom.
That sounds brutal. I literally need to move one entity between chunks usually.
which is why I was thinking sharedcomponentdata 🙂
"EntityManager.CopyAndReplaceEntitiesFrom has been added it can be used to store & restore a backup of the world for the purposes of general purpose simulation rollback."
Doesn't sound like that's what I want.
(unless I use that to make worlds go "live", but you haven't explained how I can make PresentationSystems only work in one world, and what happens to all my entities that don't belong to my simulated world)
Gameplay scenario: Floating Origin Space Game. Ship1 in PhysicsWorld1 sets a waypoint to Station2 in PhysicsWorld2, to get there, it needs to leave PW1, spend some time in an intermediate "travel" world, and then enter PW2.
You can have only one presentation world currently that's all 🙂 You have default world which responsible for presentation. And as many simulations as you want. This is what Unity physics does - they have separate simulation world and just synch states.
"CopyAndReplaceEntitiesFrom" seems to replace all entities, but I would want to keep a lot of entities in my Default World which are unrelated to the Simulation Worlds.
You can copy them without replace
It was example of update whole presentation world from simulation
Where I could literally be memcpying ONE entity and invalidate just two chunks worth of entities.
PhysicsWorld is not a World like DefaultWorld.
public struct PhysicsWorld : ICollidable, IDisposable
doesn't inherit from World
It's really just a crutch for the ISimulation
It's not matter World it or not, I describes approach. You can write your own world implementation. Point is behaviour.
What they do is working on slices of types.
You also can go that route
But result is the same - you move\copy data between worlds (no matter which worlds is)
Well for that I first need to understand how to create my own world.
And see what the repercussions are.
EntityManager MoveEntitiesFrom just dumps out a world. I have no idea how, once they are in the DefaultWorld, they would go back.
Also, that would mean that in that other world, the entire PhysicsWorld would have all of its chunks changed.
That's pretty terrible.
It could work with just 2 changed chunks.
(I mean I dont have a lot of static colliders, though, and my physics worlds are spatially rather sparse, but there are usually thousands of entities in them, with hundreds of colliders)
Moreover you have all remapping information
Ok saves me porting work, now I need to understand how to create and tear down my own worlds procedurally, and how to place entities there in the conversion workflow
I think I am just googling the wrong stuff
"unity create ecs world" gives me forum posts from 2018
Nothing changed long time it that area, most posts from 2018 still relevant (exclude renaming Active to DefaultGameObjectInjectionWorld).
In our case we using multiple worlds for EET and batch entities creating on worker thread. And process of creating and populating still the same. (exclude some simplifications in groups populating area)
The multiple worlds thing you linked doesn't show how to instantiate a new world, typical of the current state of the documentation.
this might do the trick
but man is it clunky
Ah that youtube kids.... Read source code and docs.
{
public bool Initialize(string defaultWorldName)
{
Debug.Log("Executing bootstrap");
var world = new World("Custom world");
World.DefaultGameObjectInjectionWorld = world;
var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
return true;
}
}```
I mean the post that I linked there.
Not the video in the OP
🙂
So how do the presentation systems know they need to run in the presentation world, but not in the others?
"GetAllSystems" strikes me as, you know, All systems.
Creating world itself - just 1 row var world = new World("Custom world"); populating a bit harder because you should create systems from new world but put them to defauld world update list 🙂 If you want them update automatically and appear in entity debugger. But if you update them manually, well just create them in world
"GetAllSystems" strikes me as, you know, All systems.
@warm panther again you looking not to what you should look. It's code sample of your own "Default" worlds
but that's exactly what I mean with "it's quite a bit of work to set up a new world and its systems"
Just adapt it for not default world
(and by work I mean, memory allocations etc.)
I can cache a few pre-created worlds but... it feels off.
Which allocations?
You create wolds once
That's all
Of course world require some stuff for working, but cost - negligible
like these.
in BuildPhysicsWorld system
I do not create worlds once.
I create them whenever I need a new physics bubble to be created.
That's the whole point of this exercise 😄
And I realized that I actually have a design requirement that says that two separate physics worlds need to coexist in the same presentation world. (I can maybe work around that, but my port of the physics system would do that seamlessly, at zero added cost)
oh no, wait....
It's already in same presentation and just different simulation, if you use that worlds just for simulation and default world for presentation 
how do I link the entities across worlds?
without copying over a few thousand entities every frame.
It copy at chunk level
DOES matter
So I actually memcpy all my entities into the presentation world every time.
that sounds insane
how do I keep the presentation world from simulating my stuff?
the physics system by default is in the default world
and thats where I copy it from
(also, I wonder if that copy your code snippet shows actually creates a new instance of the system, or uses the same system and all its state across worlds - because the physics systems actually contain state)
System itself - unique per world it's whole point of worlds.
k
In ecs is it good idea to control camera from system class simply by assigning Camera.main.transform position&rotation without converting it(camera) to an entity(if that is currently possible)?
@full epoch well, caching Camera.main and using that camera for move\rotate in system that's fine. Yes you can convert camera to entity.
hi, where can i find systembase examples ?
i mean real code , not just simple examples
Is anyone has an idea on how to nest an Entities.ForEach into a static function in an Utilities static class to avoid code duplication ?
Since I change ComponentSystem to SystemBase, I cannot pass the Entities to my function anymore.
I used to do it like this
public static Entity GetSelectedItem(EntityQueryBuilder entities, Entity playerEntity)
{
Entity selectedItemEntity = Entity.Null;
entities.WithAll<SelectedItemComponent>().ForEach((Entity inventoryElementEntity, ref InventorySlotComponent inventorySlotComponent) =>
{
if (inventorySlotComponent._owner == playerEntity)
{
selectedItemEntity = inventorySlotComponent._slotContentEntity;
}
});
return selectedItemEntity;
}
@sudden comet you can create a wrapper system and put any Jobs.WithCode or Entities.ForEach in it. You can have it disabled on create but the code inside will be compiled and then you can just expose methods to call them.
omg 😡
i've been rewriting my old huge generic job system from deprecated IJobForEach to IJobChunk
and found a strange bug that sometimes some parts of my code do not invoked as frequently as i expected, and it is took me 5hours to realize that i have return inside for loop where continue should be...
@sudden comet you can create a wrapper system and put any Jobs.WithCode or Entities.ForEach in it. You can have it disabled on create but the code inside will be compiled and then you can just expose methods to call them.
@mint iron it seems less elegant and feel it like a workaround, do you think it is the only way ?
the Entities type is internal to the entities assembly in SystemBase iirc 🤔
You could try an assembly definition reference to Unity.Entities and try to create some public facing API
then you can try and pass that public facing API to your static function
@sudden comet a better way would be to use burst functions or wrap IJob/IJobChunk for static methods, but im not aware of a good any way to manually create the magic code compilation that takes place by SystemBase for Entities.ForEach
Sure that looks like magic 🙂
Thanks for you suggestions
I created a thread on the forum, it is easier for the follow up : https://forum.unity.com/threads/how-to-nest-entities-foreach-in-a-static-function.899339/
I'm so happy that my Dots tweener works again
and i can animate any property of any component on any entity like this:
e.Tween<PosY>().FromTo( 0f, 1f ).Duration( 5000 ).Delay( 500 ).EaseInOut( 0.5f ).Loop().Start();
this might give you some ideas: https://github.com/jeffvella/UnityBurstFunctions it was a project to wrap jobs back before IJobForEach was introduced.
@dry dune out of curiosity, i' m currently trying to disambiguate e.g. .Tween1().Tween2().Loop() (i.e. Tween2 loops) and (.Tween1().Tween2()).Loop() (i.e. the sequence of Tween1 & 2 loop) with my tween lib - have you encountered this?
still nothing for crossplatform determinism
wonder if Unity wishes people forget about it if they don't mention it anymore anywhere
how can i get an scenesection from a scene ?
i mean i have to guess which entities have been created by certain subscene
an the way to get that is using scenesection
i suppose
@amber flicker i'm doing it this way:
e.Tween<PosY>().FromTo( 0f, 1f ).Duration( 500 ).EaseIn(),
e.Tween<PosX>().By( 1f ).Duration( 200 ).EaseOut()
).Loop().Start();
also have a Parallel tween runner
and can combine them in any way
like: Sequence(Parallel(tween,tween), tween, Parallel(tween, tween))
behind chain interface it creates an entity for each tween, and sequential/parallel sets sets are dynamic buffers, and a bunch of generic systems processes them, and after finishing animation all that can be destroyed
I ended up with chain interface for two reasons:
- this is almost similar to what DoTween does
- to construct all those entities by hands is a huge amount of boilerplate
is it possible to limit the amount of entitites inside a ForEach?
without manually queing them etc
@graceful mason What's your use case? Why would you limit the amount?
still nothing for crossplatform determinism
@dull copper
they post about it on the forums from time to time so they're still working on it
but also they mentioned same cpu architecture already is deterministic across different OS, so 64bit linux to 64bit windows but not to 32bit
not sure how to interpret it though, does this mean ps4 and pc are already crossplatform deterministic?
also across different CPU
Burst does generate deterministic code for x86 between different AMD / INTEL machines.
. Unity.Physics is floating point deterministic on the same CPU architecture including between INTEL/AMD. Cross architecture float determinism is not yet supported.
afaik ps4 uses an amd cpu so would imagine it's crossplatform deterministic? but not sure
I'm presuming math.length is the same as Vector3.magnitude, right?
yes
cool, thanks 👍
Hi all, I've been looking into subscenes to replace my runtime prefab conversion stuff but due to reasons i would like to convert the same gameobject in the subscene more then once. Anyone know if this is possiable?
@hollow sorrel same platform means same compiler afaik
in this case anyway
meaning same windows binary should be deterministic across all hardware that can run that same exe
doing ps4, xbox etc require different build so they can't give you cross platform determinism
also, there are things on DOTS that are not deterministic
some of the collections are, some are not if I remember right
I suggested Unity to actually give user a warning if determinism mode for floats is being used and user tries to do something that is known to not be determnistic
Joe at least agreed to it on the forums so we'll see
IMO it's crucial for users to know if they happen to use something that's not determnistic when they think everything is when using DOTS and the determinism parameter
ah really? linux doesn't run same exe as windows tho and requires new build, but i think was said to be deterministic already (if same architecture)
and ps4 is x64 SSE4 and windows x64 SSE2/4, dunno if the SSE part matters
and yea i agree something like that is crucial, esp since it's pretty hard to test if your game is fully deterministic
Apart from (https://gametorrahod.com/game-object-conversion-and-subscene/) is there any writeups on subscenes?
@bright sentinel just struggling to maintain FPS whilst processing really uninportant jobs :D. New plan is a simple system... it does X jobs at a time as background threads
before i was just trying to process them as Entity.ForEach which i guess is locked to frames
@ocean tundra sounds like a prefab
I've got to stop using the Unity alpha versions they are really buggy and barely work at all 
sorry ignore my sub scene questions. i dont think ill use them.
My new question is around world serialzation.
If i have a hybrid prefab entity (Entity that has companion monobehaviours, unity engine components) and i serialize the world out, and reload it do those hybrid entities keep/recreate the gameobject/monobehaviour bits?
@dry dune yea all of this is for optimizing my prefab loading/conversion stuff
I just went into debug mode and I'm getting tons of errors saying it can't find any of the installed packages 
I try again and get a completely different error entities.dll failed 
@hollow sorrel I've seen these mentions but they are not very specific, I wouldn't draw that kind of conclusion myself from it
like, if it were 100% deterministic cross-platform on x64 cpus, it would cover most of the targets already except mobile
@ocean tundra i sort of asked this on the forums, its already slipped to page 2 though and no response, https://forum.unity.com/threads/serializeutilityhybrid-serialize-and-companiongameobjects.898775/
at the same time, Burst team messages this:
basically.. it's not even worked at
there's nothing new there
@safe lintel Bumbed it 🙂
it's been on backburner for a long time now, feels like it's super low prio to Unity or they just don't want to address it yet
"maybe later this year" means definitely not this year
they had earlier targets like in few months
kinda wonder how much covid and wfh has hampered development
@safe lintel From reading the docs it looks like we might be able to just serialize the list of gameobjects and just recreate them again
it will be a pain
from what I've read on the forums, at least it's harder for them to test hardware specific things
I don't think the remote working itself will be a big issue
but like, people not having access to all test hw at homes is an issue
well in an ideal sense no, but if you got young(or old :D) kids etc at home, probably a less ideal work env than the office
@ocean tundra given how painless it is to serialize pure entities, im hoping unity have some tricks in store(probably wishful thinking though but who knows)
agreed
If I have a SystemBase with Run() it seems I can't use ECB. Anyone know how to circumvent this?
I've used ECB with Run before
WithStructuralChanges() disables burst too so I don't think this is an option
show some code
if I change to run this is the error: InvalidOperationException: System.InvalidOperationException: EntityCommandBuffer.Concurrent must only be used in a Job
if your using run you dont need Concurrent
right! 😄 thanks
@safe lintel I use odin lots and took a peek at some of their serializer stuff (which is free and open source) and i think you could use their serializer without too much work
https://odininspector.com/documentation/sirenix.serialization.unityserializationutility
but im away from my pc so cant confirm
ill have to look into that
im probably weeks away from wewriting my loading stuff so i wont be able to confirm
but ive asked the Odin devs if that code will work at runtime
will let you know
how do i get systems to show in entitydebugger for a custom world?
i think i saw the answer before but forgot
yup
yes finally 🙂
i think i could probably use the features they talked about already to move my server world back into the default update code
@ocean tundra was able to update after all, new systems window is still empty unfortunately
did you select show all worlds?
there's no show all worlds in new systems window but yea i tried that in old one
and show inactive systems
actually its hidden in the preferences window
oh huh
there's a checkbox there but no idea what it does
seems it only adds a grayed out "LIVE WORLDS" to the list
theres a setting in the editor preferences to show more
yea that's the one i'm talking about
ah
how do i get systems to show in entitydebugger for a custom world?
@hollow sorrel systems from custom world should be in default world player loop inside root groups if you want them in EntityDebugger. Behaviour of Systems window still the same as in EntityDebugger.
i do have simulationsystemgroup but i just added it to the world directly, is there something else i need to do?
oh i don't have an Update group if that matters
var simulationGroup = World.DefaultGameObjectInjectionWorld.GetExistingSystem<SimulationSystemGroup>();
simulationGroup.AddSystemToUpdateList(newWorld.CreateSystem<TEST_SYSTEM>());
simulationGroup.SortSystems();```
right now i have this
World simWorld = new World("Simulation World");
var simGroup = new SimulationSystemGroup();
simWorld.AddSystem(simGroup);
var testSystem = new PoopSystem();
simWorld.AddSystem(testSystem);
simGroup.AddSystemToUpdateList(testSystem);
is it because i don't use defaultworld?
is there a way i can get by that without using the whole defaultworld initialization stuff
oh wait
seems if i add ScriptBehaviourUpdateOrder.UpdatePlayerLoop(simWorld); it does show up
so i guess the defining part is letting unity update it
but would really like to update it manually
seems if i add
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(simWorld);it does show up
@hollow sorrel It shouldn't change anything
that seems to be the only thing that changes it
doing world.update in a monobehaviour's update() - doesn't show
adding it to unity's updateplayerloop - does show
Are you sure it's in simulation world? Because It's not how it works. And ScriptBehaviourUpdateOrder.UpdatePlayerLoop(simWorld); wouldn't change it:
Your code ```World simWorld = new World("Simulation World");
var simGroup = new SimulationSystemGroup();
simWorld.AddSystem(simGroup);
var testSystem = new TEST_SYSTEM();
simWorld.AddSystem(testSystem);
simGroup.AddSystemToUpdateList(testSystem);
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(simWorld);```
Show same screens with Show Full Player Loop
wops i didn't select simulation world on the 2nd screen but it shows empty too
aight one sec
with updateplayerloop
without
seems it doesn't get added into the playerloop at all when updating in a monobehaviour
i think in your example when you're doing var simulationGroup = World.DefaultGameObjectInjectionWorld.GetExistingSystem<SimulationSystemGroup>(); you're grabbing your existing world's simulationsystemgroup that's already being updated by unity, right?
You using UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP and this is only place of your worlds initialisation?
Because I see root level groups which you not adding manually from your code
yeah
And I feel like your Simulation World initialized with default world (if look at groups)
going into ScriptBehaviourUpdateOrder.UpdatePlayerLoop, seems it's adding those rootlevel groups there
It does because Sim world in your case created with default world systems and player loop, and with enabled define it shouldn't happen at all.
Ah stop
No without default world groups, a bit sleeping.
what do you mean?
I just checked that nothing changed in behaviour. Well, because you haven't default world your sim world will use default layer loop - PlayerLoop.GetDefaultPlayerLoop(), but if you create second world and will try to call UpdatePlayerLoop it will override player loop with systems from new created World and all previous world systems will disappear, and wouldn't update
You still need to have one common world with one player loop which will be used by every other world systems update (and appearing in debuggers).
hm, I had a lot of EntityManager.HasComponent and now I lookup through a Dictionary<Entity, ISkill[]>() which is so much faster for some reason
@hollow sorrel It will update manually (by calling Update on world or group or system), but wouldn't update automatically by engine, and wouldn't appear in debuggers
it's a pretty huge fail to expect to use the PlayerLoop in all those debug tools
and no way to register
still interesed 🙂
We just haven't convenient API
i found out about UpdateCallback which could solve my problem of having to call a systemgroup multiple times but I haven't got it working yet. with that i could register my world in the playerloop and be done
i'm poking around in entitydebugger and seems it's always tied to PlayerLoop to get what systems to show
why does unity expect us to even run the game? i don't get that. imagine we can already browse our systems from the editor.
and god damnit I need to stop. performance is like a drug ... 2 days ago 1 minute was simulated in 1 sec, yesterday I had it at 500ms, now I'm at 320ms
@viral sonnet Whats your project? as that sounds awesome
also i think the old optimize last rules probably still apply 😛
Same here, My world generation code used to take around 800ms (without more than one noise maps or any chunks) but now with all those new things it does it all in 40ms
wow
there are many more things that I didn't have back then too. Such as tilsets wasn't a thing.
hm, when it started I had to explain it but it's similar to clicker heroes 2. basically an incremental rpg game
and back then each tile was 8x8, now they are 16x16.
@viral sonnet sweet, so you can simulate the game super fast for the player?
as time went on it got more crazy, for the longest time performance was holding me back so I never could really make what I wanted. until ecs dropped and I went back to the idea
200x200 world. Sets 10,240,000 pixels in 40ms https://gyazo.com/fd2eb72a9ad906a38cc78b6c99d6e9e2
@ocean tundra exactly, I need it for offline progression. so when the player starts the game 8 hours later, those hours are simulated as fast as possible
noice
@odd cipher pretty cool stuff
it used to have a limit of 8,388,608 pixels but since I added the chunking system it can pretty much handle infinite. Though the computer does not like that
i'm only thinking about fast-forwarding the simulation, because previously, (several years now) I wasn't even hitting 60 fps
the main bottleneck is the amount of chunks
@odd cipher a chunk is 16 * 16? with a dynamic buffer?
I actually don't use Entities
sweet
in that gif they were 25x25
50x50 brings it down to 30ms
I'm really happy with how it works currently though the Chunk part could definitely be done better.
is there a way to have subscenes in a build without initially adding them to a scene? i'd like to load them in at a later point but right now i have to add them all to the scene before hand and delete them on start, which causes a huge lag spike
GetArchetypeChunkComponentType is faster than GetComponentDataFromEntity, right?
@craggy orbit i don't think you can have them outside of a scene, but you can def load them in at a later point
just disable the auto load scene checkbox on your subscene
no need to delete anything
ah good idea! totally forgot about that. thanks!
something weird is going on. I've rewritten my IJobChunk to SystemBase and while the chunk method takes 0.033ms the systembase takes nearly 1ms.
okay, i'm just a dummy and have forgotten to add my excludes/WithNone ... lol
works perfectly, @hollow sorrel ! thanks again for that reminder
what are people doing about UI type content like Strings (Name, description) icons (sprites)?
I was thinking of turning my data into a blob asset, most of it ends up in components in some way (eg health) but having the original data available could be useful
Some more context, this is for a RTS and I have all my "prefab" data in editable JSON files for my Unit/Buildings
Its all things like, max health, resource costs, production lists, attack damage, name, description, icon's
oh and what happens to blob assets and world serialization?
for blob assets and serialization = https://docs.unity3d.com/Packages/com.unity.entities@0.11/api/Unity.Entities.BlobAssetSerializeExtensions.html
Hello, does anyone know why this system seems buggy as hell ?
Here is the behaviour
i dont think you can nest ForEach's
also you can check the generated code which may help
DOTS > DOTS Compiler > Open Inspector
Also your ForEach's have no components or any WithAll's so i think that it will run on ALL entitoes
I remove most of the code to isolate the behaviour, but it happen also with filters..
Now, when you strip most of the lines of code, the "bug" does not happen anymore
thanks for you answer, I will look at the generated code.
This system in a new project trigger the "bug"
I filled a bug to unity if there could be a "bug" .. but I’ll have to find a workaround.
It seems weird that you cannot nest ForEach .. you never need it ?
i never seem too
Anyway I’m glad to know where is the generated code, big thanks to you
if your trying to access data from other entities there GetComponentDataFromEntity
or something like that
i use that when 1 entity references another and you need to access the other
I would just query speaker entity and playerentity and store them in a native container. so that during foreach I can get to the data of the queried entities.
thank you .. btw the generated code is not easy 😛
Oh I didnt read that Roycon already answered that. But yeah pretty much the same what @ocean tundra suggested
oh and what happens to blob assets and world serialization?
@ocean tundra If you serialize world it will serialize blob store with world, and restore on deserialization, but they haven't any merging, thus if you have in current world same blobs (for example built at prefabs conversion after loading through addressables) and deserialize something to your streaming world (loading game) blob store will have blobs duplication (different pointers - same content).
@storm ravine Awesome thats good to know 🙂
@humble falcon @ocean tundra It is not related to nested ForEach :-(, I did reproduce the bug commenting out the outer most ForEach 😕
@sudden comet well with just the code you showed me, I cant tell you much, why it isnt working. Specify what you want to achieve and maybe I can help you with that 😅
Achieving is not really the point here .. but understanding why it isn’t working is..
What is the system trying to do though? From what i see you're just gettinf entities and assigning them
maybe explain the bug in more detail. all i did was skim the code
I didnt understand the bug
This is his bug I guess
As he's not changing it between and it should be the same in both Debug.Log
@sudden comet this is what you meant?
yeah 🙂
Ah the has interacted bool between the first and second should be true
If I comment this line .. it works
I test it in an empty project with only this file 🙂
Just a quick test. Can you remove the braces?
Yes it will
if you remove the brace it start to work
Because it will create different local scope, this is why compiler not complains about duplicate Entity interactedSpeakerEntity declaration
if I rename it .. it continues to crash
What you rename?
not crash but "bug"
the second interactedSpeakerEntity into ointeractedSpeakerEntity
it seems to work when I put interactedSpeakerEntity out of the braces and reuse it. But it does not feel right, don’t you think ?
yes sure .. but I use to have some "if" around those first braces
They create different scope
@storm ravine sure but it is not suppose to alter the value of the boolean value
do sometime peoples from unity read this channel ?
Did anybody manage to render entities with hybrid renderer in edit mode yet?
Problem with bool here I guess can be in codegen (because of nested ForEach), as bool declared at upper scope and shouldn't be affected like this in inner scope (it should change upper scope, but feels like it become local scope instance). I recommend you fill bug report through Unity -> Help -> Report Bug
hiii , how can i iterate a nativearray parallel ?
It somehow related to local variables capturing from first inner ForEach lambda, as it capture them by codegen which allow you change outer value type variables inside ForEach labdas, and in this case it messing that capturing...
I told DOTS team about that, lets wait what they answer, good catch btw @sudden comet
hiii , how can i iterate a nativearray parallel ?
@undone torrent Run IJobFor with ScheduleParallel
okay thx u man 🙂
@sudden comet nested ForEach currently not supported and usually it throw error like this (look at screenshot). But they have different bug, that this check only throw error if your top ForEach capture some local variable outside. For example if you add in OnUpdate some bool test = false and will use that test in your upper ForEach you'll see error about nested ForEach
Does nobody have any experience with ECS in edit mode?
Can I somehow invoke a delegate in a job?
@frail seal FunctionPointers
@storm ravine Ooh, thanks. Does it also work without Burst-compile?
Function Pointers itself always burst compiled, but they not require to be called from bursted job
@sudden comet nested ForEach currently not supported and usually it throw error like this (look at screenshot). But they have different bug, that this check only throw error if your top
ForEachcapture some local variable outside. For example if you add inOnUpdatesomebool test = falseand will use thattestin your upperForEachyou'll see error about nestedForEach
@storm ravine In the last test I made, they are no Nested ForEach anymore
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
public class BuggySystem : SystemBase
{
protected override void OnUpdate()
{
int2 playerInteractionCell = new int2();
bool hasInteracted = false;
Debug.Log($"BEFORE <color=red>FIRST</color> INTERNAL FOREACH : {nameof(hasInteracted)}={hasInteracted}_");
{
Entity interactedSpeakerEntity = Entity.Null;
Entities.ForEach((Entity speakerEntity) =>
{
if (playerInteractionCell.Equals(int2.zero))
{
interactedSpeakerEntity = speakerEntity;
}
}).WithoutBurst().Run();
hasInteracted = true;
Debug.Log($"AFTER <color=red>FIRST</color> INTERNAL ASSIGN : {nameof(hasInteracted)}={hasInteracted}_");
}
Debug.Log($"BEFORE <color=red>SECOND</color> INTERNAL FOREACH : {nameof(hasInteracted)}={hasInteracted}_");
if (!hasInteracted)
{
Entity interactedSpeakerEntity = Entity.Null;
Entities.ForEach((Entity entity) =>
{
{
interactedSpeakerEntity = entity;
hasInteracted = true;
}
}).WithoutBurst().Run();
Debug.Log($"AFTER <color=red>SECOND</color> INTERNAL ASSIGN : {nameof(hasInteracted)}={hasInteracted}_");
}
Debug.Log($"BEFORE <color=red>THIRD</color> INTERNAL FOREACH : {nameof(hasInteracted)}={hasInteracted}_");
Debug.Log($"<color=red>-----------------------------</color>");
}
}
@sudden comet yes, they looking. I just retranslated their note about nested ForEach
@pulsar jay some - though I don't claim to be an expert
@sudden comet yes, they looking. I just retranslated their note about nested
ForEach
@storm ravine thank you, it is awesome to have a so direct contact 😉 I also sent a bug report
@amber flicker I appreciate any input on that matter 🙂 Just figured it might not work because the spawner entity is created by the conversion system. So I guess I will have to create the spawner entity from code in an AlwaysExecute script
@pulsar jay If your entities are created at runtime but you wanted them to be created also at edit-time, ExecuteAlways or whatever it's called might work if within an open subscene that's converted (I'm not sure, haven't tried). If it's outside of a subscene though, you'd need to call to create the editor world and add the systems you want to run.
Yes @amber flicker I got the editor world to run with DefaultWorldInitialization.DefaultLazyEditModeInitialize(); The system is also running. It seems like the last roadblock seems to be the GameObjectConversionUtility not working in edit mode. Sth seems to be null. Possibly because the conversion world does not exist in edit mode
hmm yea I'm not sure about GameObjectConversionUtility - I use my own GameObjectConversionSystem to convert my custom components after the GameObjectConversionGroup
interesting. Is there any specific advantage to using your own system?
