#archived-dots
1 messages Β· Page 160 of 1
which isn't really an engine but still
and not sure how monobehaviours compare with unreal actors/components, but I didn't think they are slow in comparison
unreal is designed with OOP in mind so it prob won't ever be as fast as DOD
ECS in unity does have some big advantages.
It seems confusing at first, but imagine it has been around for 10 years how easy the tutorials will be to follow, etc.
Because, unlike monobehaviour coding, ECS basically prescribes a software architecture, and is compartmentalized. That means a lot more people are doing things a similar way.
And tutorials don't really need to interact with other systems rather than they are concerned with, making them clear and concise. Very plug and play.
For me, the hardest part of ECS is definitely just the lack of documentation/examples - but once it has those, I think it'll really take off.
With a monobehaviour the tutorial may work with your current games structure, with an ECS tutorial it almost always will.
entities 0.13 and hybrid renderer 0.7 is up π
nah, I doubt they'll change much
vblanco mentioned unreal was working on their own ecs implementation though by the sounds of it too early to show(although with unitys recent decision are we still at that stage with dots? π )
and the other thing is that unity also compiles down to c++ with il2cpp, so I'm not sure if it is that slow, but I don't have a good comparison,
but also appears to me that if there are performance issues in unity, they are often not that hard to tackle, things like batching etc., or making your own managers for handling a ton of individual objects
lmao ECS is definitely too early to show
I have a feeling they may not do this again
Like release something this experimental again
it is also incredible what unity does to handle data and chunks in the background for fast access/cache coherency
Because I think ECS developed a reputation as "extremely difficult to learn" that has really hurt their efforts
when realistically when it's finished it will be "not that bad to learn".
problem with il2cpp is it literally doesn't do any optimizations at all, it's just trying to 1:1 copy your C# output
wait, Entities 0.13 ? 
the latest docs is .11 https://docs.unity3d.com/Packages/com.unity.entities@0.11/changelog/CHANGELOG.html
and unity's implementation of mono compiler produces really slow code in comparison to other C++ compilers or .net core
So for the average person they're looking between unity and unreal and being like "well, Unity is moving to a new programming paradigm that is really difficult, and I'm an OO programmer so I'll just go with unreal"
I think while it is harder, it wouldn't be that difficult to learn if the resources for it are better, but at the moment, you often have to go through forums to find certain information, the api still changes.
and people here in this channel are super helpful too with it ^^
yeah they do it like that sometimes Torsina
that's why burst is needed
ah interesting, didn't know that for il2cpp
GameFoundation package was like that as well, 0.4 to 0.6
Because I would be concerned they didn't do good job at their keynotes demonstrating that Monobehaviours will still be supported alongside ECS for the forseeable future
@opaque ledge is there any place where we can see the changelogs ?
is it reasonable to assume that there might be performance increases when unity switches to net 5?
yeah, from local file
is it reasonable to assume that there might be performance increases when unity switches to net 5?
yes
very
Library/PackageCache/Entities/Changlog
awesome
original reason for il2cpp was to make unity run on systems that couldn't run mono, performance wasn't really a concern at first at least
ah, afaik for most platforms you still need il2cpp
like consoles and I think mobile too?
like consoles and I think mobile too?
I think for ios only
android can run mono afaik
@minor sluice yeah you nailed it, for someone newer to programming like me the biggest killer in learning ECS is the constant changes to the API and best practices.
It's like... imagine you don't know what you're doing... and then it changes. π€·ββοΈ
Hahahah
for example, now with 2020.1, they remove a few api approaches again, you don't have ForEach jobs anymore it seems, all is done through entity ForEach queries, but that also makes a lot of libraries unusable, even if the upgrade is easy to do
What API change exactly tho ? i have been developing with ECS for 7-8 months now, and the first system i wrote it still works (only updated to SystemBase but wouldnt matter, it would still work)
but I'm glad that unity informs us what is obsolete through docs and intellisense shows that
Oh shit, mine is still all in foreach jobs and I'm on 2020.1 π
oh, they still work? π€
interesting, because I get this
IJobForEach is deprecated but its still usable i think, no ?
Wait, are the entity queries replacing the for each loops??
I hate so much that you can't even see dependency packages in 2020.1 --'
but thats just green warning, not an actual error π
being marked as obsolete doesn't mean it doesn't work.
it would still work if you use IJobForEach
ohh IJobForEach is being depricated, not Entities.forEach, gotcha
@zinc plinth its a setting of package manager now
now the entities foreach queries are easy to write, but they are not that verbose for me,
like, how are local variables in the OnUpdate passed for burst compiled jobs,
i can still access them in foreach, I have no idea what happens under the hood
I hate so much that you can't even see dependency packages in 2020.1 --'
@zinc plinth you still can
isnt Entities.ForEeach just Entity Query + IJobForEach under the hood?
0.12 patch notes above 2000 characters π
Entities.ForEach is IJobChunk under the hood
and i believe EntityQuery is still being used in ForEach->IJobChunk, tho i am not entirely sure
Updated minimum Unity Editor version to 2020.1.0b15 (40d9420e7de8) talk about bleeding edge --'
Are entity queries a new thing, an old, thing, and are they sticking around? Hahah
laughs in 2020.1.0b16
I've seen them occasionally across tutorials but am not sure where in the ECS timeline they fit in, if they're coming or going
entity queries are an old thing. and they will be sticking around
as they're a part of the whole ecs paradigm in general
Ah k, so they've just become obfuscated by some methods that kind of use them in the background or something?
yeah its an old thing, but it still have its uses
VS tells me that entity queries are not deprecated
IJobForEach is the thing that is being deprecated
Ah k, so they've just become obfuscated by some methods that kind of use them in the background or something?
yes
Gotcha.
I liked the IJob syntax though π
that reminds me,
IJobForEach, you could just use an attribute [ChangedFilter] or something and I think the object should only run when unity detected a change with that component?
does anyone know how to implement this with Entites.foreach?
Yeah, .WithChangeFilter<Type>()
obviously the type you write has to be inside ForEach query
ah, thanks a lot
Hmm, shouldn't that just be always used?
Or will it figure out by default if there are no changes for performance
I assume it has some intelligence that makes it speedy
it's so unintuitive from a programming standpoint to loop through data repeatedly for "performance", hahaha
I wonder what happens under the hood? is unity changing a flag or a version number for the component on each change?
I think it makes sense to not use it per default, because that wouldn't be expected behaviour for an "update" system
it's so unintuitive from a programming standpoint to loop through data repeatedly for "performance", hahaha
what do you mean?
Oh, I have a question, haven't really came across this in any tutorial yet.
You know in monobehaviours you can run a coroutine and yield wait whatever seconds, what's the ECS equivalent of that? How is something that updates once every 5 seconds performed? Is there a specific method or is it just done with tag manipulation or something (which seems fairly inelegant but would work?)
Normally I just use a flag/bool
and have another system check the time and manipulate that flag
jobs is also now on 0.4
"Added SystemBase.GetBuffer/GetBufferFromEntity that are patched so that they can be used inside of Entities.ForEach." \o/
so just a component holding a time counter on an entity, and something like if the time is greater than 5 seconds do this and reset to the component to 0?
imo, it's not that cache friendly, since the CPU is smart enough to cache in future instructions.
and having a flag that says, nope! just hurts the whole cache friendly thing.
but the performance hit is very minpr/ miniscule..
What I said may be dumb, I'll figure it out. Just curious if there was a specific way or not, haha.
so just a component holding a time counter on an entity, and something like if the time is greater than 5 seconds do this and reset to the component to 0?
@tardy spoke yup something like that
Yesss. I'm getting slowly smarter.
Awesome, thanks! Appreciate it.
hmmhh, that's an interesting question,
can you maybe also make a system group and have them manually update in a monobehaviour - run the coroutine and just call update on the group or system of the entity manager in there?
that's a huge performance hit
because it is outside the build in system cycle?
maybe having the manual loop in the OnUpdate in your specific system is better then
@tardy spoke btw, if you are doing some time stuff, dont reset time to 0, reset time to minus limit, for example if your limit is 5 seconds and when current time reaches 5.2 seconds, then reset current time to 5.2-5 = 0.2, otherwise you will lose the extra time and get weird behaviours
Gotcha. So then it'll run more predictably every 5 seconds instead of having some possible variance
yeah exactly, i lived that so π
I could also see some problems occurring from the Systems stopping and starting at specific times if they are resetting to zero, if somehow the time on the Component isn't starting at 0 that could be a real tricky bug to squash.
i think if you have a jobsystem, you just return the input jobhandles if you don't perform an update, and if you detect that an update is due, you regularly schedule your job or entities.foreach
oh, I have another question,
how are people usually handling timescale within an ecs world, say if you want to slow the general deltaTime steps down,
do you use a singleton component or something? or a static variable that you read before scheduling a job?
@tardy spoke
here's the example.
public class BulletSpawnSystem : SystemBase
{
protected override void OnUpdate()
{
var delta = Time.DeltaTime;
Entities
.WithNone<Prefab>()
.ForEach((ref GapData gap) =>
{
if (gap.countdown <= 0)
{
gap.active = true;
gap.countdown = gap.timeGap;
}
else
{
gap.countdown -= delta;
gap.active = false;
}
}).Run();
Entities
.WithNone<Prefab>()
.ForEach((/*SomeComponentes*/, in GapData gap) =>
{
if (gap.active)
{
//Do stuff
}
}
}
}
@deft stump thanks! That's a pretty easy to understand and concise way to do it. Just my style, hahah.
Also I haven't done a lerp yet in ECS.
I take it lerps are pretty much done the same way, just in OnUpdate()? Any weird pitfalls to be aware of vs monobehaviours?
lerp as in... lerping between points?
sure, let's just say lerping a position
or a material hue or something
vector1, keep it simple lol
Awesome, I love examples, hahah.
https://www.udemy.com/course/unitydots/ damn.. udemy doesn't list when the courses were published anymore. Pretty sure they used to. Hmm.
public class MovementOnPanelIndexSystem : SystemBase
{
protected override void OnUpdate()
{
Entities
.ForEach((ref Translation translation, in EntitiesToPanelData etp) =>
{
var dataindex = panelData[etp.panelDataIndex];
if (dataindex.index.x == etp.index.x && dataindex.index.y == etp.index.y)
{
translation.Value.x = math.lerp(translation.Value.x, dataindex.coordinates.x, 0.5f);
translation.Value.y = math.lerp(translation.Value.y, 0.60f, 0.5f);
translation.Value.z = math.lerp(translation.Value.z, dataindex.coordinates.y, 0.5f);
}
}).Schedule();
}
}
@tardy spoke this code just lerps between positions indicated in the EntitiesToPanelData ICD.
I know you can make the code shorter, but I just got lazy.
Interesting - I must be missing something, because why does the .forEach not "restart" the LERP each frame causing it to stay in it's initial position? I'm assuming the third argument in math.lerp is the duration of the LERP?
IE 0.5F
yup. that's the duration.
Yeah, I figured that that may have to be extracted out into another System or something to do a LERP, but in your examples it appears that is not the case. Interesting.
what's the difference between using system base and returning nothing with a scheduled job, vs JobSystemBase and return the handle of the scheduled job?
system base job runs without waiting for dependencies to complete?
isn't everything but SystemBase deprecated ?
SystemBase still wait for dependencies to complete
so it is all under the hood? interesting
if you have multiple entities.foreach().schedule() all stacked up in onupdate. Systembase automagically assumes their dependency order.
I feel like having the inputDeps passed and having to return a new handle is more explicit
inputDeps is now Dependency and is a property of the system, you can still have the old functionality of the JobComponentSystem if you desire(and for certain cases you will need to)
oh when did Unity add the FixedStepSimulationSystemGroup
o - i guess I'm 2 versions behind lol
eventually physics will be moved into that group right?
oh nice it actually updates dependencies now even if you have them already in your manifest(unlike before)
I think physics would be moved there - it would be nice to have it such that you woudn't need to manually construct systems that live in a monobehaviour for a fixed time step
ok just read that they do plan to move it there
new hybridrenderer seems to be working much better with the latest package manager universal
example scene renders properly, still limited to one light but at least it doesnt appear glitchy now
Finally got to fully integrate my ability system exploration back into my game π
AoE Heals, AoE Damage, Impact Explosions with Knockback, Damage over Time π₯³
Sorry, had to share π
how are you handling the particle effects?
and its not a significant performance factor?
It's good enough π
One thing I might do is slightly jitter any attacks (like add 5% variance in attack speed/cooldowns), so that they don't all trigger the exact same frame, but instead over 2-3 frames.
Here is an old screenshot with ... 1000 or so particle systems:
anyway looks cool, always wanted to make an ability system like dota2
did entities skip over 0.12 being public? seeing a number of api changes which apparently exist in 0.12 and not 0.13
that's what I was thinking π€
But i thought I had just missed the update since I wasn't actively looking for updates in the package manager, but I did tune in every now and then to check
i committed a bunch of changes without really thinking and then noticed all these little changes that I didnt remember making π
Is this standard practice at all?
I need to reference another entity's location in SystemA.
The Entity is the only one of it's kind, so I'm just writing it's translation values into it's "own" component (that isn't shared with anything else) with SystemB.
Then simply reading that value in with SystemA.
Is that... normal? Haha.
So SystemB -> updates position of Entity X, and SystemA reads the position of Entity X?
I'll clarify, I think I made it more complicated than it is.
Entity X: I have a unique component called MyLocation.
SystemB: I will write Entity X's location to MyLocation component.
SystemA: That's awesome. I shall read that in.
But yes, I believe your understanding is correct!
I'm just trying to think of if one system could do both of those functions or if the two discrete Systems are required.
There is no right or wrong there. Yes, this is a common practice, but do the way that seems more intuitive for you (if you think that splitting between two systems is not giving you anything more than headache, then combine into one and move on)
Yeah, by systems I more meant into one Entities.forEach loop*, but yeah.
Honestly, imo, i'd recommend that approach
if MyLocation is just a Translation you could also just use a unique tag component
with a regular Translation
I think that's what the plan is?
It has a unique tag, is there some fancy way just to grab the translation from that entity from just the tag inside a Entities.forEach?
WithAll
The one thing I do like about the two system approach is although it's pretty verbose it's explicit with easy logic to follow.
Hmm, yeah but if I do WithAll both the trick is if I apply a translation it will affect both entities, correct? Am I missing something?
Because I need to apply the one's translation to the other, haha.
I'm totally fine with the two system solution, but if anyone knows a way that is better practice just let me know. I was just making sure it wasn't a crazy thing to do before implementing it.
Well you can do WithAll<Translation, UniqueTag>() to uniquely get the entity
if it's also a single entity, you can also just grab it by someQuery.GetSingletonEntity() and grab the data on the main thread w/ EntityManager (if it hasn't changed recently GetSingleton and GetSingletonEntity complete read and write jobs from what I remember seeing in the source)
Right! I'll look that up. It'll likely run on the main thread anyway because it's closely tied with the user's input controls, so running a query and getting the entity could be an option. And something cool to try out.
anyway looks cool, always wanted to make an ability system like dota2
@safe lintel Haha yes, now that I have a flexible ability system I can finally put my personal Dota2 experience to work π It's pretty cool how AoE and DoT combine into sooo many possibilities. I.e. Lich Chainfrost can be made as a projectile that launches a projectile on impact. Or Necrophos Death Pulse is a AoE launched projectile.
make your own ability draft game π€© i always loved giving melee characters focus fire
Interesting idea, I AM planning a "Hero" system to spice up the gameplay π
Hey there guys, I have a question regarding level-design when using the DOTS stack.
Since using the ConvertToEntity script is quite slow and causes a large startup delay, the only other way I can think about building the world is by manually creating entities in code.
Is there a more straightforward way of handling level design with the DOTS stack?
Subscenes?
I'm not following, how would subscenes help?
My world is quite small, I'm just talking about the initial GameObject placement. (Terrain, Trees, Houses, Water, etc.)
I've created all of my Components and Systems and I need to start world building so I can test things outside of a plane.
all static environment stuff should probably be subscenes that seems to be Unity's preferred way
Oh, I completely jumped to the wrong assumption of additivescenes.
Whoops.
I'll take a look.
Sure thing, and as for Terrain are there any ways to convert this so it will render and work with Unity Physics?
Or should I just generate the terrain as a model and bring it in.
Not sure if subscenes convert terrain physics, but they will convert most physics colliders etc, into the new unity physics versions that ECS uses
there are physics, its all in beta though so it might be a headache working that all out
so worst case scenario would be bringing it in as a mesh
That's fine, I only need very basic physics anyhow.
I may end up writing a totally different movement system. My prototype was running a server that didn't use DOTS but I've redone the server using DOTS and left the client using traditional Mono as I build for WebGL, the issue there is my client-prediction for PhysX isn't going to work with Unity Physics so I'll probably end up having to redo that entire system
You could look into Havok as well, I think they released something for Unity recently
I'll check it out. I just need to make sure that basic physics work. Can't run through walls. Can jump over flagged walls with certain abilities. Can probably get away with some simple raycasts, just need to test performance.
i just spent far too long debugging an issue, only to find out that we'd gone back to 1999 and/or present day unity when serializers wouldn't handle dictionaries. π
oh yeah I found that out a little while ago, that's why I'm avoiding using them
i know its off topic it just really grinds my gears when i encounter these archaic holdovers and i need to express some rage somewhere. π
no worries I know the feeling
this new visibility changes in the package manager really hurts
ecs physics are really solidly built already, imo wouldn't even guess it was beta if it didn't say
wether it uses good general-purpose design is debatable, it seems to only be good at the use cases unity is targeting, but it does those use cases very well
but i don't think that's going to change in the future since it's baked into the core design
like colliders being immutable shared data instead of being able to just modify any entity's collider easily
if we fast forward like 5 years, im imagining the community coming up with cool stuff to offset the shortcomings in its design
with all the source available
already some really impressive ecs physics stuff demoed outside unity physics so i think its a cool space to watch
So WithDeallocateOnJobCompletion is being replaced by WithDisposeOnCompletion
May I know if ECS is currently production ready and stable? Or I should stick with Monobehavior for now?
no it is not
use it for learning purposes but if you just want to make game stick with monobehaviors
I heard about someone who has an ecs game in production, but I think it is not recommended, you could freeze your unity version and package versions and keep developing with them,
I have no idea about the issues for ecs on different platforms though
yea there is a couple but they also had to basically make their own engine in unity because there's just the basics for ecs atm
which can be fine for some ppl but it's hard to recommend if someone asks about production ready
π
Weeeeeeel, if you experienced programmer, then you can use it easily (I'm not experienced, but anyway using DOTS in production)
ive been keeping an eye on it since day 1 (to hopefully use it on a project)... and i think stuff is still in too bad a state
I mean, you don't have to use it for everything in your game. There's the hybrid approach or you can just use jobs for some heavy tasks.
And the earlier you get into the dots workflow the better your game will be able to compete on the market when it is actually ready for production and everyone starts using it.
For DOTS, do I need any other packages besides com.unity.entities
All required packages will be in dependency. Only thing which require separate install - hybrid renderer.
Entities 0.13 released, with all related packages
Is there a project demonstrating DOTS and unit testing?
@storm ravine is it available in 2019.4 or only the latest alpha?
it's available in the 2020 releases but you have to edit the dependencies manually to get it to appear.
So they've stopped releasing for lts? Are any of the coming dots package updates gonna be supported only on 2020 and higher?
From what I understand, Unity wants to proceed with DOTS as a primary focus moving forward.
I think I have read that for the upcoming packages related to dots, you need to have unity 2020
So like, does Unity with DOTS use components at all on GameObjects? Do GameObjects exist? Looking at the editor with 2020 I still see support for components.
To give you a practical example of what I'm doing, I am doing a tile-based 3D game. A tile contains air with atmospherics. The tiles know their neighbors and on updates they exchange gasses with their neighbors. This isn't all the work of the Tile's component, but other components they are attached to that look for the Tile and then use that to figure out their neighbors.
How would I even approach any of this in DOTS? Where would I even begin rigging this in DOTS?
@gusty comet depends on the number of tiles you have
if the tiles are in the dozens up to hundreds, you would normally do something similar to what you explained. You have one entity per tile, and they have different components for their data
if you are thinking on a full on voxel system where you have hundreds of thousands or more tiles, what you normally would do is to avoid the ECS part to begin with, and write stuff with Native containers + job system
there could be a componentData that stores the neighbor entities, and in a system you execute the exchange,
I think it might even be possible to do this in a job by using ComponentDataFromEntity groups
instead of a gameObject with multiple components, you have entities with different components and component types, but it is likely that those components are smaller and more modular to make efficient use of ecs
it seems (on latest hybrid renderer) that with a DisableRendering tag RenderBoundsUpdateSystem still does some work - are the bounds used for things other than rendering? I guess maybe related to lod stuff?
Hello! Hopping in for another question of mine. Does the JobParallelForBatch support nativeThreadIndex as far as you know?
i haven't used that job type specifically but i think it should work, i think its more tied to the parsing of structs passed in than something job specific.
it's very unfortunate that so much DOTS language overlaps Unity language, especially the ECS Components vs. GameObject Components
How can I install Entities to Unity 2020.1? It's not in the package manager (yes I enabled preview packages), and I also couldn't find anything on google
yup. it gets confusing when you're trying to explain it to someone who wants to learn DOTS but the language barrier just makes it more confusing to them
How can I install Entities to Unity 2020.1? It's not in the package manager (yes I enabled preview packages), and I also couldn't find anything on google
@chilly bobcat for now, unity hid it.
but there is a way.
press the plus icon on the top-left.
then Add package from git URL
then paste this "com.unity.entities"
here's their reasoning for your reference too... https://forum.unity.com/threads/visibility-changes-for-preview-packages-in-2020-1.910880/
Ah thank you!
yo, 2020.1 is out of beta
before 2021! nice! π
in the future, we'll get unity 2022 in 2023
@storm ravine is it available in 2019.4 or only the latest alpha?
@willow plaza 2020.1+. Entities 0.11 was last release on 2019 cycle
I see. Thanks. Do they plan to get out of preview in 2020?
Entities 1.0 was planned to 2020.1 cycle (which can end in the late autumn and even winter)
Isn't 2020.1 out already though? oO
Read again
(which can end in the late autumn and even winter)
2020.1 cycle doesn't mean at 2020.1 release
by 2020.1 cycle you mean versions up to 2020.2?
otherwise I don't understand what a cycle means><
don't suppose anyone here has got livelink to work?
by 2020.1 cycle you mean versions up to 2020.2?
@willow plaza yes
https://ghostbin.co/paste/qp3fx
Here's my code for chemicals in my game I was working on in 2019. These structs are populated with data from an XML file and are referenced by a chemical identifier from scientific database.
I'd like this to be as fast as possible. Everything in the game has to reference chemicals constantly and make determinations about its chemical properties based on temperature. How can I start converting this to ECS?
Can I just pull all this into a component and have entities created for each chemical?
strings can be a bit of pain but otherwise all your data looks blittable so yea, you can put that in an IComponentData etc - if the data is immutable (chemicals that never change) you may be better off creating BlobAssets of the data and having entities ref those
My project's building again with the latest entities+platforms π₯³ - though I'm noticing the exe has frame rate capped at 30fps regardless of vsync & Application.targetFrameRate and with cpu & gpu overhead (60fps+ in editor) - anyone else seen something similar / built with the new pipeline? (cc @craggy orbit aka only person I know who's tried to build their project π¬ )
what would be a good way to have an entity component list reference a blobasset, like the base stats, and then adjusted stats, would it be enough to just have both lists in the same order, or would it need more connectivity like the same unique ID on both
not sure I really understand but I have no problem with sharing indicies if you're working with something deterministic and simple/explicit - though at that point you might usually put the data in another data structure anyway? Are adjusted stats a mutated version of base stats which is a blobasset?
yeah the blobassets are fixed immutable data, I figured I would create entity components for the parts that might change
if I keep both arrays the same size it should work fine I guess, if it needs data from the blob then it just looks up its own indice on that
Is it possible to set a texture on an entity? I've never really used entities before.
I guess it depends a bit on a)if you ever need to reference the base stats, b) how often you access that data and c) by how many systems/different purposes? But what you've described should work I think.
Is DOTS not working in 2020.1?
it is working (aside from my project crashing on start up with b16 right now)
I added the dependency but Unity.Entities isn't defined. I'm reading I might have to add it to an assembly file but I don't see that in my file explorer.
my guess is an issue with your manifest file - if you share it on pastebin or similar I'll take a quick look
anyone?
I don't think what you're asking makes that much sense @odd cipher - if you're talking about sprite renderer's converting to pure entities, that's not a thing yet. You can set up a material on a quad though.
I might just have to wait until they release the new entities package for 2020.1.0f1
because the latest preview does not support it
probably just that
I'm using it fine... 0.13 with 2020.1.0f1
I'm also using it fine
How did you add it? I tried forcing it into the assemblies definition for the game and it threw more errors
I have the package installed
Windows 10 64b
so.. you have an existing game and your project already has some assembly definition files correct?
Is your unity project brand new? Like a test?
Existing concept from early that I'm trying to upgrade to 2020 and DOTS.
Hmm, if you make a new project, you could try pasting my package manifest.json in?
see if that works
I'm on a mac but the packages look pretty platform agnostic
If you have existing asmdef files you'll need to add appropriate packages - this is mine but you don't need Timeline or Rendering.Hybrid
i'll try that first, sec
Yeah I tried installing dots on an existing project and it had a bunch of problems... created a new project in 2020.1 and it installing them went fine. Painful, but a lot of the packages are only having continued development on 2020.1
yes
what really ? damn
and Entities 0.13.0 just released
i should download it
AppendSystemToPlayerLoopList(): adds a single ECS system to a specific point in the Unity player loop.
Finally
yea plus the multiple component add/removes π
Is Unity.Scenes gone?
Nvm the asmdef renamed from Unity.Scenes.Hybrid to Unity.Scenes
ecb now has multiple component add/remove?!
yea
AddComponent(Entity, ComponentTypes) and AddComponent(EntityQuery, ComponentTypes)
and same for remove. EntityManager will have them to but atm has the non entityquery versions
Wow
There's FixedStepSimulationSystemGroup now
every system inside it is updated like in a FixedUpdate
0.12.0 got some great feature additions, why did they wait for 0.13.0 to release the update π€¨
no clue, @amber flicker , sorry π¦ i actually can't build right now. Unity can't build at all on the latest mac beta (which im on)
appreciate reply - I've found out I don't need to be using the new build pipeline at all (windows desktop)? So unclear about when you need to use it
Are entities faster to "spawn/create" than GameObjects?
much
If it's already an existing in the system (as in you're making a copy) it should be very quick to instantiate
I'm thinking of replacing my chunks with entities. It would probably make them faster to create?
since I'm Instantiating each time
I'm not sure what you mean by that. In Unity ECS slang I believe they may have a different nomenclature for what a "chunk" is.
ECS allocates memory in "chunks", each represented by an ArchetypeChunk object. A chunk always contains entities of a single archetype.https://docs.unity3d.com/Packages/com.unity.entities@0.13/manual/ecs_core.html
I mean like terrain divided into chunks. Minecraft style :p
Right. Hmm, it might be as simple as throwing your terrain under a Subscene (which auto converts to entities and I believe stores everything in some kind of super fast loading binary format). Other people here would know a lot more about that than I would, unfortunately. I'm not sure if Unity Terrain gets along with Subscenes, but I thiiink it does?
Unless you mean mesh terrain, then it would be fine for sure.
Is the terrain dynamic or interactive or something?
The terrain is 2D and all of it is on a texture. It's sort of dynamic I guess? The texture does have some animations
A chunk is pretty much just one texture
Interesting. I have a feeling you're likely going to probably want to optimize what you already have if possible, and start researching the applications of ECS with some experiments. To me it would seem fairly challenging to mix ECS/Entities OOP/gameObjects/monobehaviours on existing projects without having things break.
As in it may not be a quick and easy performance fix you're hoping for, haha. ECS is super cool though. Definitely play around with it for sure.
Yeah I use Jobs and Burst right now. The textures are procedurally generated but each chunk only takes around 0.6ms to generate.
aside from instantiating them. Which probably takes longer? I don't know.
Sounds like you probably know more than I do at this point, haha.
https://docs.unity3d.com/Packages/com.unity.entities@0.13/manual/index.html
There may be some insights in there as to how entities are instantiated and you may be able to figure out what the performance gains will be.
Yeah hmm. I don't really know if theres a set amount of time it takes for a GameObject to instantiate. If entities does it faster than yeah performance would be quicker
not sure how to find out how much time each one takes though
https://docs.unity3d.com/Packages/com.unity.entities@0.13/api/Unity.Entities.EntityManager.html#Unity_Entities_EntityManager_CreateEntity it seems as though a few of these Entity creation methods can operate multi threaded, if that helps. Not sure if a GO can be instantiated multi threaded or not.
fyi rough numbers - desktop pc, instantiate 1mil entities ~1ms - that's the order of magnitude - thousands of times faster than GOs. That's why converting and serializing in subscenes is exciting π
Hmm yeah not sure how I would make it work though. Because my chunks stay in one scene to another; Forgot what that was called but yeah. Not sure if its possible to do that with subscenes?
If the goal was to generate a world through instantiating tiles with certain rules, I think Unity has a procedural dungeon project that's a good reference (or will be). It depends a lot on why you are doing things the way you are - specifically your design goals.
For doing something like this, is the correct solution to use "ISharedComponentData"?
I believe you can't just write some sort of fancy query that reads in the info from both entities but only applies the changes to one - because I think that breaks basic ECS principles and would be potentially dangerous to multi-threaded operations. Is that correct or am I missing something basic?
And in actuality the shared component wouldn't literally be the Translation component, but a new shared component like "SharedTranslation".
hmm nothing wrong with doing foreach(Entity e, in someData d) SetComponent(e, GetComponent<Translation>(d.someEntity)); if that's what you mean?
Be careful with SharedComponents - you very rarely need them - it's for when you deliberately want to fragment your chunks
wait, that's not 100% - you can't take in Translation in the foreach at the same time as using GetComponent (unless something's changed)
Hmm, I think something that makes it a little more difficult is the Entity C's translation actually needs to be the negative value of Entity B's
so a foreach that affects the translation of BOTH components is a no go
you can, it's just that all the usual parallel writing caveats apply - i.e. if you want to do it in parallel make sure you only ever write to unique indicies - in this case if you wanted to change both at the same time, you couldn't do that (safely) in parallel but you could easily enough do it as two jobs
Right, I think I have to look into the "SetComponent" and "GetComponent" stuff you wrote there. That's likely the piece I'm missing. π
yes - given you previously mentioned you had time to learn this stuff I would recommend learning about IJobChunk and writing a few of those - it will make some of the more magical things much more explicit
Get/SetComponent abstract away ComponentDataFromEntity<>
I was just looking into that and entity queries in the manual! Good idea. Will do.
They can still do one thing the lambda's can't - efficient chunk-based logic - writing code that branches based on the presence of a tag for example.
They also give a great appreciation for how much less verbose the lambda's are π
That's interesting. I'd probably have to develop a better understanding of the lower level chunk system to really understand the benefits of the branching logic in jobs. I'd probably do more harm than good right now, haha.
I'm actually not even sure exactly what the "chunks" are in a literal sense. Are they structs (archetypes) holding arrays (components)? Was wondering that reading the manual, haha. In javascript most people use either an object or an array, but C# has all these cool different types of arrays and lists, etc.
Very worthwhile getting your head around it. Some good materials (inc docs), just need to parse them multiple times. An Archetype is defined by a unique combination of types. Consequently an entity that is of Archetype A has an explicit size. A chunk is a contiguous block of memory that stores as many 'instances' of A as will fit (a chunk is typically 64kb) so this tends to fit e.g. hundreds of entities of Archetype A. When you have more than hundreds, another chunk of the same Archetype will be made to accommodate them.
Thus you could have e.g. chunk1(ArchetypeA), chunk2(ArchetypeA) & chunk3(ArchetypeB). If Archetype A & B both have a component in common (let's say Translation) then when you want to iterate Translation you will be iterating over chunks 1, 2 & 3.
https://github.com/Unity-Technologies/DOTSSample/blob/09543c800c4ab58f061db4a407c3f564dc04f734/Assets/Unity.Sample.Game/Ability/Ability.cs
This file uses many different IComponentData structs, many for a single property. When should properties be split from a single struct?
Generally only put them together in an IComponentData when they are somewhat dependent on each other and would never be queried for independently. Thus, usually best to have small ICDs.
Is there a way to quickly suss out how many chunks a struct is for complex types like Color?
@amber flicker thanks for the explanation! It all helps everything click, haha.
@amber flicker I agree with the small ICDs for flexibility. Kind of interesting even just starting my project I've almost hit the 8 component query limit on some Systems. Will probably end up using the special structure that allows you to do more than 8 for a few systems down the line.
@gusty comet the entity debugger has a view for seeing how many chunks there are for a particular archetype
Is it still not recommended for serious projects?
not recommended for production
I'm not a beginner, but I'm still not familiar with Dots to a huge extent. A lot of holes in my knowledge, since it's hard to learn it while it's constantly in development.
Lol, being uncomfortable is how you grow as a person. I must be growing a lot.
Methods and classes constantly change
Join the club. We've got jackets.
But again, are major changes stopping nowadays?
Are they getting to the polishing phase or nah?
I don't feel like it actually changes that much... but.. it does involve e.g. reading the changelog of every package update
if you want to make a product to ship, id advise not using it tbh. use burst and jobs when the need arises but for the rest of it, it will probably hinder you unless your timeline is like +3years
Well, it is a dream project more or less, so whatever
I'll try upgrading to newest Dots version, hope nothing breaks in my old project
theres still no real: animation, sound, navigation.
spotty/early: rendering, netcode
physics is shaping up nicely and the basic transform system works well
always backup and use version control
colon pain? π¬
So, there are no animations/audio/physics/netcode? Oh, then it's all fine.
You can make Zork
I have couple ideas how I could interface Mirror with Dots
moving things are over-rated
And I'm making my own physics anyway
I just learned that if you use IL2Cpp backend you can write native plugins in C++ directly.
Can Job System/Burst use native plugin code in parallel?
And audio? I could just use gameObjects.
Meanwhile animations don't matter, since I'm doing a space game.
They always start so optimistic. π€
We sure do
ECS will break you down. Rebuild you.
I'm doing my bit to help with animations.. sometime this year I hope
I've done some stuff in ECS, and it f'ing hurt
But I'm that kind of hedgehog, who keeps on eating cactus despite it's needles
I come from Javascript with no OO background, so it's just a treat
So an OO layer wrapping an ECS layer
@amber flicker what do you mean?
is just... dinner and dessert
I like Dots for the fact, that it allowed me to have 40 thousand asteroids attracted to star
And I could render all these roids via URP
Although, speaking honestly, my CPU got to 100% load only when I spawned about 4 million of them
DOTween-like but DOTS equivalent with a decent Timeline, serialized animations and some other groovy features
ooo yes, looking nice!
thanks! much appreciated
what counts as stable enough? will it crash and error sometimes? maybe? like all other versions π
you need to wait if you want something labelled production ready - for the past year I've had almost no crashes but the more you mess around with subscenes, physics & netcode, the more risk is involved
I will mess with those, but in form of me implementing my own systems
It's not like I could use Unity's physics with scale I'm aiming for anyway
64bit - 1love
I can't even use native containers without crashing, filed a bug report but I don't think it's going to get resolved anytime soon.
I was going to use Job System and Burst for performance but I think I'll just have to go native without that being fixed.
π
is this native containers in static methods? not trying to put them in ICDs I assume
If you want to take a look here's the thread with reproduction project attached:
https://forum.unity.com/threads/crashes-related-to-recursive-function-call-and-nativecontainer.934026/
I'm fairly certain it's not any of my code if you look at the cases that cause crash.
that's quite hard to follow tbh - where are the arrays allocated?
Once at the beginning, persistent.
at the beginning? line/file num plz - nevermind, found it
is there no way to get a buffer without getting the entity first?
Yeah the project is pretty convoluted because it's a script interpreter.
I was hoping I could use GetSingleton with buffers by now
But those execution code don't really matter.
I suspect it's something really low level, maybe not even related to native containers, but yeah.
The techs that are meant to help me focus on the actual game is doing quite the opposite, and I just feel like giving up and going to native plugins and write my script interpreter there instead.
looks like it might be coming from one of your easing functions
Here's the thing though, only the Constant and Execute branch are ever executed in that switch statement.
It's not just easing functions, if you reduce the complexity of the code it just works.
You can remove some code that are never executed and it just might fix the crash.
Are there any good sources to learn about Dots from?
If you were to ignore the documentation
Well nevermind
How do I update this job struct, so it fits with current Dots version?
I'm simulating attraction of some particles to attractors
use chunk jobs or the ForEach lambda with SystemBase
Last time I remember trying to do that, I had some difficulties with accessing other entities from within ForEach, especially via int indices.
But okay, I'll try once more
been out of computer for the whole week
missed hybrid update π
need to catch up now
entities 0.13 as well π
I'd like to play around with the ECSSamples, but whenever I try I'm met with tons of errors. I have an inkling it's to do with imported packages. Is there a certain unity build/packages update I'm supposed to use?
there should be a package manifest file that shows that package that project is using, maybe check that ?
I see they took my comment about lack of this seriously :D
Added MaximumDeltaTime property to FixedStepSimulationSystemGroup, used similarly to UnityEngine.Time.maximumDeltaTime to control how gradually the application should recover from large transient frame time spikes.
well, I can imagine they would have done this regardless
I wish they would take my advice of "You should build it so I can understand it"
but yeah, it's mandatory to have some sort of fail safe if you do fixed timestepping
maybe that's coming the next version... π€
oh, that's actually a pretty useful addition, nice they included that
and even more so if you were the comment or one of the comments on the issue
Hmm, simple time saving thing. If you are creating a new DOTS project, the hybrid renderer's dependencies seem to be pretty much all of the DOTS packages, so you can just install that one package and it basically installs everything you need.
Uh oh, no I have to update to 2020.1
I'm try to navigate to another scene, without ecs. When I try to destroy the existing entities, system and blob, I get an error. Ideas?
private void OnDestroy()
{
_entityManager.DestroyEntity(_entityManager.UniversalQuery);
// _world.DestroyAllSystemsAndLogException();
if (_blobStore != null) {
_blobStore.Dispose();
}
_gameObjectSettings = null;
_world = null;
}
i've got a couple of things im confused about when looking at the profiler and im hoping someone here might know.
- why is there so much "empty" space? (Sephamore.WaitForSignal, the gray bits with nothing underneath)
- im not combining or completing any dependencies in the overarching system, so why is it trying to complete them all?
Is combining job handles faster than running both separately
Sephamore.WaitForSignal is graphics thing
odd that it's running with the rest of the CPU stuff π€ not even in the presentation system group
ah never mind. i get it now that i've read what it's about. thanks!
improving some graphics stuff reduced the number of times i see that, so that's good news for me π
There's gotta be some straightforward code along these lines to grab a single entity with a single tag, right? But without the "singleton" system or whatever?
Entity sheepEntity = entityManager.CreateEntityQuery(ComponentType.ReadOnly<Sheep>()).GetSingletonEntity();
Hey guys, Unity 20.1 released but I wasn't able to find information about DOTS in the notes. Is it out of preview now? So can we start building games for production using the ECS now? π
If there are any official links for the DOTS release please post them π
there is no DOTS release, DOTS isnt a package, made up with Entities, Jobs and Burst packages, Jobs and Burst packages are out of preview iirc, so they are ready for production but Entities package is still on preview
@opaque ledge so you mean the ECS is still on preview?
Sephamore.WaitForSignal is graphics thing
@deft stump itβs not graphic thing. This is regular CPU semaphore which indicates that this thread waiting for something like threads synchronization - waiting other jobs, waiting for gpu thread, etc. In his profiler is exactly pure CPU semaphore waiting for other threads done (as called Complete and jobs chain in handle completes and main thread waiting other threads in this case)
i've got a couple of things im confused about when looking at the profiler and im hoping someone here might know.
- why is there so much "empty" space? (Sephamore.WaitForSignal, the gray bits with nothing underneath)
- im not combining or completing any dependencies in the overarching system, so why is it trying to complete them all?
@craggy orbit 1) because not all things parallelized and can run at the same time, like writing and reading same type at the same time as it can be race condition and safety system prevents you from that, and RW-R jobs then runs in chain, and depends on job type, amount of data for processing etc. threads can idle while another jobs doing their work.
- depends on types (or if you manually doing that) systems builds dependency chains,
under hood systems completes their own previous frame dependency and if it was hard work and wouldnβt fit in to this time range (between this system update calls) - this force complete it. Reason for that (and this is mentioned in source code) is preventing infinite, growing chain. Second reason - EntityManager, as some calls trigger sync point, other calls can trigger dependency complete (for write chain or readwrite, depends on that youβre calling)
Is there a guide that helps with converting existing code to DOTS?
@gusty comet not really doable, its a very different programming paradigm
at least if you come from heavily oop-d monobehaviors
if your code was just algorithms on Lists, you can likely change to jobs on NativeLists and have it just work
let me send you something I wrote and where I'm at trying to convert it, it's mostly math and not a lot of OOP-based gameplay so it can be done I think
it was almost entirely written for unit testing and not scene testing
uhm, if its stuff easily unit-tested and math-y, you should be able to mostly convert it straight
yea that's what I'm thinking, sec
Original: https://ghostbin.co/paste/qp3fx
DOTS: https://ghostbin.co/paste/age38
DOTS does not compile yet, I'm trying to see fi that's the right idea
and I'm wondering where the conversion functions go (the GETs attached inappropriately to the static class)
so the chemicals would become entities, I don't need the Cid anymore because of the new entitymanager system, and the conversion functions would just become static functions on the static Chemical class?
you have zero need to split things that much
just keep your original struct unchanged
it will be simpler for now if you just have that monolythic component
later down the line you can split it once you know what you are doing, and if you know splitting will be useful for some reason
hi, im creating an entity from a prefab with entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings) and without instantiating it, an entity appears already on the entity debugger. Anyone knows why?
It will and should be visible in the entity debugger.
If you want it to be a prefab entity, make sure it has the Prefab component; this will make it so that systems don't do anything to it (this also includes rendering, so no worries about that)
For an entity to exist, it must be in an entity world. Thus, when you make a prefab entity, it must be in an entity world. The Entity struct is just an id for a given entity in a given world.
@vagrant surge I was following this example.
https://github.com/Unity-Technologies/DOTSSample/blob/master/Assets/Unity.Sample.Game/Ability/Ability.cs
Is there a reason they split the struct up so much?
It will and should be visible in the entity debugger.
If you want it to be a prefab entity, make sure it has thePrefabcomponent; this will make it so that systems don't do anything to it (this also includes rendering, so no worries about that)
@tawdry tree Okay, so if I undertood you, the entity created with the Prefab component is mandatory and necessary in order to make instances of it. Also it is just a reference and is not modified by systems. Right?
You can instantiate an entity from another entity, whether the entity has a 'Prefab' ICD or not. EntityManager.AddComponentData(convertedEntity, new Prefab()); after your conversion will mean that the convertedEntity is ignored by all other systems in the world (unless a system specifically requires it)
Im doing this:
entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);
this line creates an entity which is not modified by a system and appears in the entity debugger.
then I instantiate the entityPrefab:
Entity entity = entityManager.Instantiate(entityPrefab);
this one creates another entity and is system sensitive.
my question would be what exactly is the first entity that I do not instantiate.
Entity entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);
entityManager.AddComponentData(entityPrefab, new Prefab());
Entity entity = entityManager.Instantiate(entityPrefab);``` - this will give you two entities: `entityPrefab` will be ignored by all systems, `entity` will be your instance to do with as you please
All right, thanks
@gusty comet they split so much because they are adding and removing them
they use them for states and things like that
in your example, your molecule never changes
and you dont have variations
so there is no need to split
oh I see, so they're using components as flags
right because structs can't change, I get it
So the other part of my code is what I call a Jar. A Jar is just a MonoBehavior class which handles the addition, subtraction, and division of chemicals, as well as the math for pressure and temperature. A lot changes in a Jar all the time, but for simplicity's sake, it is assumed all chemicals in a single jar are evenly heated.
So for this property on the Jar <Chemical struct, moles>,
public Dictionary<Chemical, float> Chemicals = new Dictionary<Chemical, float>();
How would DOTS work? Is that a job for IBufferElementData?
or I could just add as many as of these as I'd want to the Jar entity?
public struct JarChemical : IComponentData
{
public Entity chemical;
public float matter;
}
afaik, each entity can only hold one componentdata of a specific type,
I have seen that there are blitable array implementations, but I think the common way might be this,
(although, just started watching the video, so can't say much)
https://www.youtube.com/watch?v=XC84bc95heI
β
Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=XC84bc95heI
Let's learn about Dynamic Buffers so we can store multiple values inside our Unity DOTS ECS Components. (Array, List)
Unity DOTS ECS Playlist
https://www.youtube.com/playlist?list=PLz...
yes dynamicbuffers are the general solution for arrays of components. Remembering that every entity archetype has to have a fixed/known size, DynamicBuffers work by having a fixed initial size and after that, Unity abstracts away allocating memory on the heap and using that instead. Haven't watched the vid but codemonkey's are usually good
He covers the memory allocation in the first 6 minutes
Video suggestion on EntityArchetypes please
It's a template of component, that's it 
Makes it so that you don't have to have 50 AddComponent when you setup your entity
They actively exist in ecs tho, so it's way better if you create them at start and reuse them rather than recreating them everytime
okay so just to make sure, in DOTS: singletons are OK
because I've thoroughly beat into myself that if I have to use a singleton I'm doing something wrong
DOTS seems to suggest singletons are great
singletons are okay and needed in some systems
I use singletons all the time
use them sparingly as side inputs to systems
cheers, saw that video suggestion, I've seen some but not this
Yeah I had deleted the link to it just because I
watched a bit and figured it was probably a bit too "beginner".
The best DOTS material I've seen so far is this guy live streaming making a game:
https://www.youtube.com/watch?v=JkiJoAufH9A
And this Udemy course absolutely destroys pretty much all the available un-paid content on YouTube:
I pretty much disagree on the paid course
Why?
1: it's outdated
2: it doesn't teach anything beyond official examples and docs
It's not very outdated? All the code in it would still work I believe even in 0.13 ?
its indeed a bit outdated, but i watched it, and think its great
other than the outdated apis (easy fix), its pretty great to explain the flow of using it
No, but the reason it's valuable to myself is because it's basically someone who understands the documentation reiterating it in the proper sequence, etc.
yet, it doesn't give you more info than the free resources
but its linear and explained
it also had clear errors
Yeah, it's linear.
vs the scattered stuff with free resources
i would say watch it, but dont follow it exactly
follow it with the docs + newest apis
Totally agree. I spent two weeks looking up free resources and learned more from that course in one day - BUT, I think a really experienced programmer would likely learn more from things like that DOTSBOTS video, etc.
anyway, that tutorial doesn't even know about SystemBase, so you end up learning more complex and outdated approach first
The codemonkey videos I find are a little tricky because he shows what he does, but doesn't exactly explain why he does it. Which is more suitable for someone more experienced than myself.
unless she's updated that
well, Penny didn't explain all things on that tutorial set either
Well, yeah but on the other hand if you understand the older approach you understand the system and what's going on under the hood better because the new pattern is just a slight abstraction over the old one
how I saw it, it was more like recap of existing tutorials quickly put together
anyway, that's just my take on it
Well if you learned a bunch from the existing tutorials I could see how it wouldn't be very valuable haha
I didn't really watch it to learn more, more like watch if it was decent
Yeah, well the other thing is, even if it's slightly outdated, at least it's all taught in the same version of ECS, because the existing tutorials and stuff are all over the place
Like I don't care if I learn the cutting edge stuff, I just need to get the concepts down hahah
there is another thing i recomend allways. Forget about DOTS, and attempt to do stuff on entitas
mostly to get how "ecs" works
yeah but with DOTS, things move in fast pace
as a pattern
alternatively, snap Flecs or Entt and do some games on pure Cpp with SDL
Yeah, but they'll slow down as it starts to approach it's final form
changing the mindset to ecs/dots is fairly tricky
you probably weren't here year ago when we still had inject stuff in
practically nothing of the old code we wrote works today
same thing will happen with the things on that tutorial once Unity wipes the deprecated stuff she teaches there
and they ARE deprecated already
yeah but programmers aren't memorizing syntax for the most part
they're memorizing concepts
and luckily the concepts won't change that much. Some parts of them might, like how they're applied, but those are much easier to learn once you have that foundation
again, how Unity ECS works has changed quite dramatically
like, the core concept of systems, components and entities hasn't changed
but whole practical usage has
Yeah, totally
I agree with that. The application is fairly different.
However, the trick is, there is no more up to date course, so the only alternative is... not really learning anything, hahah.
And it's not really that out of date. It still uses the system forEach loops, etc, which is still the current paradigm. Maybe the structure of some of the jobs stuff has changed, but I didn't even know what a job was prior, so, hahaha
if you want to learn thing on that paid tutorial, pretty much just watch this https://www.youtube.com/watch?v=a9AUXNFBWt4 and open the Unity Physics docs and DOTS Examples for physics
In this workshop style video we walk through an example project created by Unity Evangelist Mike Geig on how to script a Pong style game using Unity's Data Oriented Tech Stack (DOTS) including the Entity Component System (ECS). This video covers the latest syntax in Unity 2019...
there wasn't really much beyond that on that paid set
that Pong tutorial is pretty much what codemonkey "aped" for the roll a ball tutorial
Are you talking about Penny's crash course with the viruses or the full course?
I'm talking about the DOTS course you linked
there are tons of videos, like 70 or so
but they don't truly teach you much more than on those mentioned resourses
I guess there was like 10 videos on how to use math lerp etc
Yeah, they seem to cover the "how" where as noobs like me need the "why". If you already know the "why" you're good to go.
but if you don't have programming background, you probably shouldn't touch DOTS in the first place
Hence that video is 55 minutes and penny's course is 13 hours. Yeah, it does cover similar content, but it takes muuuuch longer to explain why you do something than how you do it.
it's just too raw in general and for a beginner, it would be total disaster
Nah
right now only people one could recommend DOTS for is technically minded people who don't mind diving into the deep end and being willing to adapt to constant changes
it simply isn't ready yet
So your advice is instead of taking a course to learn something... to not even try to learn it? Hahaha
its not that bad I'm an idiot and I can just about use DOTS 
Yeah, this stuff isn't exactly rocket science. Sure there's a learning curve, but it's not impossible. Everyone here has done it.
I would never recommend DOTS for person wanting to learn Unity
this has nothing to do with complexity
I'm excited for it because I was afraid my systems would be too cumbersome to run and it'd be hard to multithread it
now I think it's probably easy to achieve
it's a lot of physics math
current Entitites programming is getting pretty straight forward now with less and less boilerplate
I just had some experience with running a Minecraft server and the entire game is single cored
it's actually horrific and I can see why Unity is pushing this
you can still get most of the perf gains without Entities still
job system + burst are production ready and you don't have to use ECS
Yeah, you can get a lot of them with the Job system, that has been in Unity since version 4. Penny taught me that. π€
Hahaha just kidding
job system has definitely not been exposed until recently
it's been internally used in Unity for a long time though
would it be weird to have a blobasset and a dynamicbuffer on the same entity?
No
π cool figured that's one way around my problem
It'd be weird not to, bro
How does one reference something like a material in dots? I am trying to create a system that changes the material on some entities based on some component's value so I can better debug my systems, but I cannot figure out in the first place how to get the material into my system.
rendermesh contains a chunk's material, and needs to be read on the main thread
how do i add dots to my project
i video said i need to add hybrid renderer and entities packages
but no packages by those names exist
Did you enable preview packages? What version of Unity?
You may have to manually add the packages to your mainifest.json file
I can show you, one sec
@restive horizon https://www.loom.com/share/451828d30ebc486a80dd837479947856
"com.unity.rendering.hybrid": "0.5.2-preview.4",
I think it's a dependency of that package anyway so I believe it'll get installed
oh okay
If it doesn't it's the same process but with the other packages... adding them to the manifest
i dont understand why it has to be a package, why cant it be built into the engine?
Because it's not ready for "prime-time" yet and they basically don't want people to try it and get discouraged since it's not super polished.
@wise monolith this may help. Shows instantiating an entity with a mesh and material...
There may be better ways to do it than this, I'm not sure, but it might help in the meantime.
Thank you
alexwilkinson this does exactly what I need right now and hopefully I will be able to find more elegant solution later.
π
So I switched out my really crude 2d physics engine from systems running inFixedUpdate() on a MonoBehavior to the FixedStepSimulationSystemGroup and I'm pretty glad everything pretty much works π
That's awesome man, nice work. π
thnx π
Rather that newing a job struct every time, can I simply save it, change fields, and reuse?
The structs need to be localized , so you end up calling the copy constructor if your struct happens to be a field in the class
Ah so that would be pointless then.
If I'm running a job on main thread, can I just use a field as input and output, rather than a native array?
w/ burst, no, WithoutBurst() sure
RIP.
Can't be lazy I guess.
But you can use a field (of the job struct) as input though, so how does that work exactly?
Got an example?
Can someone help identify what's causing a Unity freeze (like a while true loop). It seems to freeze when I set an item in a native array, but it has space to store it. https://hatebin.com/sdqbwcjphq
@lusty otter oh, yeah that works, since the job struct would likely be a local declaration in OnUpdate() when scheduling - you'd copy the data locally to that job struct
Hmm, so result has to be in a native container? Can't just be a plain float field of the job struct?
Or a pointer, if you want to grab that result and use it in another job (probably best to see what the generated code does exactly)
I see.
Is there any performance benefit or other reasons to declare WriteOnly?
I have become a god. Finally figured out how to reference another Entity's components, hahah. I dunno if this is the "right" way to do it, but it works.
@amber flicker apparently you can do this with the Translation after all.
Also, if someone could explain this I have a feeling it would be super helpful in understanding the structure of ECS.
Every Entity has an index (and a "version"), sure, and you can see that here. But you can't access the components or their values this way - I assume this is something to do with how everything is packed into memory? Or because the Entity technically doesn't "exist" yet?
It also seems a bit strange to be running the entityQuery and changing it to an array EVERY update, however, when I tried it in OnCreate I think it returned an array length of zero since the Entity may not exist yet? You'd think the Entity would though as it's created in a monobehaviour that I think should instantiate prior to that... I'll have to play around with that.
the new entities foreach has a fluent api, you do stuff by chaining method calls,
Run in this case means execute it immediately on the main thread,
the index in the foreach are usually if you have concurrent command buffers and such to pass the index of the entity for operations like adding a component or destroying the entity
not exactly sure about the query, but I think you have to use this methods (ToEntityArray) to have them usable in a sychrnonous context, but you could also do the same filtering with entity foreach asynchronously/in a job
(sorry, just saw the message and wanted to comment)
whenever you query or generate an array like ToEntityArray, you get data that represent the current state of the world afaik,
if you do it on oncreate, you might get nothing as the entities you look for don't exist yet
https://discordapp.com/channels/489222168727519232/497874303463850004/736301578214047826
the code in the picture looks a bit odd though, why is the array disposed in every iteration of the loop?
(also, I mixed something up, I thought about the index passed in things like if you do a IJobForEachWithEntity like foreach query, but you meant it like the index attached to each entity in itself?)
Yeah the index attached to each individual entity
Oh, yeah the dispose should've been below run. Changed!
But that is cool to know that the command buffers and stuff have passable indexes
I actually never accessed the index of an entity like that,
if I wanted to get or set some data or add to an entity, I use an entityManager,
and in jobs you can inject ComponentDataFromEntity with GetComponentDataFromEntity in a system,
that gives you array like acccess where you use the entity as indexer directly
I use whatever works and then change it later when I figure out what the hell I'm doing. π
Hey is there a proper way to shutdown ECS and switch to another scene?
same alex ^^
I'm also not that concern about which approach is more efficient or not atm, as long as it works for me.
sorry, don't know
I agree though the entity manager seems like the more proper tool for it. It seems weird to allocate a new array EVERY frame if it can be avoided, haha.
Lol, well I know my project is going to take years to complete and I assume nothing I'm writing now is going to stay.
Plus ECS will likely have changed into LISP by that point.
in your case, how many physics facade player entites are there? You only use the first element. there is a method to get a singleton entity for example
https://gametorrahod.com/ecs-singleton-data/
and you could run your code in an async/parallel job probably, by just passing the float3 position parameter as input and read from it, since all entities get the same position assigned
App.GameplayRuntime.activeEntities.Sort(new EntityComparer());
int length = App.GameplayRuntime.activeEntities.Length;
int count = 0;
for (; count < length; count++) {
if (!App.GameplayRuntime.activeEntities[count].needInitialization) {
break;
}
}
I wonder if it's worth making this short piece of code a job and burst it.
also, in your example, you don't need to call SetComponent(entity afaik,
translation is already passed by reference,
I would cache the position above
float3 dstPosition = GetComponent<Translation>(physicsFacadePlayerEntityArray[0]);
and in the entity foreach simply do
translation.Value = dstPosition;
I don't see any changes that happen in the loops burrito?
or do you only mean the first line?
The loop is for getting the count.
I think in practice activeEntities is less than 100 in length.
so you are only interested in the first occurrence that has needInitialization = false? and stop there
ah, I think then it's probably better to just have it like this, if there are so few entries
@minor sluice yeah I caught that and changed it. Good lookin' out, though. π
one thing I'm not sure though
App.GameplayRuntime.activeEntities are those simple fields you access or is there anything happening behind the scenes (like a property that runs some logic)? if so I'd cache it
var activeEntites = App.GameplayRuntime.activeEntities;
It's just a field and can cache.
I do wonder though, because both the sorting and the counting access the native array, so it would do stuffs like boundary check and other C# overhead stuffs?
ah okay, the caching should still be faster then, but practically it probably won't make a difference when it is all just fields
oh, if that all is a native array, I think there is some overhead when you try to often access it in managed code
Oof.
but if there are only around 100 entries, shouldn't matter much
Thanks, I'll just leave it like this for now and check later.
I'm thinking if the job overhead isn't big it might just be worth it, for the occasional 100+ entries situations.
Is there a blittable data type that can be used that is similar to a struct? I think the NativeArrays and stuff can be utilized inside a component, right?
I was thinking you could probably make an interesting quest system by having essentially an array of data in a component and a System that acts as a parser on it to figure out next actions. So it's almost like you're writing your own little scripting language for the quests inside the components. All the dialogue, the type of quest, etc.
would that make sense to be in jobs or components?
because strings are also non blittable, or should it just have an index to a text outside?
I saw blittable array implementations, but I think a problem is if they can have variable length and for blittable data, their size should be known for memory layout and management reasons
there are blobassets to store readonly immutable data for example, and dynamic buffers to make something like a one to many relationship
Well, I guess having a System parsing it could stay no matter what the input storage method ends up being, I was just hoping there was something in ECS that would be able to hold that kind of data.
The trick is you just need the component to hold some data to somehow remember the progress on the quest or whatnot.
So possibly reading in an instruction set from some external text and holding the progress on a component or something. I bet someone will come up with a pretty eloquent system for doing it at some point. It'd be interesting to see.
A component that knows whether the quest is active and what the progress is I think would be all you need and then you could read in an instruction set. π€
maybe possible, but I have no idea how to approach it,
haven't tried the hybrid approach yet, but can't you simply store references to objects/behaviours in a component that you assign to an entity somehow?
to me it just seems like this might be a case where the ecs approach would make it harder than necessary,
you could still synchronously access the logic that manages the dialogue tree in a system update and I don't think there is any good reason to structure that to be usable in a job
dialogue decisions and consequences are pretty infrequent and are usually super light in the logic they contain,
I would maybe just reflect the effects in components
Yeah, I'm not sure. In my opinion I'd rather use a slightly harder approach in one system than* split across two easier systems, just because discrete systems can potentially multiply exponentially in complexity
if they belong together, I think that's true, but if they can work autonomously from each other, or have a benefit from the modularity, I think the ecs approach can have benefits
Yeah, that's what I meant, if I had to do it I'd like to reflect the effects in components for sure.
That'd really limit the scope of the other system and it's responsibilities so it doesn't accidentally become more complex that it needs to be. Basically just acting like a database.
I really have no idea how to approach this, or even how a logic structure would look like where the decision logic is implemented in an ecs kind of way,
but.. for example what I could think of, a player entity might either get a decision component attached that has the index of the current dialogue and the index of the answer,
and all entities that have that component are then queried in an OnUpdate, the dialogue behaviour makes its checks and then stores the consequences into a database like structure or write consequences to components of involved entities
I was thinking simpler than that even and just put the branching logic right in the "database" and let the parser (a System) handle it.
So your system is reading in a weird struct or whatever (I'm from javascript land where everything is an object, so I dunno what the best one would be in C#)
and it's kinda like this. I'm sure you could do this with either an object or an array or whatever.
[0]QuestName: "This example quest",
[1]QuestType: Kill X of something
[2]Dialogue: "Hi. I have a quest for you."
[3]Choice: "Sure", "Nah".
[4
Woops. I hit enter. But you get the idea, haha.
I dunno if that is a super naive way of doing it... without suuuuper sophisticated branching logic it would probably be okay. Branching logic would make that approach pretty difficult.
And a "Progress" component might just store the index array for the progress of the quest.
and the System looks for some keywords or something of the corresponding [i] in the quest array of the progress component and just parses them and the condition to progress to the next one.
It is pretty hard to imagine what it would end up looking like, I'm sure there's lots of issues with that implementation, but it'd be cool to do some experiments and see what happens.
sounds fine to me, but I haven't worked on dialogue systems yet,
like all the database and branching logic related stuff I think don't have to exist in components
Yeah, it's an idea. I'll probably try fiddling with that soon... now that my character can move, he'll need some stuff to do, hahaha.
maybe I wouldn't even store any outcome of the dialogue in a component, just leave the result in the database or decision representation structure in that parser/system
I was thinking that the "Progress" component literally is just the current item of the quest array and that's it. I think that's all you need, because you can decide if it is active or not based on instructions in the Quest... object... thing.
lol
only thing maybe to just store the current dialogue index to identify where the player is atm,
or storing the id for the dialogue lookup of NPCs in their components?
Yeah, the second thing you said I think is the same thing I'm saying
except the "quest" contains everything, including dialogue... I think, but I would have to check, that generally every single element of a quest is sequential, so it could work
hmhh, yeah,
but I wouldn't probably even store any permanently required/persistent information as component, except as duplication.
so the current mission and dialogue state should still be persistent somewhere, but maybe it can also be in a component if that helps in any way
Oh, yeah, persistency of the data in the components would have to be sorted out for sure.
Yeah, I was just assuming persistence and player state is backed up to a server somewhere and the components would somehow get their progress data back. That'd be an interesting problem to solve as well. Guess you would have to somehow reinstantiate all those quest progress components with the correct values, etc.
But the nice thing is that's literally ALL you have to do for the entire quest system's state
the issue of serializing and deserializing world and quest state from persistent data to the runtime effect representation is a general one I think, not sure what a good way to handle this is,
but maybe the parser system could also have a method that just runs over all the stored consequences and applies them to the world
Lol, i'll find out when I get there. I plan to play around with SpatialOS in a bit but I'm sure any sort of persistent data in my project would be months away
Hopefully I'll understand something about ECS by then. π€
ah, sounds interesting,
good luck with all of that,
spatial os seems amazing too, but isn't it kinda expensive to use? with more users etc
I dunno. I'm rich. π€·ββοΈ
Plus the only players for 3 years will probably be my friend who's doing the art assets and I... so... it'd be weird if we went bankrupt
ah, okay 
yeah that shouldn't happen then
I just recall that worlds adrift had a problem where the server infrastructure just was so expensive for them, even though they had a lot of players
Lol, that's definitely a "ducks before they hatch" situation. Too many players is definitely the problem you want to have.
Because at least you have a problem there's value in solving, hahaha
And they were on SpatialOS?
yeah,
but also, if that is a project that should bring revenue, there should be a simple calculation of having new/more concurrent players even returns more profit or not,
if not, that sounds like a pretty bad model
ah yeah, they used spatial os
Well I mean... I would say they should probably increase the price of their game, but a lot of people are afraid to ask for more money because they think they will lose all their customers... which sometimes happens I guess, but it could easily have been a symptom that they just priced their subscription too low
yeah it's tricky,
there are probably other reasons too why the game shut down, but operating at a loss would be a bad idea in any way, except if you are maybe a project that is focused on customer acquirement and have a plan to turn profitable at a specific amount of users and subscriptions
okay, will go now,
good luck with your project further down the road and the dialogue implementation 
If you can kickstarter a project that would make sense, but if you're just doing something indie you probably want to keep it super lean
Cool, thanks for the help! π
It is appreciated
well, am only starting out with ecs too pretty much, so I'm not sure how much of my statements are correct, but I'm trying to learn ^^
have a nice day!
Can't wait to Kickstarter this
@minor sluice did a quick test of the ECS "quest system", made a vid.
there should be a tab dedecated to dots physics, but here's my question https://docs.unity3d.com/Packages/com.unity.physics@0.4/manual/simulation_modification.html
how do I modified the movement phase
as in, i want dots physics to calculate all the forces etc
but i would like to have custom code for how the forces are translated to translation and rotation
May help, may not. Depending on what you mean by "custom code", you might want something far more complex than this, haha.
Just looked at your link. Clearly you're trying to do something much crazier. π
Yeah
Basically tell the system to not calculate movement on its own
While a custom code would handle it
@vagrant lotus I noticed at the top it says Note: Hooks for simulation modification are a work in progress. They may be incomplete and the interfaces are very likely to change between releases. The Unity Physics Samples project has one scene for each type of modification and it may be best to refer to those in order to see how the current interface behaves and what the API is. , and I was looking at the cool samples they have out of interest and it looks like they don't have any samples specifically demonstrating that, so I wonder if those hooks are not in yet?
Yes that's the problem with previews
Not enough explanation
I was hoping what I want to do is possible with the new 0.4.0 preview
Guess I have to wait and see
Weird they would describe some of the potential hooks right under that though if that were the case
They are adding features every update with dots physics
Thought I might try my luck
physics samples should have some examples on modifying the simulation
did you check there?
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/UnityPhysicsSamples/Documentation/samples.md was lookin' at em but none specifically state they're doing that
oh, maybe this one
`hmm
I posted a video of an idea for an ECS quest system a couple hours ago, but I was thinking, if a System allows it - and I don't see why you couldn't - I wonder if parsing the plain text "quest" file from JSON would be beneficial vs just trying to parse your own little custom script written in plain text. I think it would be, because 1) it ensures the formatting is correct or it won't run, and 2) you have an "object" (whatever C# calls it... a dictionary or something? haha) with proper key value pairs off the bat. There's likely some other benefits to using something more standardized as well, and I don't think it really loses any flexibility since you're still writing the code that interprets what to do with the data it contains. Would be easy to make a tool that the game-designers or whoever could use to make the quests, since it just formats it as JSON.
are you modifying your json manually
and are these scripts modifiable after build or just in editor
what is the equvilant of vector3.angle with ecs
what does it do ?
check Unity.Mathematics and Unity.Mathematics.math static class
but you can still use vector3.angle inside your jobs, just need to convert to/from vector3
what does this error mean?
At least one component that derives from IBuildPipelineComponent must be present.
I'm trying to build for android
Or wait
do I need Tiny for this?
I just read this old post from April: First, the current version of addressables will not "just work" with DOTS at some point. There will instead be an Addressables v2 that depends on DOTS. Second is that we are learning from the current addressables and focusing our energy on making sure v2 will cover all the same use-cases of today's addressables, with minimal amounts of re-learning.
Basically, i'm making a gacha game (think call of duty mobile) (my real project; the bullet hell game was just practice to get to understand dots better).
But for this gacha game (better known as, game as a service), the player needs constant internet connection, so they can download new assets from the web using addressables.
So if addressables isnt gonna work on dots, then time to redo my whole game (the 4th time)

I mean i know what i was heading into when i converted the game to dots. But maaaan...
pretty sure there's been people on this channel using addressables with DOTS
ask Roycon π
you can always run stuff on main thread and without burst which 'supports' Addressables
i mean.. systems that you write can always be run on main thread and without burst, you can always do ECS stuff in monobehaviours as well
can help more if you give me specific use case
Hrmmmmm... Time to NOT abandon dots then...
But I still need to build it for android
So how do i do that?
to build for android ?
So, I've been looking through the Unity.Physics documentation and I'm just wondering if there's any way to manually simulate such as the PhysX Physics.Simulate method. I've been converting all of my code over to DOTS on the server, but I've gotten to the point where it's time to implement client-prediction and reconciliation and I'm completely stumped. Due to the performance improvements of DOTS I've been able to implement some systems that I couldn't before, and I've been super excited to start playing around with some friends online to test them out, but I really don't want to have to enable client authority for the player's local character.
I've considered writing a non-physics based movement system that could handle reconciliation, only utilizing rays since they're quite performant when used with the job system, but that seems overkill.
The CharacterController sample which they made can be easily modified to allow for prediction/rollback https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/UnityPhysicsSamples/Assets/Demos/6. Use Cases/CharacterController
I'll check it out, thanks.
that char controller sample is not very robust though
it would need a lot of extra work to work properly
unless your char movement use case is really simple that is
Addressables works pretty well with DOTS, whole our assets in game loaded through addressables (not from network but from local bundle, as our game is single player RTS, we using addressables for smooth loading and better memory footprint, and just for more convenient management instead of raw asset bundles)
@tardy spoke saw your video. Didn't know you can use classes with IComponentData, although I expect that this would be a problem if you ever have to go into a job context with it (although that isn't necessary here). But nice that you got it to work that way,
with the hybrid ecs approach there should be a way reference reference types with maybe isharedcomponentdata? or something similar that is basically just a wrapper around a regular class instance/monobehaviour. ButI haven't worked with that yet so dunno
@minor sluice Yeah I saw that trick done by the Dotsbots guy here. https://youtu.be/JkiJoAufH9A?t=3966
Agree, there will definitely need to be a standard approach for working with external reference types, and maybe there already is, but that trick should do for now.
and are these scripts modifiable after build or just in editor
@hollow sorrel
Manually in JSON, only modified in editor.
If I was better at ... comp sci in general.. I could probably have the System create an actual graph/nodes setup based on the JSON's hierarchy, and I believe that would get you fairly close to how traditional quest systems are approached but with an ECS backbone.
With this code, I want to have a bunch of methods for combining or exchanging chemicals. Would the logic for this belong on the static class Jar?
It used to be a MonoBehavior and I'd just do something like Jar1.EmptyInto(Jar2), but I think with DOTS I'd need to do something like Jar.EmtpyInto(Entiy Jar1, Entitiy Jar2). Does that sound accurate?
Take everything I say with a grain of salt, but that sounds correct to me, haha. :)
You'd probably have two components, jar1 and jar2 and a foreach loop (System) on them that does the required action (pretty much like normal).
I don't think you'd need to explicitly "call" a function that does it like you have there, and instead just let the system manage when that happens, etc.
nothing wrong with a static method like that... though imo it smells a little OOP - does it matter that it's a jar? Or is it about Chemicals mixing in a volume? When do you call 'emptyInto'? It's likely related to other data - essentially what @tardy spoke just mentioned.
1776 got lucky. I am right once a day.
yeah you should probably have some system that just transfers anything that needs transferring. so if you need something transferred, you add a component to it or some other way of making it get picked up by the transfer system.
Out of curiosity, does anyone frequently use .withName("System name whatever") on your systems for debugging? You rarely see that in examples and stuff, but it seems useful.
I rarely do as I use the profiler timeline view a lot and the system names tell me all I need to know and debug gives me stack trace.. though I think it's useful, I just don't usually think to add it. Will probably add them in as code becomes more polished.
Ah, maybe they changed it so it just does it by default or something now, because it seems to only be prevalent in older tutorials
I'm actually not even sure where that name shows up, haha. I should look into that.
And they probably should just make it do it by default unless it causes an odd amount of overhead for some reason? ... would make sense to have it named whatever the System is named... haha.
I think it sets this name - the name of the lambda
i havent used it but it makes sense i guess, if you have a few different jobs scheduled in the same system, it cant really identify them well (for profiler)
i tend to just go by the system timing in entity debugger, since i assume that takes into account any jobs launched from it, could be wrong?
interesting.. apparently the name has restrictions - must consist of letters, digits and underscores only and may not contain a double underscore
I think the entity debugger timings is just main thread time? Though I generally don't trust those timings.
Yeah, I just saw that.
Also it appears that the name doesn't show up in the actual entity debugger at all
yea I think just system names in the entity debugger & systems window
Yep
Super noob question, but how do you get to that thread profiler? I just assumed that was in the regular profiler but I don't see the threads so I must be in the wrong spot or have it not setup correctly haha
pick 'Timeline' from the left dropdown that probably says Hierarchy currently
invaluable
Has a lovely view of your worker threads under 'Job'
Beauty! Found it. Now the second problem. My ECS project is so sad everything all my systems run on the main thread, making it an exercise in futility, haha. They're all related to player controls so that's not too surprising... but still. Sad.
You know what would be super handy is the ability to "turn off" a System/component script. Like how normal game objects have the enable/disable check box. Would make ECS troubleshooting/redoing systems a lot easier.
@amber flicker it is about chemicals mixing but jar is just what I called the mono behavior
I guess you're right that the concept of a jar isn't necessary without oop
like the tile with open space also had a 'jar' attached to it to represent the contents of the tile, i.e. oxygen and nitrogen
but I can just attach those chemicals directly to the tile, but the benefit I was going for was that it'd be very easy to take other containers of chemicals (i.e. a bottle of water or a gas tank of helium) and easily combine A into B
@tardy spoke ah alright, brought up the json questions because pretty much the only reason to use json for serialization is if you're manually editing the files (and thus has to be human readable), other than that pretty much any other serialization format is gonna be more efficient
but if you do edit it manually then nbd
i'm guessing what's preventing you from using jobs is the managed components, would be a big benefit if you could turn your static data (such as the quest textassets) into BlobAssets
seems you are using your quest textassets for scripting? if so then you don't have to put them into your systems as TextAssets, better to parse them into some useful struct/blobasset format and then put them into the system
also regarding the enable/disable, systems have an Enabled property you can use, and a Disabled tag for components is coming in the future, but yea no easy in-editor checkbox like monobehaviours atm
but yea the managed components are a crutch, ideally your project doesn't have any managed (ecs) components
not saying you have to convert everything since it takes more work and not gonna assume time is infinite, but is something to strive towards
@hollow sorrel is efficiency really important for quest data? Serious question, haha. I figured since they're loaded/parsed fairly infrequently it would probably be alright to have some inefficiency there
Though true - they could become blob assets which would be cool.
I'm missing some connections here though -
Would I go to Text file in JSON -> Unity parse that JSON into some sort of object --> Store that object as blob asset?
is efficiency really important for x
that's up to you. one could argue as long as you are above 60 fps then you don't need to worry about optimizing
usually the cost of optimizing is time, but i think with a lot of these things especially in data oriented design it's more about learning how to structure your data better, which is an upfront cost, but once you learn how then doing things the more performant way is basically free since it takes about same time to implement
personally i like the idea that every part of the game is as optimized as possible depending on time spent, because that means you have more frametime to spend on future things rather than have to spend time at the end of your project trying to patch up parts of your project that you made months/years ago and have to reassess how they work
ofc you should prioritize hot paths, if your quest code rarely runs then you shouldn't spend too much time optimizing, but i think it's good to do at the start just to learn how to make better systems in the future
There is an easy enable checkbox for enabling systems at least - editing entities is hopefully on its way
Oh yeah, I'll never fight anyone that it's a good idea to use best practices haha
@amber flicker where is that checkbox?
or in the systems one too I think
oo nice there is a checkbox
Well, my project is interesting. Basically my buddy who used to do tons of art stuff recently got into 3D modelling, so I'm trying to keep the progress fast enough to keep him motivated, haha. For myself, it's just for the fun of learning so best practices are definitely of interest to me. And BlobAssets do seem useful to be knowledgable about.
i don't get to see it because no support for manually ticked worlds π
Is that selection persistent? That'd be handy
actually I think they recently changed that? think it was in release notes
they changed it for entities window but systems still borked
ah ok
@hollow sorrel also I definitely have to worry about optimizing because the target platform is Oculus Quest, which requires 72FPS minimum constantly without stressing the hardware and overheating, haha. That's why I asked.
If anyone enjoys pain I have another one of my noob questions
Would I go to Text file in JSON -> Unity parse that JSON into some sort of object --> Store that object as blob asset?
yea i think that sounds about right
don't have that much xp with blobassets yet but that's prob what i'd start out with doing as well
Okay, so I'm trying to optimize this code. I remember FM said the Entity Manager was a better way to go about this, so I started moving it over.
So here's the "new" code with the Entity Manager. And it's nice because it's less lines of code, but it didn't "solve" or "change" anything I believe. It's still a fairly naive implementation, I'm sure.
My question is - I'm trying to understand some ECS patterns here.
What patterns would I follow to make this piece of code run:
A) With Burst enabled.
and
B) Multi threaded.
you should be able to just do GetSingleton<PhysicsFacadePlayer> before your foreach instead of the whole entityquery stuff
if it's a singleton
(doesn't answer your question, just a sidenote)
I think you can try what I wrote yesterday, get the entity before the loop
, store var facadePlayerRotation = GetComponent<Rotation>(physicsFacadePlayer).value into a quaternion variable before the loop,
and then just use
rotation.Value = facadePlayerRotation;
and have
WithBurst().Schedule(); or something
this is what I'm not sure about though: how does unity handle OnUpdate local variable access in jobs,
because unlike with real jobs,that isn't really verbose if you use ForEach queries
i think the codegen just turns it into the same as passing that local variable into the job
that is nice!
working with ecs gets more convenient, but the expense that you have to learn more about how the internals work since it isn't as explicit as it once was
Awesome, I shall look into this. :D
Haha, totally. I'm all for ECS style stuff, the steeper learning curve doesn't bother me at all. And I'm not a huge OOP fan so the idea of learning a ton of OOP isn't appealing to me as learning ECS paradigms.
Thanks for the help! I shall see if I can make this code not smell so bad.
the thing is also, those 2 paradigms are good for some use cases and bad for others,
maybe a complete replacement is possible, but I think it doesn't make sense for every use case,
sometimes it can be convenient to have an inheritance hierarchy or to work with direct references,
although I'm surprised how easy it already is to access a specific component of an entity that is not the current one
Hah, I'm still figuring out how to access specific components on other entities properly. π€¦ββοΈ
Yeah, what (little) background I have in programming is all functional, so OOP is just foreign to me.
you'll certainly get there 
Oh, yeah, totally. People can do anything if they put the effort in. My brother and dad are also awesome programmers, so that helps, haha.
Also in exchange for all the help if anyone here ever needs help/advice on sound design, like audio recording/mixing/mastering, I am extremely competent at that stuff, haha.
My game may run like shit, but it'll sound good doing it.
Yeah, totally that looks neat. But I more meant like help with professional audio in general. Like "hey this dialog sounds lame, how do I process it to sound pro?" or "How do I export stems so I can change the volume of certain instruments dynamically in the game?"
Also I can't believe this is all I had to do π€¦ββοΈ
Also I can't believe this is all I had to do π€¦ββοΈ
@tardy spoke You can also cache the entity query so you don't need to construct it all the time every update step
@hollow sorrel I spent like 2 days googling in search of that one line, hahaha.
@coarse turtle totally would love to do that!
EntityQuery query;
public override void OnCreate()
{
query = GetEntityQuery(...);
}
public override void OnUpdate()
{
var e = query.GetSingletonEntity();
}
Ah, I was struggling with that since I believe my character is created after OnCreate for some reason, let me try
GetSingletonEntity<> basically codegens to the same thing far as i know
but yea what psuong posted is a good pattern to know when using non singleton entityqueries
Hmm yeah I better look at how this player is instantiated
Also it looks like this pattern forces it to go back to .WithoutBurst().Run() , which in this case is probably the more performant move than finding that reference to the facadePlayer every frame
You could try RequireForUpdate(query) so the system checks if its dependencies are met before executing
Yeah, also something interesting is this is how the player is instantiated
should work with burst and schedule if you're getting the singleton outside of the loop
I'm not sure where convert fits into the script running timeline
You would think it would run first though
Should be the awake call if it's outside a subscene iirc and using ConvertAndDestroy / ConvertAndInject
the odd thing about the default singleton setup is that you cant directly use them inside jobs, its just a fetch in the system and pass it in, which is just annoying boilerplate.
and if you're never querying on it, or doing anything else with it, its practically no different than calling a system method or static helper for it
i guess it shows up in entity inspector which is nice if you want to view it and maybe hopefully in the future edit it; can be loaded in from subscenes too.
maybe they could have a wrapper that lets you just Get/Set them within ForEach without the hassle.
I think it's b/c the GetSingleton<T>() call ensures that the read/write fences are completed before actually fetching the singleton (though idk if that had changed in later versions of entities, it's been a while since I looked at it...) π€
it would be the same as using GetComponent<T>(entity) in ForEach but with a dedicated singleton entity
Got it!
Any further obvious optimizations or is that pretty much it?
@coarse turtle the RequireForUpdate worked
Also i'm aware you would probably want to do this on the main thread with .run() since it's related to the player's input, but I like that it CAN at least be scheduled, haha. Makes me feel like I'm doing something right. π
@tardy spoke cool π
@mint iron oh right, that'd be an interesting change to GetSingleton
There was also a "RequireSingletonForUpdate" or something that seemed pretty interesting, but I couldn't seem to get it to work. Might not do what I think it does, haha.
you'd think they're almost there because they're already converting it to a GetComponentDataFromEntity. But what would be even is if when iterating the entities, they made a local get first, passed it into each loop call, then save set the component afterwards.
@hollow sorrel I see what you mean about the referenced textAssets vs having them as a blobAsset. Seems like it disables the use of Burst and Schedule for every System that needs to reference them, which could definitely snowball.
yea managed components can't be used in jobs and burst
and secondly you prob also don't want to just put the textasset string into a blobasset because i assume you wanna do other stuff with it
instead of just read it
i mean if you're just using it for text to display on your ui that's fine
but if more than that you prob wanna parse it first
Yeah, probably parse it first I imagine
Then throw the object in as a blobAsset
I think that makes more sense... then the QuestGiver component holds the progress per quest. BlobAsset is just the read-only instruction set for the whole quest.
Would be fun to experiment with some graph stuff and try to store the quests as proper graphs so they can do cool stuff like branch but that's ... a rabbit hole haha
yea
there's a DataFlowGraph preview package that's aimed at DOTS graph editing
https://docs.unity3d.com/Packages/com.unity.dataflowgraph@0.15/manual/index.html
has anyone used it yet?
docs seem pretty scarce atm
hey guys, so, if i want to spawn a 3d entity like a box, say from a prefab or even directly through code, how do I approach uv mapping it? For standard gameobjects I usually edit the MeshFilter.mesh in a script inside awake().
Interesting approach. I take it just UV unwrapping it in Blender or something before import is not an option?
im completely unfamilliar with blender so I prefer doing everything i can inside unity
but if that's no option then i guess i have to look into that
What's the best approach to making a "multithreaded bool"?
By that I mean, I want a bool that is false by default, jobs running in parallel can turn it to true.
These jobs don't need to read the bool, and can only make it true.
I don't have any good idea other than using NativeQueue and checking the count afterwards, but I feel that's a bit overkill.
@humble mason my experience in 3D is likely pretty dated, but this is pretty much how it used to work.
If you're using primitives like cubes, etc, you may be able to work with the UV maps in Unity since they are so simple, and I believe they come unwrapped in a fairly logical way upon creation.
UV unwrapping anything more complicated than a box in code I believe would become quite complicated. However, if there are tools in Unity itself that allow for "directly painting" on an object the UV unwraps may be able to become simplified, as a "human" doesn't have to be able to paint on them in photoshop, so the unwrap doesn't necessarily need to be laid out logically.
I'm not sure how much sense that's going to make, it's somewhat difficult to explain what I mean there.
Basically if you're texturing something in 3D space the computer maps your brush to the UV's in 3D, so it's figuring out how what you're doing correlates to the 2D UV map.
If you're texturing something in 2D (IE in Photoshop), and it was a bunch of triangles (faces) laid out seemingly randomly, you would definitely struggle.
So if you need to texture them in 2D, like in Photoshop, you will probably end up unwrapping manually with Blender.
If you're texturing them in 3D, some sort of unwrapping done in code may not be too difficult, I'm not sure.
However, Blender I believe can also do that unwrapping/painting in 3D process, which might be the best compromise.
When you learn Blender, you do not learn ALL of Blender. It is an enormous program, like Unity. You learn a part a time. I don't think doing an automated UV unwrap and painting in 3D in Blender would be substantially difficult.
@tardy spoke im mainly working with cubes since im only working on a prototype/proof of concept right now, and exploring dots through it. I had no trouble uv mapping cubes when I was dealing with gameobjects, I'm just not sure how to do the same to entities
What's the best approach to making a "multithreaded bool"?
By that I mean, I want a bool that is false by default, jobs running in parallel can turn it to true.
These jobs don't need to read the bool, and can only make it true.
@lusty otter you could take an int, and treat it like a bit flag w/ the # of jobs/threads executing (1 << 0, 1 << 1, 1 << nwherenis the max number of threads you're executing)
for example, im creating a new entity when i press a button, i can give it the components it needs (transform, collider, mesh etc) but I dont know how to tackle mapping specifically. In a gameobject i would just do it on awake().
@tardy spoke
like this
{
private Mesh mesh;
private Vector2[] uv;
private void Awake()
{
mesh = GetComponent<MeshFilter>().mesh;
uv = new Vector2[mesh.vertices.Length];
uv[0] = new Vector2(0.5f, 0.5f);
uv[1] = new Vector2(1f, 0.5f);
uv[2] = new Vector2(0.5f, 1f);
uv[3] = new Vector2(1f, 1f);
uv[4] = new Vector2(0f, 1f);
uv[5] = new Vector2(0.5f, 1f);
uv[8] = new Vector2(0f, 0f);
uv[9] = new Vector2(0.5f, 0f);
uv[16] = new Vector2(0.5f, 0f);
uv[17] = new Vector2(0.5f, 0.5f);
uv[18] = new Vector2(1f, 0.5f);
uv[19] = new Vector2(1f, 0f);
mesh.uv = uv;
}
}```
Hmm, I added a texture to a material because I was curious if it would Expose anything in the Entity's RenderMesh component, but it doesn't.
My guess is it's probably actually done the same way you're doing it - the mesh has to have it's UV's manipulated before it's converted into an Entity.
@coarse turtle Oh I don't mean to need to know which thread/job set it to true, I just need to know if any of the jobs set it to true.
okay so then i take it it's impossible to do that for a created-from-scratch entity?
Or actually... hmm
@coarse turtle Oh I don't mean to need to know which thread/job set it to true, I just need to know if any of the jobs set it to true.
@lusty otter oh then maybe justbool* valueorNativeArray<bool>w/ 1 element is all you need
I assume I'll need to use NativeDisableContainerSafetyRestriction
But would it be alright for multiple jobs writing to the same index?
I feel like that's a recipe for crashing π°
@humble mason I'm thinking you're gonna have to grab an entity with the <MeshRenderer> component and see if you can manipulate it's "mesh" in the same way you're doing now. If you can, you can, if you can't, I wouldn't be sure how to do it.
I don't see why it would be different?
I think it'll work with the same method you're doing now
NativeDisableParallelForRestriction*
@tardy spoke through a dots system or straight up from a monobehaviour script?
However be aware that your mesh is likely on an ISharedDataComponent and it'll likely manipulate things in bulk, haha.
@humble mason through a DOTS system you should be able to execute that code
I believe
you could always or to the element if the condition is true and not set it if the condition is false
The bitflag approach can let you selectively write to a particular bit index, and you could always check if the bitflag is > 0 in your next job @lusty otter
I'm pretty sure the "mesh" it's referencing is the same thing, I don't think it's a special "DOTS Mesh". I think a mesh is a mesh in this case, but I'm not sure.
thank you very much for digging into this! @tardy spoke β€οΈ
That mesh being ON an Entity may affect how it's accessed though, so I'm not sure it could be accessed with a monobehaviour easily.
Yeah no problem, this is all just afaik, so hopefully the hypothesis is correct and it's modified the same way!
I'll give it a try, hope it works out and won't be overly complicated
im not very comfortable with dots yet, or with unity itself for that matter
I'm sure you'll get it, just prepare for a bit of pain. The ECS documentation is... interesting... π
yea, that's my biggest issue really, how feature discovery is achieved through experimentation instead of documentation rn π¦
Hmm
I'm using the NativeArray<bool> with just 1 element solution, and in jobs I just set it to true.
It doesn't throw errors or anything, I wonder how it deals with two threads trying to write to it at the same time?
@humble mason yeah stick around the channel, I'm in the same boat, haha.
Well potentially a race condition - 1 thread can overwrite the other thread, so if write into the index regardless of whether it's true it could be like true -> false -> false
thanks again for your insight!
Anytime!
But since I'm strictly writing true (and not writing at all otherwise), it's fine?
yea should be