#archived-dots
1 messages · Page 180 of 1
and maybe they're also lazy devs.
But I neither feel compfortable enough to judge what is right or wrong in regards to ecs nor am I sure anybody else found the "correct" way already
eh, I don't know. I never liked inheritance in the first place.
it feels so bloated just by doing it.
@deft stump for me its the other way around
right now I have to write a lot of boilerplate code just to get things done with ecs
hell I cant even cast a blobArray into a nativeArray. and even that I have to deal with 3+ different kinds of arrays at all
and I still dont feel good about loosing controll over my data. if everything in a component is public any system could just change any field of it (e.g. set health to -50 and set isAlive to true). this may be a bad example because this probably shouldnt be the same component
Phew... great that im not the only one thinking like that... Well i understand that we shouldnt atomize components too much... like having a "Location" component and we extract the x,y,z position in extra components. But constructing gameplay out of those compositions is great and flexible, so why should we switch back to oop ? Well its probably a bit more complicated some times : "Entities.ForEach((Mob mob, Clicked clicked, RunTo runTo, Explode explode) => {});" but it has many advantages too
guess its a win some, lose some kind of thing. on the plus side there is definitely the performance. How well the extensibility thing turns out is remained to be seen though
@deft stump I thought all devs were lazy? 👀
@amber flicker wouldnt the advantage of a blobAsset vs a dynamicBuffer also be that I could easily reference it everywhere via blobAssetReference?
if you have to store a blobassetref somewhere you can always store an ICD with an entity
a dynamicBuffer would have to be put on some specific component on an entity. I would the have to obtain it from this entity every time I need it
sure - you could use a singleton if you like
alternatives also include shared statics or a public property on a system
yeah I guess it would have to be entities than
It should not even be a singleton as there could potentially be multiple tilesets
also I just figured out how to cast a blobarray into a native one but now it seems like there is no way to dispose a blobAsset 🙄
so I guess if nobady has an idea how to do that I will have to go with the dynamic buffer solution
btw. it would be great to integrate prefab conversion into the addressable assets. would make sense for it to be able to build "entityAssetBundles" out of the addressable assets
pretty sure there's just a dispose method but as I've mentioned, I think it's the wrong tool for the job personally
some ecs compatible adressables is planned - common request
some ecs compatible adressables is planned - common request
@amber flicker great. is there a forum thread or anything on it?
not that I know of - that would be what ye might call.. information. That be rare in these parts.
I think Joachim mentioned it was taking longer than expected
hopefully in the next update
i've hit the "yeah, enable/disable components is the right move here" multiple times
nah, theres a correct way, its composition. inheritance is the worst, and everyone who claims to want inheritance really wants polymorphism and doesn't know how to accomplish it in any way other than inheritance.
composition is a design principle, inheritance is an implementation strategy.
abstraction and polymorphism are wonderful principles, and programming would be lost without them
because of Oracle's aggressive (multi billion dollar) marketing campaign, inheritance is the most widely adopted enterprise developer way of accomplishing polymorphism and abstraction. Its a great example of how much lasting industry damage can be done by tying a product to an implementation strategy.
Now then, back to DOTS, which is totally not a product tied to an implementation strategy.
composition is a design principle, inheritance is an implementation strategy.
@tight blade Thing is C# is also build around this implementation strategy
yeah, C# and the original javascript both got eaten alive by the Oracle beast from the outset. Microsoft, ever the masters of being the third best at what they do, wanted to take market share from Oracle
javascript and to a degree even c# are both starting to outgrow it now, thank goodness
I guess the only thing you can do is move forward, and the only place you can do it from is where you are right now. C# will grow, and so will the gaming industry. And we here are part of something that could really move that needle forward
I dont blame you for not wanting to go against the grain, though, especially if thats how you were trained.
I guess the only thing you can do is move forward, and the only place you can do it from is where you are right now. C# will grow, and so will the gaming industry. And we here are part of something that could really move that needle forward
@tight blade I should frame that and create a motivational poster for the office from it 😅
or write it on my tombstone after a few more months of working with ECS
is it the right mindset to enable disable systems whenever I don't need them to run?
even if they don't have a match in Entities.ForEach?
to me, if applied broadly that seems like an incredibly small optimization (assuming is at all) that has the potential to backfire
thats what I'm afraid of honestly. backfiring
what I try to go by is, my systems always operate when the specific combination of data it declares, exists. If I don't want it to run, add a tag, change that explicit pattern of data.
of course sometimes there are reasons not to do it.. but in general the e.g. ForEach through it's definition is telling you under what circumstances it will run. That's awesome. If it's not running it means the data isn't in that pattern.
yeah, seems like you're saving a pretty silly small amount of time by disabling systems
id keep em on just to keep things more deterministic, unless theres something Im not aware of
if you really wanted to save on the query overhead, surely you could just have the first system in a group of systems that operate on similar entity patterns just set some flag to say "there are no entities this frame, dont bother with the query"
and then in the update loop of all the other ones, throw in a line that says "if (otherclass.noEntitiesHereGuys) return;"
there could definitely be something I dont know, though.
Entities.ForEach auto-(does not run the system) when there's no matching entities
but yeah... I should just leave them on for determinism
when enable/disable component comes around. then I can party 🥳
wouldnt it have to run the query though to determine if there are no matching entities? maybe a query for any is optimized
so...
im about to need to move on to a major next initiative which Ive been afraid of tackling, and Im wondering if I could steal some knowledge off of somebody
I want to pass a nativearray of floats to a shader
I really dont know anything about passing data into shaders at runtime
much less in DOTS
I actually have no idea how to write shaders in general except in ShaderGraph, so I'm praying that somebody tells me theres a way to do it with something made in shadergraph
@tight blade I think I glossed over some intersting docs concerning shader variables in the hybrid renderer docs
oooh
something like
Shader.SetGlobalVectorArray("_Points", positionList);
and you need to cast your native array into a list(not sure if it also takes arrays)
something like
Shader.SetGlobalVectorArray("_Points", positionList);
and you need to cast your native array into a list(not sure if it also takes arrays)
@safe lintel yeah that should work but its the classic way and not thread safe I guess
not sure if theres another way atm?
the hybrid renderer uses components to set the values somehow
the docs looked pretty solid on that but I just glossed over it
I think the way I've designed things I can get away with doing it on the main thread. its a static global array anyway. ideally I could stick it into a single thread job and use the handle to delay other writes until the copy finishes, right?
I mean I guess if I could somehow do it from threads that would be even awesomer
Are there any major breaking changes in the dataflowgraph API in the future?
@gusty comet probably, its not even publicly acknowledged outside of references by the animation team
though if you are using any other part of dots imo you could probably handle the changes assuming you stay current, the whole thing is progressing way slower than I wouldve expected
Thanks 🙏
I know it’s experimental and all but it really fits my use case
My ECS systems are just a bunch of event handlers sending events to each other
Not the best way to utilize ECS, but dataflowgraph looks much more suited
ugh when will they update the animation samples repo
-no
-i think hybrid renderer started to support skinned meshes on latest update
@gusty comet samples are approaching being a year out of date for dots animated skinnedmeshes 😩
does anyone have that url handy for what packages you need to install from url on a fresh build?
you know, the url of the forum post where everyone is complaining about having to do this in the first place?
found it!
lol, love that feeling when you update packages and things go red. Does anyone know what this got replaced with?
huh, no I feel like thats right. I think IntelliJ's assembly caches are confused
yup. turnt it off n on agin
so, this isnt really dots related, but do any of you ( @safe lintel ) happen to know how to reference these "global" properties, as in SetGlobalFloatArray("_Point", ...), from within a shader?
well, theres a whole other channel for this, actually
its like a whole discord server in here
which do you guys think would be faster
a) using an IJobParallelFor to copy values from one nativearray to another of the same size
b) using memcopy to load all the values from one native array into another
c) ????
probably memcpy, right?
@mint iron would probably have a good handle on this sort of thing
i typically use memcpy since it's more convenient for me API wise
you could technically do memcpy per different slice of an array
haha, yeah, probably overkill, right?
yeah, I guess you could jobify that. huh, actually thats not such a crazy idea
I think there are things in the Entities package that do that actually...
where have I seen that before..
there it is
yeah, with a raw pointer, you could actually jobify that fairly easily
I have no idea if that actually would be faster though, come to think of it
oh man, and then there's MemMove
has anyone ever messed with that?
nevermind, thats not what I was thinking it was
what's an easy way to instantiate a prefab entity from world A in world B?
i think you just instantiate it into world A and move/copy it to world B (off the top of my head - I haven't done anything like that)
@tight blade woudl be even faster to not use a job for that, just use the chunks list from the archetype directly. http://shorturl.at/gmzQX
hm thanks, sounds interesting. optimization aside, i need to ensure that it's done at the end of the frame and i don't really know how that should work, is there a world order, sync point?
ok, i need to look into ExclusiveEntityTransaction. i think that should solve it. feels awkward though that i need to put a system behind EndSimulationEntityCommandBufferSystem because i usually use commandbuffer instantiation in jobs.
wait a minute... where did the Entities debugger go?
Windows -> Analysis -> Entity Debugger
oh god im just an idiot, yeah there it is
How would you store the relationship of tiles in a tilemap. Right now I create tiles as entities. They also have a CellPosition but its hard to look them up this way as I would have to iterate over all CellPositions to find the one for a specific position. I currently use a NativeHashMap<int2,Entity> to access them by position but I cannot put that on a component as far as I know. I know there was some example ecs project which was also using tiles and storing them in an additional data structure but I cannot remember what it was
@digital scarab hope you're well - also from yesterday https://discordapp.com/channels/489222168727519232/497874303463850004/760847503246491651
How to handle Prefabs is like the no2 question around here (after why can't I find the packages 😅 )
.... coming... this.. year.. possibly? 👀
the... optimism?... is.. understandable. It's been about 6? months of close to zero comms though. Started to worry a bit.
There's an epic post on the forums if you haven't seen it but, for myself, ideally: 1) High level dots strategy post (Acton promised a blog post which I consider bare minimum quite some time ago), 2) fortnightly/monthly blog post from dots team on what's being worked on or failed experiments, 3) dream-land would be some kind of live dashboard of prioritised work being undertaken. Honestly you being occasionally around here is reassuring that the team hasn't been disbanded 🤣
this is to anyone. has something changed with physics? why isnt my cube falling anymore?
what is this witchery
Would be much appreciated.
I can understand there are perils with talking about what's being worked on - like inviting unwanted opinions 😅 .
That said, I personally feel often pretty blindsided by things (e.g. Data Flow Graph, DOTS Timeline etc). Almost no idea what's being worked on at all. I think quite a few of us feel fairly empowered by DOTS after a couple of years working with it - yet working on projects, no idea what we might expect to have changed in the next 1, 3, 6 or 24 months. Makes it incredibly hard to plan. Right now it's even harder if you want to contribute to the asset store and help DOTS developers. I hope there isn't someone working on an asset for better handling of DOTS Prefabs for example.
Is it a common strategy to use components as "commands" ? Lets say i want to "command" some of my entities to build somewhere a nice structure. I would just mark them with "Build(position, building-type)" and a system that iterates over "Entities.ForEach((Build build, MoveTo mvt) => {})" to inject the position and another loop to make sure they place down the building once they reached the "build-position" ?
Comms wise, would love to see some sort of roadmap if there is one
Most of the "Coming soon" stuff I know about, was glanced from forum replies joachim makes. Would be nice to have a more stable location to get news
I'm running into a problem with a large project that I have. DOTS sometimes doesn't seem to pick up changes to the data flow (which systems write to what, e.g adding a ref) without a rename of the System. Does anyone know how to refresh this? Restarting the editor doesn't seem to do it
I'd be happy to just delete a cache somewhere, but I don't know which cache
Is it a common strategy to use components as "commands" ? Lets say i want to "command" some of my entities to build somewhere a nice structure. I would just mark them with "Build(position, building-type)" and a system that iterates over "Entities.ForEach((Build build, MoveTo mvt) => {})" to inject the position and another loop to make sure they place down the building once they reached the "build-position" ?
@stone osprey your idea is right but using entities as messages is expensive. Try googling “Event System tertle”. It’s a package that allows very performant messaging
@gusty comet Thanks ! 🙂 Its probably ok, because there not that many entities building at once. Nevertheless events other than entity events are probably a good solution too.
What could we do that every system is able to run at any position in the system hierarchy ? Currently i run into the problem that some of systems put things into a list, a few other ones read that data and it gets disposed before the next frame, so i run the first system at the start.... and the disposal system at the end of the frame. This requires multiple systems at different locations which is probably not that great
Damn someone should really create some sort of website featuring ECS patterns and structures or all kind of mechanics and workflows...
If you loosen your view on a frame a bit, the same system that creates the initial thing can also dispose it. Something like:
void OnUpdate(){
DisposeOld();
MakeNew()
//probably other stuff?
}
So basically treat the system from a relative perspective where the "system-centered loop" starts and ends in the system.
Not sure if I understood your query correctly, and thus if this really answers it, but this pattern have had several other people fire off lightbulbs.
Also, don't get too hung up on perf - you get a lot of perf from ECS and long as you're not dumb about it, and most games could probably be written with mostly main-thread system, some job systems, and some optimized, bursted job systems.
Beware premature optimization - If you're trying to optimize because you think it might not be the fastest, take the time to actually test your hypothesis before spending that effort!
Oh, and +1 to this
some sort of website featuring ECS patterns and structures or all kind of mechanics and workflows
...and this website already has some of that. https://gametorrahod.com/tag/unity-ecs/
I do my event passing by adding stuff to DynamicBuffers of other entities in ecbs
@tawdry tree you’re right about premature optimization. I have a question about a performance issue I’m encountering though. I’m currently using a ton of message components as entity events. All these archetype chunks, one per event type - if I have 100+ of these, would all this occupied memory present a problem?
That doesn't need a resize 99% of the time
100+ chunks?
and 1 chunk has 1 entity?
(I'm probably reading your problem wrong @gusty comet )
Why do you need your tiles to be entities?
@digital scarab I want my Tiles to be Entities because what I refer to as Tiles are actual 3d objects (converted instantiated prefabs) on a Cell. They need to be rendered by the hybrid rendering system. This is why they have a CellPosition component. They are positioned by a GridPlacementSystem. So its easy to find the CellPosition from the Entity but it is hard to find a Tile that fills a specific cell without keeping a list. I guess the main question is how can I keep an ECS conform 2D list of Entities?
@amber flicker @digital scarab Got the BlobAsset cache working 🙂 Used an unsafe extension method to cast BlobArray to NativeArray and be able to destroy the converted prefabs. I would be really interested in how the planned prefab solution will work though
e.g. finding the tile on the neighbouring cell position or all the tiles in a radius
@pulsar jay You want a flattened 2d array, which is a method of taking a 2D (or 3D or 4D...) array and "flattening" it to one dimension. "flattened array" or "flattened list" as keywords should give you decent results
yes I have the math class to calculate that position
but now that I have the position I would have to loop over all CellPosition components to get the Tile on this cell position. I thought it might make more sense to have a lookup table CellPosition -> Tile but maybe looking through all the tiles is fast enough?
When does this lookup happen? On click? every frame? When something does something?
Because if it's less than once per frame then using a simple lookup should be no issue, perf-wise
I suppose the "worst case" would be an in game (runtime) map editor because it could add/remove/replace many tiles at once arcoss the whole map with one click
"Once" here potentially being multiple lookups, as long as they're in the same Job and not too many (<100, maybe?)
If it's an editor then just do it the easy way
As for batch commands, those could be done in better ways - instead of "find and change/delete this, then that, then that other one" you just "find everything that is within this rectangle, and change/delete those"
The simple way might still be performance enough for a rare user-initiated action (<1~5/s)
probably right
maybe the more problematic part might be a lot of entities querying for tiles on neighboring cells during gameplay (e.g. if any connected cell has a tile with BuffComponent on it get a buff)
that could potentially be many "querys" per frame
I assume you mean the grid structure as backing data, and then some other way for the rendering which can be -just- the rendering?
the tilemap itself is "just data"
its basically just a 2d list of integers
but a tile that might be spawned from it (e.g. a tower in a tower defense) will have a visual representation and functionality
@deft stump my situation is even worse than that, it’s 1 entity per chunk at most but most of the time 0 entities per chunk. Messages don’t get sent that often, so those chunks are just empty eating up space
then what Entity do you need to query for a BuffComponent? why not have the buff data be in your tile data?
@digital scarab that sounds interesting. but it also sounds like it might end up recreating an ecs like structure in my own data... bacause I tile might have several functions which could be components etc....
well in this case it wouldnt be turn based but I dont even wont to track the moving things so this should work well
It might even work to create it once at build time. I was looking for the appropriate data structure. Currently I am using a NativeHashMap<int2,Entity> which works great because I can quickly lookup/add/remove tiles but I cannot store this on an entity
What did you use in your hackweek project?
is this array stored in a system? because I cannot just pot a native array on an entity could I?
I am afraid there might be multiple different maps 😬 so I guess it would make sense to store it on an entity. was looking at dynamic buffers for that but not sure if thats the right "tool"
have to see how I can use that as a flattend array though it has to also stay "dynamic" during edit time but maybe it would be a good idea to just have a system that recreates the lookup table each frame
yeah the grid has no size 😬
its a sparse grid
I know. many gotchas
btw. how expensive it is to create a blobasset?
let's say... I want to create and re-create this blobasset every frame.
well, I was speaking hypotheticals; I don't plan to anyway.
terrible approach anyways.
but thanks for the answer.
@digital scarab would be great to have the prefab conversion integrated into the addressable btw. so it could convert them into blobAsset caches to be instantiated from
I think timboc mentioned that sth similar was planned already
Thanks @digital scarab for your input. Its good to know that I am not completely off track. Would be really interested in how the planned prefab conversion workflow will look like. I will try my luck with the Dynamic Buffer 🙂
gasps Topher is here 👀
i am still waiting on that new entity prefab workflow Topher...
Curly scared 'em off 😠
😄 i was just kidding, i am sure they are working hard
I guess a dynamic buffer cannot be shared? If I want to associate a dynamic buffer with multiple entities should I make a shared component which references another entity which has the buffer?
you could just have: an icd with a reference to a specific entity on all the entities you share it with, and on your specific entity it has a dynamic buffer
icd?
regular IComponentData
i see
right now I am trying to use a SharedComponent with an entity reference
but both should work. I just thought there might be a better way to share buffers
learning ECS sometimes feels like hammering nails with a screwdriver until somebody asks why you didnt use a hammer 🤔
is there a way to create an EntityQuery outside of a System? Because I cant access GetEntityQuery anywhere else
EntityManager.CreateEntityQuery
learning ECS sometimes feels like hammering nails with a screwdriver until somebody asks why you didnt use a hammer 🤔
@pulsar jay thats a good line
EntityManager.CreateEntityQuery
@rancid geode wow thanks. couldnt find that anywhere
hey can one of you folks drop into your entity debugger real quick and screenshot your ExportPhysicsWorld system?
i want to confirm a hypothesis without downgrading my version
sry dont have any physics running atm
guh. Well, Ive been chasing this bug all day. physics just totally stopped working. Figured it was related to the fact that I I upgraded unity editor and reinstalled packages so I probably have a newer one
Apparently, in this latest build, they've prevented any of the motion calculations for physicsbodies from being applied to the physics body's position unless it has a collider
you can see there ExportPhysicsWorld is getting no entities, even though BuildPhysicsWorld and StepPhysicsWorld both calculated the updated position 😦
is there any way to see a code diff between package versions?
I want to go yell at the physics guys
and I want to show them the line number
The thing is that code is the same in 0.5.0. The dynamic entities group is initialized with the same query...
Something strange goin on
What does the OnCreate of the new package look like? Does it Require the component somewhere?
I haven't come around updating to the newest version yet
I had to step out to take my dog to a vet. I'm trying to find the source online on my phone lol
They dont seem to keep it on github though :/
update:
it only affects the query for whether or not the system should run. if theres at least one entity with a collider, all physicsbodies will be exported
A while back when playing with ECS I recall reading something about being able to have a subscene loaded, but run it slower than normal, Am I just remembering wrong?
I havent done anything with subscenes, yet unfortunately.
Can someone recommend a comprehensive up to date tutorial on dots, primarily on data handling? I am struggling so much, and the fact that a lot of outdated info is still floating around and partially is even still in the official documentation does not make this any easier.
I am even struggling to do something as simple as creating an entity that has actual values attached to it let alone change those values from the monobehavior side of things.
https://hastebin.com/abofaxebin.xml is how I created the entity and attached the components to it, but how the heck do I even attach those components with initial values?
the player component is literally an empty tag component and the position component has two integers xPos and YPos that I obviously want to assign a value to.
@gusty comet you can use
entityManager.SetComponent<Position>(player, new Position{XPos = 25, YPos = 200});
right after the Add Component.
or the lazy route:
entityManager.AddComponent<Position>(player, new Position{XPos = 200, YPos = 59129.121f})
oh wait derp of course we are in value types now so I can just do that... I had to see it to be reminded of that. Thanks a heap much appreciated
Well it tells me that AddComponent does not have a method that takes two arguments...
And the other thing errors on it wanting an entity command buffer...
Well I leave it at that for today.
wait... are you doing it in a system?
is there any way to see a code diff between package versions?
They dont seem to keep it on github though :/
@tight blade yeah it would be great if all the DOTS repos were on github and we could see PRs and commits like the Graphics repo. That aside, you could still download the two different package versions (install then save external copies from the package cache to elsewhere) and diff the C# yourself using git or any diff tool.
There's https://github.com/needle-mirror
@tight blade Something like this? https://github.com/needle-mirror/com.unity.physics/compare/0.4.1-preview...0.5.0-preview.1
In NetCode, why would my values be reverted after one frame when my ghost owner's ghost field is set on the client?
no idea william sorry :/
i have a quick query regarding the behaviour of componentsystems
i'm using a modified version of the netcube demo
i've decided to add a main menu in a separate scene which works fine, the problem is that when i load the scene the systems aren't reset
so they don't run oncreated again
is there a way i can fix that?
Just a DDOL?
DDDOL?
Or make a onLoadScene function
Don't destroy on load
It keeps the data between scenes
ah :P
yeah i know, my problem is that the componentsystems aren't re initialising
the dots ones
make a listener for a OnSceneLoad
ah ok
And call oncreated there
thanks
Was there going to be entities release that features the option to disable components? 🤔
@deft stump not in a system as I said in my initial thing the whole thing was from a monobehavior
Was there going to be entities release that features the option to disable components? 🤔
@twin raven it's planned.
not in a system as I said in my initial thing the whole thing was from a monobehavior
@gusty comet strange that it's asking for ecb.
that was with the Set component it seems to require that
This is what I mean though its utterly confusing and poorly document for something that I can do in 5 seconds in c# it takes me an hour here
Also @deft stump the actual syntax is entityManager.AddComponentData<Position>(player, new Position { posX = 100, posY = 100 });
Aaaaah
Lol
No intellisense to corrsct me
I blame discord for not having intellisense
So yeah at least I got that to work now I know how to create and modify entities to some degree, still my criticism still stands that its far more convoluted then necessary and its kind of a good thing that they kept it preview longer then planned
Was there going to be entities release that features the option to disable components? 🤔
@twin raven
https://docs.unity3d.com/Packages/com.unity.entities@0.14/api/Unity.Entities.Disabled.html
Oh that disables an Entity, you want to disable a component, my mistake
I am not sure what you are asking. A component is just raw data. What would be the behavior of "disabling" that?
its because adding/removing is too costly, why even bother copying data around / structural changes, if you can just keep an index of flags and enable/disable components when its something that could be added/removed multiple times (or you prefer performance over useless data taking up memory)
they said its a feature they were implementing about 6 months ago and we havent heard anything since!
Does unity waits on all system jobs to complete before running them? And if so how does it do it if no one explicitly called Complete() on any of the JobHandles created by the systems?
each system tracks the jobs that were started within them when using Entities.ForEach. optionally you can explicitly assign dependencies to make jobs execute after each other if you want. All jobs scheduled within a system and tracked either automatically or explicitly will be completed each frame. You can however independently schedule jobs if you want a job to run multiple frames without being forced to complete.
yea but they need to complete before even finishing a frame are'nt they?
because all systems are completed probably N times a frame
so one cycle needs to be finished before new one needs to start
no ?
@remote torrent I am still not sure what you want. As said how do you imagine inert data being "disabled". I assume what you want is that under specific circumstances you do not want to consider a given set of entities despite them having a given component. That is what you can already get by having specialized tags for that. So I guess you basically want syntactic sugar for that?
Unless I am grossly misunderstanding something here, in that case sorry.
@mint iron
oh wait did I ping the wrong person. Fuuu. I am sorry.
I pinged him only because I still waiting on his response 😄
I am still not sure what you want. As said how do you imagine inert data being "disabled". I assume what you want is that under specific circumstances you do not want to consider a given set of entities despite them having a given component. That is what you can already get by having specialized tags for that. So I guess you basically want syntactic sugar for that?
@gusty cometits more on keeping the spirit of making your code cache friendly without the need of moving chunks via tags. or weird if statements that just early outs.
Tags are great, but they're costly to add / remove because of the chunk system.
and putting If statements inside Entities.ForEach() such as:
Entities.ForEach((SomeData somedata) =>
{
if (somedata.can_I_Do_Work_Now)
return;
//some work here
}).Run();
is a waste of cache coz you've already gathered somedata to work on, only to throw it away.
thus the solution of enable/disable components is much needed.
no more add / remove tag. thus no more moving to and from chunks.
and no more weird if statements that all it does is early out.
Entities.ForEach won't run (thus most likely, your system won't run) coz the Component its trying to gather isn't primed to be worked on.
Again how do you "disable" inert data? The data itsself does not know any state it IS state. What you want is not possible without incurring the cost anyway. A disabling would at best syntactic sugar.
you're not disabling it.
you're just telling the entity query to just not query it / just ignore it.
also, right now. unity hasn't implemented this much requested feature
@deft stump its not that costly anymore since ECB is using burst now
enabling and disabling a component is in works i think, but god knows when it will come
maybe as a new year gift
In May, Joachim estimated between 3 weeks/months. Recently, he mentioned, he was a bit optimistic: https://forum.unity.com/threads/dots-skill-system-repo-available.894007/page-2#post-6324234
(Completely fine, it's hard to estimate a feature like component disabling/enabling)
The May post is referenced just above the one I am referencing.
Really looking forward to this feature, as it means nearly no structural changes anymore and constant entity sizes (I already have this but need an enabled bool in some components and need to skip them myself, not great)
its not that costly anymore since ECB is using burst now
@opaque ledge but moving entities to and from chunks is, right?
maybe as a new year gift
if it comes before my birthday then I'll consider it the best gift unity gave me
😄
I think @mint iron makes perfect sense. Using "tags" has always bothered me because every time you add or remove a component, that entity has to be removed from its current chunk and moved to another chunk. Using tags to assist in entity queries seems to be an officially supported/promoted pattern.
So yes, adding and removing components from an entity has performance consequences. I think all he is saying is he would like to have a means to avoid those consequences.
Tags are perfectly fine if they change infrequently (or never), they only become a problem when you move around 1000s of entities per frame
Going to ask again, is there guarantee that for each update cycle for all ecs systems, unity is going to wait on all system jobs before running another cycle? Otherwise there going to be jobs from more advance cycles running before older cycle jobs, am I correct?
@hearty leaf every job you add to the Dependency handle in your system is completed before that system runs again
@rett clearly that's the case for almost anything. Doing something expensive once, you can get away with it.
@worldly pulsar 2 questions then:
- If I don't add a job to the Depndency handle of my system, can a later cycle of this system run before the older one since it's multi-threaded and we can't guarantee order?
- How do I set up system depndency handle to it's self?
But the point that was trying to be made was, in general, it would be nice if there were away to disable components instead of having to remove them and I think it's totally valid. I still think making structural changes to entities as a means of triggering queries seems like a poor solution
@swift heron What I mean is having an entity with tags {Enemy, Alive} that later (only once) change into {Enemy, Dead} is strictly better for query performance than having a flag for IsEnemy and IsDead
but yeah, having an "queries please ignore the existence of component X on this specific entity" would be great
@worldly pulsar I think you mixed up the answers with the other guy ? 😮
woops 🙂
@hearty leaf 1. If you just drop the handle on the floor there are no guarantees on anything. Entities.ForEach has additional magic that may - and probably will - complete your job tho.
2. not sure I understand the question
@worldly pulsar So I'm not sure there's no guarantee that a later cycle can complete before older one ? 😕 and you said prior every job you add to the Dependency handle in your system so that I can do that to guarantee the it won't happen? but that means if I have MyJob that runs on MySystem I need to make it dependent on itself to later cycles won't run before older ones?
If you schedule MyJob and for some reason don't want to add it to Dependency, you can just store the handle in your system and Complete() it at the beginning of the next update
or you can just do
Dependency = myJob.Schedule(Dependency);
you can actually make it depndent on the previous job handle of the last run ?
At the beginning of OnUpdate Dependency is not the handle from last run
it's overriden somewhere in the internals (don't remember exactly where, something like BeforeUpdate() )
Dependency is a property of IJob or just a property you used to save last JobHandle?
Dependency is a property of SystemBase
before SystemBase (in JobComponentSystem) OnUpdate used to have JobHandle as argument and return value
and they changed it to have a Dependency property for convenience
hmm I see
so unity is actually making it so jobs depend on themselved as-well as other jobs readin/writing same components?
automatically
I'm still not sure what you mean by depending on themselves
a job can't wait for itself to finish before starting
what I mean by it
is that the ECS
is calling the OnUpdate method of each system
numerous times a frame
so when it finished one cycle of all OnUpdate of registered systems
it starts another cycle correct?
it calls all of them once a frame, but otherwise correct, yes
why would you want them to run as many times as possible?
so how something like a RenderSystem would achieve higher framerate? Isn't running something like RenderSystem multiple times a frame would result in a higher frame rate
sorry sorry
I meant in a second*
I mixed up some things
ok, "a second" makes much more sense 🙂
is calling the OnUpdate method of each system numerous times a frame
->
is calling the OnUpdate method of each system numerous times a second
so how do you make sure a later run won't run before previous run
is it more clear now ?
because we're basically dispatching jobs in threads
that's what Dependency is for, the handle you put in Dependency is completed before another Update
ok so back to this Dependency Property of BaseSystem does unity sets it up in the BeforeUpdate in such a way that the current system job is dependent on the current system job as-well ? 😕
by the time you reach OnUpdate any job scheduled previously by the system is completed
what guarantees this ?
unity internals just going through all previous frame JobHandles and wait on them ?
BeforeUpdate() is essentially
Dependency = FigureOutDependenciesFromPreviousSystems();```
so first run Dependency.Complete() does nothing since it's not initialized?
and later runs it is via Dependency = FigureOutDependenciesFromPreviousSystems();?
yea, there is some more magic there, read the source for details
gotcha
one more question related to Jobs if you don't mind
the way I setup inputs and outputs
is only via setting object properties?
like so:
Myjob job = new MyJob();
job.x = 8;
job.y = 9;
...
job.result
no other way ?
no nicer interface?
SystemBase has Job.WithCode()
which uses the same codegen magic Entities.ForEach uses
but if you want to define your own job structs then inputs go into struct fields/native arrays, outputs via native arrays. No way around it
And of course, jobs are structs like any other, so you can give them constructors.
So back with my daily questions... how would you implement conditions ? Lets say we wanna construct a timer/task/countdown in the ecs. That one finishes by itself or it can get abborted. The abbort condition should be flexible aswell, and there probably multiple ones. My current solution is the following : Condition{ list of bools }, AbbortIfMoved {Marker }, AbbortIfMovedSystem{ running on AbbortIfMoved & Condition to check if entity moved and if, writes the bool into "Condition" }, CountdownSystem { Checking the condition and if its true, abbort }... Whats the problem with that ? First of all every new condition requires a new system. The second problem is that each entity can only have "one" condition... because the "Condition" component only stores a list of plain bools... that works fine for a countdown timer, but causes problems for more complex entities.
How would you implement such "conditions" for entities in an ecs ?
@glacial berry @hearty leaf @swift heron The concept of tags is fine; its nice to be able to have an Entities.ForEach that only operates on the components you want to include. The problem is with the way it was designed. When you add/remove components it changes the archetype, and is a structural change as hanke mentioned, and structural changes require completing all other jobs on top of the costs to calculate where everything needs to go, potentially allocate, copy the data, re-index all sorts of stuff to make it work. Queueing changes with ECB and replaying later in deliberate sync points is specifically to avoid that problem and is really just a work-around.
Its the same line of optimization as class allocation avoidance and pooling, re-use stuff instead of deleting it and making new things constantly. The components wouldn't be removed when disabled, they just get marked somewhere else in a fast index as disabled, and Entities.ForEach would check the index and ignore them. So instead of doing a bunch of work, you just like set a flag and you're done.
I'm a bit confused, I've not touched my project in some time. Now I'm trying to poinpoint some error, I remove my AddComponentData from AuthoringComponent (checking that this is the only place where I add component etc). But my Ghosts still seem to have the component. I've tried deleting SceneDependencyCache, Updating all Ghosts & removing and generating the NetCode code. Anyone got any idea? 🤔
Ok, so the thing was I had GhostCollection in a subscene which I only indexed from hash of scene. So I had to make a new scene, put the subscene in the script and reimport it.
I need help understanding GhostFields in NetCode since there isn't much doc on them. I have a player that is owner predicted with a component with a ghost field. When I set the ghost field's value on the owner's client, the server receives it but immediately reverts the value. What am I missing so that the client can set his own value to a ghost field without the server overriding it?
Think you need to set value through the input/rpc
Or is that not possible and I'm supposed to set the value in the server?
Haaa alright then
It's only predicted, not authoritive
Makes sense thank you. So I need to set it on the client, then send an RPC to the server
I had somehow unlearned how prediction works lmao
I'm not sure what type of value you're talking about, but you would generally do it by consequence of the commands(inputs) from the player
Or do a RPC to server which will change the value to the player, which will not be predicted.
I'm still not sure of how to decide between input and RPCs. My use case is: The player can click on a ghost in the scene to set it's ghost id as his target, I have a component target with "TargetGhostID" that needs to be synced between all clients and server
Surely I'm not meant to send the location of the mouse raycast to the server and then determine the target?
I guess it depends, if it needs to be cheat proof, maybe you need raycast? If not, put the targetGhostID in your command struct. I assume you're doing actions directly on that target after selected it, so it needs to be set on client right away to predict further actions?
I think I can afford the delay it takes to set the target via RPC
I'll play around with the command struct and RPCs to try and figure out what is best
Thanks for the guidance!
General question for ECS, but should purely data be an entity? Like storing the speed of different classes of ships in an entity instead of on every ship but just referencing that entity, or storing the global player statistics in an "singleton" entity.
Nothing wrong with storing some global data on a singleton entity. That's what they do in the project tiny samples
big oof 😦
I've found a pretty fundamental problem in NetCode 0.4 with lost inputs and I made a specific test extending the NetCube sample which also failed.
My test uses GetKeyDown(KeyCode.Space). The expected behaviour is that every keyDown is received on the server but in reality some are lost. They are reported on the client but not on the server.
The test server runs in AWS and I'm not aware of any issues having to with that.
Any help or insight is appreciated.
i've posted further details in the forum, the current conclusion is when the prediction tick is the final tick the input is lost!
Is there an easy way to copy all of an entity's components into another if I can't instantiate a new entity?
there's EntityManager.CopyEntities
Yeah but I need to copy into another :/
if anyone got some time, i'd like to know if someone can reproduce this error in netcode and unity 2020.1.4f1 or higher. project link: https://bit.ly/30twGI8 - when pressing space, sometimes the server doesn't receive the input. more info here: https://forum.unity.com/threads/dots-netcode-0-4-0-released.971838/page-2#post-6379683
there's also EntityManager.CopyEntitiesFrom if you need entities from another world
Jo @viral sonnet it's the guy who answered you on the forum earlier. I downloaded your project and I'm still pretty certain that it's just related to the way the input is sampled. ``` var isInputForThisTickAlreadyStored = inputBuffer.GetDataAtTick( input.Tick, out var dupCmd ) && dupCmd.Tick == input.Tick;
if ( !isInputForThisTickAlreadyStored )
{
if (input.jump)
{
Debug.Log("CLIENT JUMP at tick " + input.Tick);
}
inputBuffer.AddCommandData( input );
}```
Changing your sampling code to that prints the "Client jump at tick" correctly for me.
cool! hey! o/
I changed it to your code and on some spaces i get no output then
do you get a full print everytime?
No. You basically have to implement your own GetKeyDown logic which takes the last command that you stored into account.
Because it will only store the very first command you sample each tick
i'm not aware of any rollback or something in input sampling so I'm not sure what you mean
Inputs are stored based upon ticks. The problem you had earlier came from you storing/sending an input to the server and in a later frame overriding it on the client.
hm someone on the forum could reproduce the error. can you post your CubeInput.cs that's working for you?
Wait let me do a sample which also shows how to handle GetKeyDowns with the sampling stuff correctly
thanks!
Took a bit longer than I've expected. I had problems with unity not wanting to generate a .sln for me
no problem. thank you! i'm not sure why the early out works for you. the good news is, i got it to a state where it seems to work - i just don't know why really
var inputBuffer = EntityManager.GetBuffer<CubeInput>(localInput);
var isInputForThisTickAlreadyStored = inputBuffer.GetDataAtTick(serverTick, out var dupCmd) && dupCmd.Tick == serverTick;
var spaceDown = Input.GetKeyDown(KeyCode.Space);
if (!isInputForThisTickAlreadyStored)
{
var input = default(CubeInput);
input.Tick = serverTick;
input.jump = spaceDown;
inputBuffer.AddCommandData(input);
}
else
{
if (spaceDown)
dupCmd.jump = spaceDown;
inputBuffer.AddCommandData(dupCmd);
} ```
this is the shortest form with which i could get it to work. what i don't understand is why it's so important that i have a condition for spaceDown in the else
it doesn't work otherwise
something in my understanding of input sampling and command data must be wrong
@mint iron same page -- my sentiment exactly
is there anything in the Tiny 2D project template that disables 3d rendering?
Answer was that it is the 2D Renderer package
How do we track changes of variables efficiently ? I need to execute some stuff once a attribute of my "condition" component changes from "false" to "true".... instead of every frame, just once when it gets toogled. Do we need to manually track the history or is there a simpler way in unitys ecs ?
I spent months looking for a good way to store data in a ECS game, data as in weapon information (name, description, base stats) and the like. And I eventually dropped the project (and game dev in general) after burning out going through native and blobs failing to get it working.
I just came back and started from a different angle, everyone always says ECS is so easy to save and load, and I believe them, I can't find any resources showing HOW it works but it's data driven so it must be (if anyone has resources please share)?
But while looking up how people handle saving in ECS I see someone mention them saving a reference to the base "entity" before it was modified to see if it needs special settings applied when I suddenly realised.... can't I just make a dictionary of all my "data" and just ... hash its name and store that int reference in ECS?
How do we track changes of variables efficiently ? I need to execute some stuff once a attribute of my "condition" component changes from "false" to "true".... instead of every frame, just once when it gets toogled. Do we need to manually track the history or is there a simpler way in unitys ecs ?
@stone osprey Maybe the EntityQuery.SetFilterChanged method would be useful to you?
@loud matrix data is stored in the components
Theres also the concept of entity versions or something like that, but it's a real rabbit hole. For now you can use that SetFilterChanged method to restrict the query to entities that have had a component modified in the last frame
@toxic walrus I know, but I don't want to assign identical data to 1000 entities when I can assign a reference to the unchanging data, especially when it means i can store things i can't easily store in ECS like strings the bane of my existence for 3 months.
@loud matrix sounds like a use case for shared-component
Would that not be a pain to handle not blittable data and saving?
@gusty comet Thanks a lot, that helps 🙂 Does this only work when setting/adding components ? Some of my systems using direct component references to modify values, not sure if those changes also getting tracked
I've updated this project to the latest entities package, hope it is useful for someone: https://github.com/ElliotB256/ECSCombat
I'm basically waiting for tiny to get custom shaders then I'll have fun porting it over
@gusty comet Thanks a lot, that helps 🙂 Does this only work when setting/adding components ? Some of my systems using direct component references to modify values, not sure if those changes also getting tracked
@stone osprey It works when you modify a component. For example, if your component has only a boolean value, it appears in the EntityQuery when that boolean value is modified. If you want to detect if a component is added, then look up "Unity ECS Reactive System"
@gusty comet No, this is exactly what i need 😄 Thanks... just wondering how unity detects that i changed the bool value ^^
https://docs.unity3d.com/Packages/com.unity.entities@0.14/manual/ecs_entity_query.html?q=filter#change-filters typically when you want a write access the chunk is notitfied, not whether the the data was actually written to
I have seen references to having separate worlds for simulation and rendering, does this mean you can modify the speed of the world to enhance performance?
I'm finding my tiny project builds, but nothing shows up when running the build - just a blank screen without any objects. I can see them in editor (but IIRC that uses a different rendering pipeline). I've got Unity.Tiny.Rendering included in the assembly, is there anything else I am missing?
has someone tried to use the 2D renderer package without tiny?
hi there, is it posible to sort a list of entities on a lookup by component data
I dont know much about lookup colection so i tried this
Lookup<int, Entity> l_up = aux_entities.ToLookup<int, Entity>(p => world.EntityManager.GetComponentData<SampleOccluderID>(p).OccluderID, p => p);
but it gives me a syntax error
this part i am working on main thread so its easier
Those are Linq functions, they don't really have anything to do with ECS
Small Joachim update on DOTS: https://forum.unity.com/threads/looking-forward-to-dots-roadmap-information-in-2020.980850/#post-6382230
they should be working more on better hybrid workflows, as a way to bridge the gaps
cant really expect people to write full game in DOTS until years from now
What is the best way to find an entity with a specific component value?
@pulsar jay "Best" will depend a lot on your exact scenario. Other than the obvious (foreach entity == value), choosing/filling/maintaining an acceleration structure (i.e. hashmap). In occasional instances shared component data.
I am still trying to reference the tiles with their CellPosition components by position.
Atm I see two possible ways:
- Iterate over all CellPositions and find the on mathcing the position
- Building an acceleration structure
- Would need to be a 2D Array though and I didnt find a way to store a flattened 2D Array on an entity
So I am trying the iteration approach now
I am currently trying to replace my (non system) GetEntityFromCell method which currently uses a NativeHashmap to lookup the entites on a cell
there are so many ways you could do this. Imo a lot depends on what tile data is regularly changing and why. You can, as an example, add a CellIndex component to every tile generated which is just an int into a NativeArray (or multiple Arrays) that are public members of a System.
If you're trying to pick the most optimal thing from the start (which I would advise against), you need to think about what's happening with the data at what frequency - do neighbouring cells need to constantly check with each other and you need some optimised structure for that? Do you need AI nav between tiles? Is it worth duplicating the data in another more flat structure for an AI system? I'd get something working first and tackle performance issues as they come up.
I'd get something working first and tackle performance issues as they come up.
@amber flicker yeah thats what I thought. Thats why I stopped with the acceleration structure and started to just "search" for the entity
Currently it looks like this:
var query = Manager.CreateEntityQuery(ComponentType.ReadOnly<CellPosition>());
var entities = query.ToEntityArray(Allocator.Temp);
var positions = query.ToComponentDataArray<CellPosition>(Allocator.Temp);
var position = positions.FirstOrDefault(p => p.Value.Equals(positions));
this should work for getting the correct cellposition component but how would I get the entity now
if you're using linq there should be an index overload - e.g. (p,idx) =>... but I can't remember off the top of my head which methods have that (you might need Select or smth) but that should be easy to google. Which you can then use into your entities array. Though I might, myself, make this into a job if I'm generally trying to make something bursted & multithreaded but as I literally just said not to worry too much about performance 😅 , that looks ok to me
yeah also thought about turning it into a job. but for now I would like to also use it outside of systems and the job would need to return an entity. Dont know how to do that though 🤔
The index overload sounds good. So can I be sure that the indices in the component data array and entity arre are the same?
yes
imo executing logic from monobehaviour isn't a very nice workflow.. that said, you can e.g. have a system (that doesn't automatically run) that you call .Update() on then get the result via an exposed public NativeList<Entity> Results; that you've created in mb land.
I see. But wouldnt that at least break mutlithreading because I could just publically access the results list at any time?
if you're workflow is outside of systems.. you need to manage your own scheduling if you're trying to do multithreaded stuff. In this case, I'd just use Run().
yeah good to know. I am just trying to port the MB code step by step. For now this works out pretty well as a can always ensure that everything still works as before after each small step. Eventually it should run as full ecs
thx again for your help. Found the Linq overload:
positions.Select((pos, index) => new {pos, index}).FirstOrDefault(p => p.pos.Value.Equals(pos));
wow this is still surprisingly fast without burst, jobs or anything 🙂
I didn't see anything in the changelogs yet, but I know there was talk of making components Enabled/Disabled at some point - does anyone know whether this is here/imminent?
k Cheers! 👍
does anyone know when/under what conditions a Parent ICD turns into a PreviousParent?
@amber flicker looks like if that entity query isn't empty the PreviousParent get's attached to the entity
hmm.. you mean anything that has Parent, LTW & LTP removes Parent and adds PreviousParent?
well they handle different cases in the parent system - there's UpdateChangeParents(), UpdateDeletedParents(), UpdateNewParents(), UpdateRemoveParents()
I appreciate the help but I'm finding this as clear as mud 😅 . I'm trying to work out if an entity with a PreviousParent ICD is currently considered to be within a hierarchy... I think the answer is yes? Or perhaps it's only if there's also an LTP?
Yeah I'm looking at the code just to see what's going on 😅
Anybody has an idea how to get ScriptableObject data into a system? Trying to do this MapData -> MapLoadingSystem -> MapEntities
@amber flicker so if you remove the LTP component, the PreviousParent also gets removed. The children entities are still within the hierarchy since the children still have the Parent entity and the Parent entity will still have a DynamicBuffer of children
wait sorry, the DynamicBuffer of children doesn't exist (got mixed up with a component I had which does something similar)
So the LTP gets updated if the chunk transform data changes 🤔
hmm there's a lot of transformation structs to comb through 😅
I think the LTP will get updated if the previous parent moves since a system will run on the DynamicBuffer<Child> to update the ParentInverseScale component which will cause the chunk to update (probably just need to write a small system which moves and shuffles the PreviousParent to see what happens)
That sounds... like a lot of implicit behaviour
Well I gave it a try but it doesn't change the matrices 🤔
One quick question... im trying to use the "FixedList32" for storing some of my structs... When i try to .Add() one of my structs its throws me a capacity exception. Any idea why ? I havent found a way to set the capacity... thought it would resize on its own
Exception in the last line where i set the data.
The exception i receive... i tried to change .Capacity or .Length none worked... how the hell do we use that FixedList ?
Furthermore what should we stick with ? UnsafeList, NativeList or FixedList ? 😛
FixedList32 can store 32B, your struct is probably bigger
UnsafeList/NativeList/FixedList are different things for different use cases
NativeList - separate allocation
FixedList - "inline" list, for small amount of data
UnsafeList - like NativeList but with less restrictions/safety
Damn... thats right, my struct uses one FixedString32 and one short... Thanks, that should do the trick 🙂 Then im using a nativelist instead
Is there a way to use unitys ecs without the unity engine ?
Or does the ecs make use of the engine itself ?
Project Tiny uses ECS without any part of UnityEngine at runtime
@zenith wyvern Thanks, thats pretty cool 🙂 Does this mean we can download that ecs like a lib someday for using it in any c# project ?
I'm not sure. You can always check out the Tiny source and see what they're doing, maybe it's possible right now
something odd: with a subscene open for editing, when i enter play mode everything is fine. but if i close the subscene and enter play mode, some authoring components don't appear to work. i've tried reimporting the subscene and clearing the entity caches. any ideas on what i can do to get it to work?
the authoring component only references a prefab but that shouldn't cause a problem, right?
never mind. it suddenly works for some reason....
i was just looking at the use of rpcs in the dots sample
i'm a bit confused as it seems to completely defy the "data oriented" theme of the package
are we supposed to write functions inside IRpcComponent?
for serialisation?
it seems a bit counter intuitive to me
How do I inform a parent entity about its children? I guess when converting a gameObject hierarchy unity automatically attaches a DynamicBuffer with children or sth. So it seems just parenting by AddComponentData(entity, new Parent() { Value = parent }); is not enough when doing it from code
This is why creating hierarchy at runtime isn't fun 😄 - there may be some convenience methods - I'm not personally aware of any
There should be convenience methods but I havent found any yet
I guess I will just have to add some kind of childbuffer
Honestly I haven't done much of this but I think there may be a better and worse way to do it. For example, if you add a LinkedEntityGroup to the parent, the Child & Parent buffers may get added - not sure what to suggest other than checking out some of the source or experimenting
Ok will have a look at LinkedEntityGroup too. For now I only want the children to be destroyed with the parent so the child buffer might suffice
I cannot add anything to the linked entity group 😕
layoutEntityGroup.Add(entity); throws an error
Attempted to access BufferTypeHandle<Unity.Entities.LinkedEntityGroup> which has been invalidated by a structural change.
but this is the method used by the conversion system
you are doing a structral change before you add stuff, you have to get a reference again just before you start adding to entity group
Thx @opaque ledge this prevents the error
But it does not seem to add anything:
gridEntityGroup.Add(cellEntity);```
the linked entity group is still empty
well it shouldnt
Manager is EntityManager struct right ?
it should work tbh, no idea why
anyways, i am back to work, gl with that
hey ..
there is an ANR ..
What is the solution.. help me
ANR "Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 4. Wait queue head age: 5604.6ms.) com.unity3d.player.UnityPlayerActivity"
yeah thats the entity manager
I am not in a system so it is defined like that:
private static EntityManager Manager => World.DefaultGameObjectInjectionWorld.EntityManager;
oh my bad. was looking on the wrong entity. it actually works. Thx @opaque ledge
It does seem like EntityManager.Destroy(entity) does not destroy all entities in the group
I have an entity with a LinkedEntityGroup linking 2 entities. However only one of them gets destoryed when I destroy the root entity
It is even consistent. It is always the first of the two linked entities that does not get destroyed 🤔
Could any body test this code or tell me whats wrong with it:
Manager.SetName(rootEntity, "Root Entity");
var child1 = Manager.CreateEntity();
Manager.SetName(child1, "Child 1");
var child2 = Manager.CreateEntity();
Manager.SetName(child2, "Child 2");
var buffer = Manager.GetBuffer<LinkedEntityGroup>(rootEntity);
buffer.Add(child1);
buffer.Add(child2);
Manager.DestroyEntity(rootEntity);```
rootEntity and child2 get destroyed as intended but child1 always remains
does it make a difference if you give a chance for the parenting systems to run? e.g. wait at least a frame before destroyentity?
no doesnt make any difference
I am running this in edit mode though so there may be "side effects"
nah edit mode should behave the same generally
It may be you also need to create the Child buffer and the Parent components - I don't understand that whole system but I would guess you need to end up with whatever a converted hierarchy ends up with
just tried it in playmode. I call the create and destory methods manually from inspector so there are several frames in between
oh I thought you just meant in editor.. ok I'm not sure your systems will be running if in edit-mode in editor
It may be you also need to create the Child buffer and the Parent components - I don't understand that whole system but I would guess you need to end up with whatever a converted hierarchy ends up with
@amber flicker didnt do this yet in my repro case. it does not seem to have an effect though
oh I thought you just meant in editor.. ok I'm not sure your systems will be running if in edit-mode in editor
@amber flicker yeah they do. was a lot of work to figure out how but they run
interesting side note: if you use a parent component and the referenced parent has a child buffer the child will be automatically added to it
@pulsar jay yea you can certainly do it but it doesn't happen by default is all I meant - though some systems run when you e.g. open a subscene. Good to know about the child being added
Manager.SetName(rootEntity, "Root Entity");
var child1 = Manager.CreateEntity(typeof(Parent));
Manager.SetComponentData(child1, new Parent() { Value = rootEntity });
Manager.SetName(child1, "Child 1");
var child2 = Manager.CreateEntity(typeof(Parent));
Manager.SetComponentData(child2, new Parent() { Value = rootEntity });
Manager.SetName(child2, "Child 2");
var buffer = Manager.GetBuffer<LinkedEntityGroup>(rootEntity);
buffer.Add(child1);
buffer.Add(child2);````
just add parent and child components. they link correctly but still the same. one child gets destroyed, the other one stays 😬
I think the parent and child components are not connected to destroying entities
From the docs of LinkedEntityGroup this seems to be the whole reason of this component. To link lifetimes together
except.. the lifetimes aren't linked unless there's also a hierarchical relationship?
yeah I see what you mean. with the updated code they are also in a parent child relationship now. but it does not change anything
and it would totally make sense to decouple the lifetime connection from the hierarchy
yea.. I assume there's.. a reason
Any idea how we could store entities in databases ?
And more important... how would we convert them from the database to an entity and the other way around ?
@stone osprey we know Unity are working on improving prefab workflow.. likely involving Blobassets somehow by the sounds of it. If you can avoid touching this for a couple of months, I'd be very tempted to wait myself.
I have a default Unity project with GameObjects not DOTS. Is it still possible to use the Job System https://docs.unity3d.com/Manual/JobSystem.html ?
@unreal scarab yes the job system is independent
you just need the jobs package
@amber flicker I need to correct that. The child buffer is filled automatically if the parent has a LocalToWorld and the children have a LocalToWorld and a ParentToWorld
but this still doesnt lead to all linkedentities being destroyed
@pulsar jay thank you!
Wow I just found the solution to my linkedentitygroup problem @amber flicker. The first entry in the linked entity group has to be the root itself 🤯
I guess it is just being skipped as it should already being destroyed
oooh yes.. that's true.. completely didn't spot you weren't doing that in code.. ok that makes a lot more sense
does anyone know if there are any stats available on like "average memory footprint of games by genre and platform"?
anyone who has worked with animation jobs api?
is there a way i can add a normal (ijobparallelfor) as a dependency of an animationjob?
Huh, is getting Havok the only way to get the Unity Physics Package, or is it possible to get it by itself?
Because it doesn't appear to be in the package manager
@sick summit see https://forum.unity.com/threads/visibility-changes-for-preview-packages-in-2020-1.910880/
this link needs to be added to the pins IMHO
I dont think I fully understand the dependency argument in .Schedule(Dependency). It doesn't seem to be waiting until the dependency has completed before operating on the subsequent job. but maybe thats just because Im observing it incorrectly..
depends what "Dependency" is, you probably have to use JobHandle.CombineDependency if you're scheduling more than one.
ahh no now i remember, theyre supposed to return the combined dependency when scheduled
Show the scheduling code
does anyone know if it is possible to have a build be both client and server?
@shy pilot Yes you can. Don't define UNITY_CLIENT or UNITY_SERVER
@fair flame where would those be defined?
Project settings > player > other settings > script compilation > scripting define symbols
ah
thanks
:)
so just to be clear, will this still work?
removing the #ifs obviously
at runtime how do i choose?
Without the #ifs they will both run, you should pull the functionality out into seperate systems if you want to choose between them
ok :)
that's the init code though
so could i just get away with putting an if statement there with runtime variables instead of define ones?
Yes but make sure you have these runtime vars set by the time this system runs. If you're using the netcode getting started code then this system runs on the first frame after the world is created. If you want to choose client server options from a menu you may want to defer world creation or change the conditions to make this system run until that choice is made
forgive me i'm new with this, how does one defer world creation?
Create a class inheriting from ClientServerBootstrap. Take a look at ClientServerBootstrap.Initialize() to see the default behaviour and then override this so it skips creating client and server worlds. Then create your own systems to create these worlds when it's appropriate
ok thanks Tom :D
Is there an ConvertGameObjectHierarchy equivalent for Scriptable Objects?
@pulsar jay nope. I'm also not sure a generic engine level conversion makes complete sense for that. You likely want a mix of Blob & runtime data/icds. I think someone did make some systems for converting them for their own purposes that you could try and find on the forums if interested.
The conversion system as it is is already pretty flexible though. It should work to create the map entities when converting a Map Scriptable Object. The only caveat is that there is now method taking anything else than a GameObject. Will have a look at the forum
I'm saying you very often wouldn't want a SO to be converted to an entity as SOs often contain immutable data.
Picking up an old project and realising I dropped it because the physics library just tanked my performance. Guess it's time to test and see if i can get away with chunking up the world and disabling physics on entities when not needed.
https://forum.unity.com/threads/bugfix-for-entitydebugger-com-unity-entities-0-14-0-preview-19.983730/#post-6393394
I think the next version of entities has already branched-off
more crumbs™️
How can I use an animator component on an entity?
I need to access that animator and have the entity play animations from a blend tree (using setfloat and setbool)
I cannot use custom animations by code as they are complex animations like moving a foot in a 2d sprite
any solution or tip?
you can use AddComponentObject(theEntity, myAnimatorAttachedToSomeGO);
Yes, but then how do I access that component and use for example a setbool in the entity? since when I add the component and when referring to that component, it does not modify the component of the entity, it modifies the component of the go
you understand me=
?
Well in a ForEach statement, you can access the animator like so:
// Important to call WithoutBurst and Run since the animator is not thread friendly.
Entities.ForEach((Animator anim) => {
anim.SetBool("someParamName", true);
}).WithoutBurst().Run();
let me try but normally when I access that animator component I am actually accessing the gameobject
The operator '.' cannot be applied to operand of type 'void'
in the "withoutBrust()"
and if I do it without that, the same thing happens to me as before, which is that I access the animator of the gameobject and not the entity
So maybe im not getting the setup
You have an animator on an entity or a gameObject?
in a gameobject (I tested it with a prefab and a gameobject in the scene)
I need that animator to reproduce in the entity, that is to say that the entity is animated
not the go
It appears like this in the entity so that it is referring to an object
Is this gameobject represented as an entity using ConvertAndInject?
not currently but I also tried it and the same thing happens
I also tried using convert and inject on the entity that I want to animate but two sprites appear in the scene and only the go is animated
So I have a similar set up, 2D SpriteRenderer + Animator
yes
currently I'm using hybrid component for the Animator with ConvertAndDestroy - but before that I was using ConvertAndInject
You're not using subscenes right?
I'm not sure but I don't think so
Maybe I am not explaining myself correctly ... I would like to explain how I have done it ... mmm
I'm not sure if you're using Hybrid Renderer (I also don't know if Hybrid Renderer supports SpriteRenderers)
Well fwiw - I do remember at one point in time I had 2 sprites appearing simultaneously - but i was kind of messing around with a feature in the conversion workflow
I have a go with the convert and destroy script and I have another go with convert and inject but with an animator. To the entity I add the components of the convert and inject go (the animator basically) and I try to access the animator of the entity but the problem is that when adding those components to the entity I am only making a reference to the go that contains the animator then all the parameters that you pass to the animator of the entity are only reproduced in the go and not in the entity
im using hybrid renderer because when im using convert and destroy the sprite renderer dont add to the entity
So the sprite might be rendering twice for the ConvertAndInject due to the HybridRenderer & your SpriteRenderer (so it's rendering twice effectively)
Speaking of hybrid, Is it possible to destroy a CompanionLink created by the gameobject conversion? I tried destroying the gameobject but the link sticks around and continues to try to update the GO transform
So I still haven't touched the Hybrid Renderer (most of my stuff just ends up using Graphics.DrawMesh) - so animation support in the HybridRenderer is likely not existent, so it's likely a good idea to excludethe SpriteRenderer from being a rendered entity
So how do I render an entity with a sprite renderer?
the CompanionLink component is internal so I am not sure if I can remove it manually
So how do I render an entity with a sprite renderer?
@buoyant willow Or more simply, how do I animate an entity using animator?
I need to push the animator component to an entity and control it so that the entity responds to those animator actions
So the animator will only effect a GameObject, so I think the best way is to ensure that the SpriteRenderer entity
is not converted into a RenderMesh entity (maybe through a GameObjectConversionSystem you can try to remove all of the RenderMesh components before it finishes converting)
the CompanionLink component is internal so I am not sure if I can remove it manually
@keen spruce So I remember fiddling with this sometime ago, and I ended up using a AssemblyDefinitionReference so I can access the internal structs.
Any advice on how to remove those rendermesh?
You can probably write a system in that asmdef reference to remove the CompanionLink @keen spruce
that's good to know, I might try that..
Any advice on how to remove those rendermesh?
@buoyant willow Maybe you can set the full entity archetype directly in one of yourIConvertGameObjectToEntity, a GameObjectConversionSystem might work to try and remove the RenderMesh as the last step before it's fully converted, or remove the Hybrid Renderer package if you don't need it. I'm not sure if there are other ways, maybe someone in this discord knows of a way since I haven't touched the HybridRenderer in a while.
and can I render an entity without hybrid renderer?
Well you would be relying on the SpriteRenderer to render the sprite
I use hybrid renderer because otherwise my entity is invisible but is there a way to use sprite renderer on the entity?
when I do the conversion sprite renderer is not added to the entity
the only way I know of currently is to use ConvertAndInject/ or use conversionSystem.AddHybridComponent(component) <- this will still make your rely on a GameObject tho
otherwise, you could try and write your own rendering system (this is what I do with projectiles for my stuff)
the problem is that I need to animate the entity and not the gameobject and I think that if I use convert and inject I still depend on the gameobject so only the gameobject will be animated
if you use the subscene conversion you will get a reference to the spriterenderer on the entity along with a CompanionLink that links to the GameObject
Animator support for pure entity is pretty much non existent to my knowledge (there's an animation job package but I can't speak about that and its limitations since I never tried it before)
and can I somehow set a sprite sequence to reproduce in an entity?
Well a sprite sequence is just pretty much an array of textures, so you just need to update the material's texture to play the animation - so it's likely something custom if that fits your needs
ok i will try to render using sprite renderer on the entity although i am not sure how to do it but i will try haha
I added a sprite renderer to the entity and removed hybrid renderer and the unit is simply invisible
You will have to convert the object within a subscene
forgive my ignorance but what is a subscene? 😅
create a gameobject in your main scene and add a subscene script
then create a second scene to hold your converted objects and reference it in the subscene component
I forget if you need the DOTS Editor package for subscenes
ok, because they are giving me terms that I don't understand, I'm going to study them and when I have an idea of what they tell me about the subscenes and if I need something, ask again. Thank you very much for your attention, I appreciate your time.
I am now wondering about netcode...Anyone know if its possible to have different ghost prefabs on client and server representing the same set of ghost components that is to say the server spawns ServerPrefab and the client uses a ClientPrefab representation
I kind of just use the scriptable build pipelines and load different configurations based on the type (although Im just using the transport layer and not the netcode package)
so I'll have like different scenes with subscenes in them for client representation and server representation
I will have to experiment. I think netcode is still a bit immature for now but I like where its going
Hi is this the place to ask about Project Tiny? I've got a project coming up that is a mobile-first web game. I wonder if someone with some experience could advise on the risk and shortcomings of using Project Tiny right now.
cc @zenith wyvern (sorry for the ping, I saw you mentioned it recently) ☝🏻
It's extremely extremely early alpha. Very unfinished. I wouldn't even think of using it in production.
Promising future, but not very usable right now
Unity3D web build doesnt' seem to support mobile either.
At least by default it will pop up a warning saying so.
So I guess we'll have to look into a JS solution.
Does anyone know a reason why my systems don't initialise with a custom bootstrap?
@shy pilot are the systems running?
Any idea how to disable an entity together with its children (or linked entities)?
Does anyone know a reason why my systems don't initialise with a custom bootstrap?
@shy pilot show code
The fun of optimising DOTs code, I think I need some more frames.
Only 100,000 entities currently
@loud matrix 100k entities doing what? 😄
looking pretty and deciding if they're needing to have a mesh currently. I'm doing some load tests to see how far I can push the physics engine.
When I added physics to my last project even with very little going on it tanked performance.
So i need to execute some action once a bool was changed from false to true... this happens in another system, so i dont have direct acess to the last value. Someone suggested using a filter on the query to determine changed entities, which did not work properly... How would you deal with that ? Would you simply track the history of that variable and check if it differs from the last frame ? Or are there other ways ?
Sounds like something I'd just use an event for
@loud matrix Hmmm... that sounds interessting. Could you describe this a bit more detailed ?
✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=fkJ-7pqnRGo
Let's learn 2 ways we can handle Events in Unity DOTS! The final class is included in the Project Files.
Unity DOTS / ECS Tutorials
https://www.youtube.com/playlist?list=PLzDRvYVwl53s...
@loud matrix I know what events are, i just mean... how do we wire them ? Should the system changing the variable every frame fire events ?
When you change bool from false to true in system A just invoke the event then
or when ever you change the value of bool fire the event with a payload of the new value
@stone osprey filters work on the chunk level, not entity level. imo either store the last state of the bool on an entity rather than introduce an event system and corresponding timing issues. Depends on details ofc
Well its part of my condition system... Theres a component "Condition{ boolArray }" that gets cleared on the start of the frame and other systems validate conditions and put in the value... for example true/false. I actually just wanna execute some action when the condition was false last frame and this frame its true. As @amber flicker said chunk filters are a bit tricky because they listen to "read" acess... not actually checking if a value really changed.
@amber flicker So you mean i should simply track the history ? That would be pretty simply... not that sure about performance
compared to creating entities or using nativequeues.. .adding one bool to an entity is not going to be profile-able
you can also use a flag enum when you start entering this semi-stateful territory. E.g. enum ConditionState { Invalid, BecameActive, Active } or whatever
@amber flicker Well its a list of bools, but i guess that wont have such a huge impact either ^^ The enum is also a good idea, thanks. Such a pitty that theres no inbuild way to listen for such changes. But probably thats also a feature nearly no one would use.
honestly the above all sounds a little unusual.. I rarely find myself with a list of bools. If every item in the list needs to track it's own previous state then by definition they need to store state more than 0/1. So I'd probably turn them into enums as mentioned.
Its a system recommended by several people in the gamedev stackexchange. Its used for stuff like spawners that can have several conditions. Multiple systems validate those conditions and pass their bool value into the spawners conditions list. When all conditions are true, the spawner gets triggered. Pretty flexible with adding/removing conditions. My case with listening to value changes of those conditions refer to sending network packets ^^ But the same mechanic is also used for other condition related stuff... thats why i dont wanna send packets every frame, just when the bool value changes from false to true
There are a couple of things you just mentioned that cause me to 🤨 but I think rather than going down that rabbit hole I will remind myself there are many ways to skin a cat and wish you best of luck!
@amber flicker Thanks, but may i ask what causes you to "🤨 "... i can only learn trough mistakes. Probably im wrong with this architecture. What are your thoughts ?
I encounter more and more cases where I feel I need more control over my queries. E.g. find all unique SharedComponents whose entities also have another component
is it possible to get all unique shared components in a query? Same as query.ToComponentDataArray but query.ToSharedComponentDataArray?
@stone osprey I don't know if you're using netcode etc - I'd expect there to already be a method for spawning ghosts if you were. If you're not, I don't think firing an event off the event that leads to the spawn is a good idea - I'd probably have a tag on the entity with a system that reacts appropriately. I don't know the details of your project though so it's mostly speculation on my part.
@pulsar jay working with shared components is generally a bit not great - you can't use jobs or burst I think right? Is there somewhere better to store the data I wonder?
@amber flicker jobs are somewhat limited. As the sharedcomponents are per chunk you can start a job for each chunk an pass the specific sharedcomponent into the job
@pulsar jay is that the only benefit for you? maybe you could use a ChunkComponent instead if you're not needing the chunk segmentation properties.
It works pretty well for my grid cells. I start a job for each GridSharedComponent and align the cell entities to each grid
@amber flicker No, im using "SmartFoxsServer"... Im not firing an event off an event ^^ atleast if you mean entity/class/method events. Those systems do run after each other and simply fill in the conditions, in this case theres no need for events, its actually like you described. "Entity(Spawner, OnDayCondition, DesertCondition, ConditionResults)" -> OnDayConditionSystem, DesertConditionSystem writing into ConditionResults.
if you have a grid and data in ISCD's, to me that sounds like not a great idea - I'm guessing there will be times when some cells need to know data from other cells or some systems need to know data from multiple cells
@amber flicker thats why I was thinking about an aditional lookup structure if you remember
it works great for positioning and for looking up the cell position from a clicked entity
but cell position -> tile entity works not so great
@stone osprey ok cool - like I say, I don't know the details and I'm not familiar with SmartFoxsServer - I'd expect an entity to 'exist' thus needs spawning - rather than send a 'spawn' event across the network.
@mint iron if I understand them correctly I think SC is better suited than CC because the cell entities of one grid might span multiple chunks and should be grouped together
@pulsar jay sorry I think I forgot already 😄 - ISCDs make accessing a specific tile really easy... they're basically detrimental in every other respect. I'd be exploring the way Topher was talking about.
yeah, personally i haven't tried SC because all i heard was that it was a nightmare for performance. 😛
the one thing good about 'cells' from DOD perspective if you have all this data with the same pattern that you can iterate over (linear memory access pov). ISCDs deliberately destroy that 😅
if its a uniform grid then theres nothing wrong with a lookup structure to entity imo
@pulsar jay sorry I think I forgot already 😄 - ISCDs make accessing a specific tile really easy... they're basically detrimental in every other respect. I'd be exploring the way Topher was talking about.
@amber flicker I will eventually. But for now iterating over a query to find the tile on a cell position is fast enough
if its a uniform grid then theres nothing wrong with a lookup structure to entity imo
@mint iron yeah its not. Its sparse
well.. you're not going to find many helpful api's ... certainly not for doing things the slow way 😄
what was tophers suggestion?
my whole journey with ecs so far was like: If your system would work like this you could easily use that
well you're just a maniac 😛
dots/ecs is certainly very opinionated
@mint iron basically just flat NativeArrays I think
yeah the flat array would be the way to go. but for the sparse grid its not that great
btw @stone osprey maybe you could have a chunk component with a structure of change versions; then it would be easy to update at the site when/if you actually change values.
I worked with a nativehashmap which is great. but it cannot be stored on an entity
UnsafeNativeHashMap can 😄
but you could also just store it in a system somewhere instead of entity
ecs is really great for one dimensional fixed length problems. unfortunately games are usually done in an "infinite" 2-3D world
but you could also just store it in a system somewhere instead of entity
@mint iron yeah thought about that but that would only give me access to the data from this system
I could make it static but that prevents thread safety etc.
ah you may just be missing .GetExistingSystem<>
it would be better if a system would collect them and store them onto an entity so other systems yould use it
ah you may just be missing .GetExistingSystem<>
@amber flicker yeah I know that but it is not really intended for systems to communicate with each other directly is it?
it depends how dirty you feel like getting. i tried putting stuff on singleton and grabbing it from the entity every time i needed it (was actually a 3d grid stored in a dynamic buffer in my case) to ideologically stick to keeping each system independent. But it just created a bunch of crap code scattered about and exposing public stuff in a system ended up cleaner.
dots so far makes me feel pretty dirty 😅
I wouldn't make heavy use of inter-dependency between systems.. but having certain data stored in certain systems can make sense. It's arguably a bit better than static due to the GetOrCreateSystem that declares the dependency and creates it if necessary.
well actually the next step from that was to make GetOrCreateProvider() extension and just have a place specifically designed to be storing data.
thats also one of these "could be's": I could use singletons if there was only one grid
Better singletons feel like ultimately a better place for this stuff... I think?
well actually the next step from that was to make GetOrCreateProvider() extension and just have a place specifically designed to be storing data.
@mint iron is this part of the dots api or your own custom solution?
just custom stuff... somethign like this, not sure if this was the final version. https://hatebin.com/abycodpfhd
unsafe AND generics 🙂 - someone's feeling brave
At least some content has appeared on the forums on generics recently... though I'm gunna have to read it another 100 times before I fully understand https://forum.unity.com/threads/scheduling-100s-of-jobs-just-for-one-gameplay-system-could-it-eventually-become-a-valid-approach.882187/#post-6395012
oh wow that looks like a deep rabid hole...
just custom stuff... somethign like this, not sure if this was the final version. https://hatebin.com/abycodpfhd
@mint iron thx for the example will think about it
I believe the rules for bursted generics are not yet fully understood by everyone on the DOTS team 😬 🤣 - makes me feel a little better at least
the guys solution looks a lot like this from 2 years ago... https://github.com/jeffvella/UnityBurstFunctions
what's generally the earliest point in a frame i can schedule some jobs in?
I think there's an InitializeSystemGroup or similar that runs before SimulationGroup
ahhh, currently not using entities, so i dont think i'll have that to hook into
PlayerLoop stuff might help me create such a hook point, seems a bit complicated tho
update/lateupdate however would work fine i think.
just was wondering
it schedules as soon as you call .schedule - just like any other code, you can put that at any point in the frame pretty much.
yup, was wondering if there was a point in the frame before update that i could schedule in
the results of the job are used in an animationjob so i was wondering if i could schedule even earlier than that
it's a monobehaviour question really but there's PreUpdate() I believe.. possibly? I've never used it & docs look empty
animation loop runs after update
that does look like PlayerLoop stuff
i'll take a look sometime, cheers
otherwise all the usual things - script execution order, statics etc
final note - sounds like it's all main thread code anyway but if you're animation job depends on another job, usually that's where you'd use the dependency system to explicitly declare such and then the 2nd job would be sure to run after the other
yup ive already set that up
my only concern was that since i do that in Update
and the anim loop executes right after
theres not much time in between
to let the background workers mull over the 1st job
hmm.. they don't mull so much as "do it as fast as possible" - i.e. the jobs won't be lower priority just because you need the result later. Would recommend checking out the timeline view in the profiler if not already familiar. You should get errors if you're doing anything unsafe like stuff not being ready in time.
yup, i really should be doing profiling before thinking of all this
thanks!
i was just wondering only if i could get the jobs to run longer in the background before being Completed by the animation loop (since i declared it as dependency)
spread it out more i guess
imo the easiest way to achieve that is to control how much data is processed each frame. I completely understand the concept of limiting by time is appealing (and was quite doable with coroutines in the past).. but with parallel work, it's just much easier to do it by quantity of data processed.
i could try limiting on the main thread i guess, to like 30fps. animation work would not require too much resolution beyond that i suppose
I don't know what kind of thing you're working on but if you can put up with 1 frame delay, you can have a job take most of frame if you like. If you're not using Systems though, controlling this scheduling might be tricky.
what do you mean by that? curious
isnt it possible for Systems to scedule jobs from systems over multiple frames? Now that there is a fixedupdate group it should be possible somehow
ECS will try to force complete on every job from every system its aware of at the start of each frame. So the way to do that is to use a normal IJob/IJobChunk and keep it outside of the ECS dependency system. Since burst is its own stand-alone thing you can schedule things outside of the awareness of ECS, and then they'll just run for however long it takes to complete. But you'd have to be careful because they complete all these jobs each frame for a reason, to enforce safety on data access and structural changes.
Its not the start of the frame right? But the start of the system that scheduled it
And only if you use the SystemBase
yeah you're probably right, i don't have the source in front of me at the moment.
AFAIK what happens on SystemBase is something like that:
// The Dependency property that you have access to
protected JobHandle Dependency;
private JobHandle _lastFrameDependency;
private void OnUpdateInternal()
{
_lastFrameDependency.Complete();
// user defined OnUpdate
OnUpdate();
_lastFrameDependency = Dependency;
}
So, yeah, you can create System that schedule job to run over multiple frames, but you need to handle the JobHandle manually (not trough Dependency property)
Hey guys, I have one questions which might be raised alraedy several times. What is you approach for player related systems. What I mean if you have several systems which have to check something like the players position. Do you have a system early which retrieves that information and you pass this somehow to the other systems? Or do you query in every system where you need it the player or even player entites again?
IMO you should avoid passing things between systems if you can. Keep the system self contained and query for what it needs
Not always possible but it's the way to go I think
Even if that would mean that several systems needs to do _playerEntityQuery.ToEntityArray() or maybe .ToComponentDataArray<Translation>() before the actual Entities.ForEach?
share the data via a component on the player and then let the systems read that component via a player query
you can use ComponentDataFromEntity to access it
If your player entity doesn't change during the game you can store the entity reference and use GetComponent like baron says
Sure or the GetComponent from SystemBase. But for that I need at least to know the entity of a player. So I need to query the playerEntityQuery.ToEntityArray again and again?
If it does change then yeah you would have to query it every time
Yeah just cache the reference
Hah, never thought about that but you are right. At least when the player is really fixed and never get's deleted I can cache the entity and even the component itself, I guess.
Maybe even a check if cachedEntity == Entity.Null would be cheaper before querying all the time.
You can't cache the component since it's a value type
You would never see it change
True, I can not cache a ref to a component. But at least the entity. And then reduce it to GetComponent.
Yup
@pulsar jay, @frosty siren sorry, went to bed 😆
This is my bootstrap, Host() and Join() are called from onsceneloaded in the proper game scene.
thanks in advance :)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@shy pilot CreateClientWorld and CreateServerWorld should be passed the default world as the first argument, not a new world like you're currently doing (ie. Use World.DefaultGameObjectInjectionWorld)
ah, thanks @fair flame i'll try that now
ok, i've made the changes you suggested and the default systems seem to be working properly
but my systems aren't appearing
So the default systems appear in the network worlds but not your custom systems? Mind posting one of these systems?
sure
https://pastebin.com/cDiwEkwf
Most of my code (currently just an unfinished lobby) is based off the cube sample
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i've had to do some janky stuff with entityqueries to get around not being able to have nested foreaches
I can't spot anything there but I think it might be due to how you are calling your Host and Join methods. I suspect you're creating a new instance of your bootstrapper maybe? Either way I'm just calling the create world static functions from the base ClientServerBootstrap class and that works for me
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
thanks, i'll have a look at it
@fair flame do worlds persist across scene loads?
Yes
ok, your paste confuses me slightly, do you have the networking join/host code in separate systems, if so what is the purpose of LevelLoadSystem?
i.e what is the difference between
_levelLoadSystem.LoadLevel(LevelSceneName);
_levelLoadSystem.OnLevelLoaded += () =>
}
World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<InitializeServerSystem>().StartInitialization();
};
and
SceneManager(LevelSceneName);
SceneManager.sceneLoaded += (Scene scene, LoadSceneMode mode) =>
}
World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<InitializeServerSystem>().StartInitialization();
};
@fair flame
why route everything through a system?
I think they are the same but I'm not in front of my computer anymore, I'll double check for you later. I think it's probably just that I wasn't aware of the SceneManager.sceneLoaded delegate. I have the server and client init systems separate in their own worlds and join/host call these as appropriate
thanks, i assume your join/host functions inside the initialization systems are simmilar to what can be found in the Game system of the sample?
oops systems not components :P
Yeah essentially identical but they run from the network worlds themselves and have configurable addresses/ports
so they are in HostClientWorld/ServerClientWorld and HostServerWorld?
@shy pilot I just checked and actually my init systems are running from the default world and looping through all worlds to find the relevant network world just like the sample. My level load system doesn't do anything special it just tracks loading progress and alerts my 'go in game' system when loading is complete
I feel dirty, My project was 100% ECS outside of a bootstrap, but i just can;t get Unity Physics working in pure ECS without using unsafe pointers. Had to swap to loading prefabs and converting to entities.
Just refactoring some game state logic, and I'm pondering using SingletonComponents to denote the stage of the pregame-game-summary cycle, which would then imply making almost-duplicate systems where I want slightly different behaviour in the various states.
I think the performance is essentially irrelevant (though I'm always keen to know about that...), but in terms of tidiness and maintainability, what do you guys prefer, more systems filtered by presence of a component versus slightly different logic within a system dependent on data stored within a component?
Many hours spent testing the physics engine in ECS, but when try it in build to see the performance and it crashes on load at 1000 entities. This really is not looking amazing.
@wary anchor Depends on what you're implementing I guess. I'm currently playing with physics so an example is I'd rather have one system check entities and see if they need collisions and add a tag, and another system to act on that tag than have that acting system also handle the checking. The issue I usually end up with is the semantics of naming folders and folder structure in general.
Currently I have a GameState with some bools in, but this just doesn't feel right. I'd rather have the filtering done earlier than that, but it does mean a few more systems. TBH it's probably overkill even thinking about it, given my game is entirely GPU bound anyway
@loud matrix just fyi the 1000 number sounds suspiciously like it's what happens when you get beyond 1 chunk and have something unsafe happening with jobs or smth
it crashed with 1 too, no idea where the issue has cropped up, trying to rip out code section by section to find what's causing it. Had 100,000 fine yesterday before swapping to prefabs that convert themselves.
I don't suppose anyone knows how I manually add Unity Physics to a project, its not showing in the package manager?
I'd guess hit the plus, add via the git option, type com.unity.physics (or use the pinned ref to find package name) then hit enter
What version of Unity are you on? in 2020 I think they changed how you access the preview packages.
I'd rather have one system check entities and see if they need collisions and add a tag, and another system to act on that tag
This, because you can work on all the detection mechanisms without having to implement the rest of it; or add/remove/disable game mechanics that work from it without breaking your game because its decoupled.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public class Bootstrap : MonoBehaviour, IDeclareReferencedPrefabs, IConvertGameObjectToEntity
{
public GameObject prefabGameObject;
public static Entity prefabEntity;
public void Convert(Entity entity, EntityManager entityManager, GameObjectConversionSystem conversionSystem)
{
Entity prefabEntity = conversionSystem.GetPrimaryEntity(prefabGameObject);
Bootstrap.prefabEntity = prefabEntity;
}
public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
{
referencedPrefabs.Add(prefabGameObject);
}
}
Anyone have any idea why this works fine in editor but just crashes on build?
you have jobs debugger enabled in editor just to check and you're doing a debug build? no logs at all?
I have all debugger options on in editor and when i tried a developer build earlier it also crashed in the same way with 0 results (Though I've never done a dev build before so don't really know what I'm looking for.).
any log generated? https://docs.unity3d.com/Manual/LogFiles.html - see Player section if not sure where.
I have the player log but the crash report may as well be in Chinese. https://pastebin.com/QnK85Mjn
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Are you using the latest physics package? Does it even support 2019? I thought everything moved to 2020?
I'm on 0.4.0 as it was the latest I could get to run (with out errors or so i thought till I built)
But it does say its compatible with 2019.3+
I don't see anything in there that would indicate it being the physics package though. What made you point it out?
I saw you were using 2019.4 and was a bit surprised given https://forum.unity.com/threads/moving-dots-to-2020-1.910931/ that's all
I'm surprised the physics is compatible with 2019.3.. great if true
I had not seen that post, bah. Only reason i installed this version was LTS 😛
haha LTS != good for experimental packages
Last time i played with dots it took a few days to get versions that worked together and i had to jump back a good few versions, so I was hesitant to jump at the latest version.
well it's not like I can guarantee a smooth time, just that as that post indicates, you'd be working with a dying versions if you want to do DOTS stuff
I'm not doing a full project at the mo, I'm pretty much just stress testing the physics package as last time I added it to a project it tanked performance. But I'll update to 2020 either way.
https://twitter.com/FickleSwimming/status/1314543107460009984 envious of all that gold
Benchmarking with ECS this time. I can get up to about 200k coins before framerate starts to drop🤔#madewithunity #unity3D #indiedev https://t.co/ttYKYtpIdK
172
I was looking at like 100k as a stupidly high end with a 1-2k non dynamic and allowing for some low quality low density boids. But damn I'm envious of 200k
caveat - the above is with some custom physics rather than unity.physics - looks like they were previously using havok but were having issues - i.e. not indicative of unity.physics performance
I've been considering just throwing out the idea of nice mesh colliders and cobbling some cubes together on my entities and using that for basic collision. It's a space game so i don't need gravity or friction or anything fancy.
spheres ftw
https://twitter.com/tweetweasel/status/1302652943502540801 My art style does not know what "spheres" is
Tried out the @MortMort_ #Blender pixel art modeling methodology from here https://t.co/RG4vJBWGSj Had to manually unwrap in the end, but have to say his setup and workflow works really well.
#lowpoly #pixelart #gamedev https://t.co/65y28h530m
ooooh, hey thats pretty!
yeah I figured sphere colliders would best for anything 🤔
yea, if a sphere doesn't cut it, use more of them 🙂 (mostly a joke)
how long does that sort of work take, @loud matrix ? compared to, I dont know, 2d pixel art and 3d modelling
Current plan is push Unity.Physics to breaking point, then I can look at deactivating the physics based on chunking up the world (which sucks as last time i played physics does not like someone else moving the entities so mixing and matching movement would suck). If that doesn;t go well just make my own basic collision based off basic shapes instead of meshes.
@tight blade With that one I was using someone else's methodology to see how it worked out. Was much more accurate than my usual and faster, while playing that was about 3 hours including setup and rendering.
Would probably only take me 1 normally now
there are a lot of gotchas with unity.physics. Ive been neck deep in them for a while. keep me updated/@ me with questions
like make sure you remove the collider components from the gameobjects, knowing which of the 3 physics systems to insert your code before or after, where the inverse world matrix gets calculated, etc
its all weird
once you get passed the gotchas, unity physics is happy to let you push things around etc
Getting it working wasn;t too hard, though I was never able to do it with pure ECS without unsafe and pointers for the mass, which annoyed me as I know its not needed as convert to entity works fine.
lol. unsafe is pure ECS
ECS if and only if unsafe.
@mint iron baptized me early on in the fires of direct memory access.
but seriously, ECS relies a lot on understanding multithreaded performance, so at some level you kind of have to know what's going to interfere with the memory access of other jobs, because if you dont, Unity's errors arent going to make any sense
and if you understand it, well, no reason not to use it
I'm at the top of the Dunning Kruger ECS graph. I know how to make stuff work, but I also know I'm doing it wrong and shouldn;t touch anything becus it will break.
only one way down that ladder -- go break stuff
That's why I'm here after failing to get a single entity working in build today, can't get much more broke than that heh
au contraire
Well I also did crash Unity as a whole 5 times aswell.
lol, the other day I got into a state where whenever I entered play mode, the scene view buttons stopped working
And totally froze my machine on one of those
wait wait
theres literally nothing you could do with direct memory access that would brick your computer. worst case scenario, youre fine after a rebbot
its memory, its cleared on reboot anyway
I don't think it as memory related, reboot did fix though.
I almost created infinite folders in my hard drive a little while ago 
luckily it crashed before it completely filled my hard drive
Combine it with a zip bomb and you can wreck someone's machine good with that.
@amber flicker I wonder what kind of logic is behind those coins. there's no way those have simulated physics
yea no idea - all I know is what's in the thread - feel free to ask! likely something simple - they also explain they're moving on to fluid simulation on the gpu - I shared mostly because it's pretty 🙂
Hmm, still can't get this damned thing building even after playing with untiy and package versions, think it;s time to shelve this for now.
I assume an empty scene builds fine?
Yeah, but if i add an empty with my bootstrap code that takes in a game object and and sets up the prefab entity (and convert to entity) it dies.
all other systems have ben removed
Even if I leave the Convert and DeclareReferencedPrefabs methods empty it still dies.
hmm runtime conversion has always been the ugly cousin that might not get support but I wouldn't expect it to crash. Any more luck if you build it with the new build process?
There's a new build process?
it's... undocumented.. you need com.unity.platforms as well as e.g. platforms.windows or something depending on your platform
you then need to create a scriptableobject with the build settings
you need it for subscenes.. not sure if you also need it for runtime conversion
Well my latest test crashes, with a single empty with only convert to entity on it, I might just call it quits for now. I can deal with my code being a dick but 8 hours on failing to build anything is burning me out a tad too fast for comfort.
yea.. know that feeling. If/when you come back to it, things to try: 1) deleting lib directory, 2) ensure you're now up to date with all packages in 2020.1 (I'd avoid 2020.2 for the moment), 3) try a new project completely
2 and 3 I have already done, I'll try lib now just in case it works, as the game i was about to play was the one that annoyed me so much i wanted to remake it with ecs... I need some stress to decompress from the stress apparently.
lmao
if you've done a completely fresh project I don't expect clearing library to do anything. Builds are working ok for me in general but I don't use the convert to entity component - anyone here confirm if it works in build?
ConvertToEntity component worked fine in builds for me so far
... (ノಠ益ಠ)ノ彡┻━┻
build successful
So updating unity, totally reinstalling all packages to latest version, nah. Deleting library however, yah. Lets see if this still works with what i was trying to test 5 hours ago.
I'll need to setup my PC to delete library key after it detects me headbutting the desk a certain number of times.
Yup test works fine, Thanks for the help
😅 glad you got there in the end
Now I'll see how badly this performs and start the comparatively easy job of a custom physics engine heh
welcome to the never ending treadmill of, "man this sucks, I'll just do it myself"
is anybody else having a problem where the editor freezes when running ClientServerBootstrap.CreateServerWorld(World.DefaultGameObjectInjectionWorld, "HostServerWorld")?
maybe, I've experienced freezes until I go out of memory since upgrading burst and netcode
has anyone encountered the issue where the hybrid renderer v2 uses quite a bit of time every frame even on almost empty scenes just to update the (empty) batches?
No idea what might be wrong here, first time seeing this.
Has unity said anything about their plans for ECS and the new UI system? I've seen mention of them saying they are to be help at arms length from each other, but the new UI still uses monobhaviours which unity seem to be trying to get rid of.
i really doubt its on high priority 😄
I'm debating trying to use the new UI system and idk, I'm a professional web developer so their idea of CSS does burn every time I see it.
They said dots ui integration is a ways away like a year or so which probably means longer. Imo uitoolkit works decently enough in hybrid though
I've not used ui toolkit so it was a good excuse to use the new one and never touch the old
Would you say it's worth getting into the old then using the new when it' more polished or just start with the new when working with ECS?
imo just use ui toolkit unless you need screenspace ui
using a gameobject for every gui layout piece just feels dirty as hell
I don't even know what you mean by screenspace ui, so I'll go with no
oh sorry i meant world space not screenspace
but: think like a healthbar on a unit, worldspace ui which isnt yet supported but coming probably next year
Ahh, I will be needing that eventually, but I think i cna work around that easily enough
playing around with fps space game so a need some form of hud, but it's not exactly going to be over the unit in world space
screenspace ui for menu elements/hud works
I mean, if a UI system did not support screen space coordinates, I'd be worried. Unless it was specifically for XR or something, for which screen space isn't really helpful
is anyone else immensely confused by the dots animation package??
what de fugg is dis :DD
the hardest of all the aspects of dots, it has yet to click for me unlike netcode and other stuff. i can't make sense of it
I guess they are still experimenting with the design for that one 😦
I mean there is a reason they are hiding preview packages like entities away
and especially for animation in dots, it makes sense to wait... this is no easy topic and hard to get right for the majority of use cases. And even harder to support an easy to use workflow for existing animation tools
I say it will take at least another year if not two until we get proper integration. Right now it still has the ducktape and gum feeling to it.
For dots as a whole.
nice for playing around but stay the heck away from it for production purposes.
I'm very unfamiliar with DOTS, so forgive me if this is a dumb question. Why would I want to convert a prefab to an entity and then instantiate the entity, and not simply slap the Convert to Entity script on it?
You do not instantiate entities. An entity is literally just a container
The whole conversion workflow is in my opinion an antipattern for data oriented design.
because in proper data oriented design you rarely operate on very specific entities but on a set of entities that fulfill certain requirements.
@sick summit you don't. you want to instantiate an entity in any case where you would instantiate a gameobject
think about it like this @sick summit instead of saying "hit the player for 5 damage" you:
Query for an entity with a player component, a health component and a takedamage component. And then set that takedamage components damage value to 5 which then triggers a damage system to reduce the damage value to 0 and reduce the hp components hp value by 5
The idea in data oriented design is that you generalize so you are able to compose
@gusty comet i think you have it the opposite way round. an object is a container. an entity is literally just a number
nice for playing around but stay the heck away from it for production purposes.
@gusty comet it is still very rough around the edges, but if you take it wherever possible and your design allows it, the performance improvements and especially CPU usage per frame is noticeable and depending on your application/game critical
I am not denying its benefits. What I am saying is that its too much in flux to use in a production enviroment.
If you are a hobbyist then yeah fine but I would not risk money and jobs to be "on the edge"
we are deploying first mvp versions in ~2 months and rely on ECS to hit target performance for very low end machines, as the old monobehaviour cpu usage was just too high and hard to improve
