#archived-dots
1 messages Β· Page 16 of 1
I suggest to check this guide to see whether everything is intact
https://docs.unity3d.com/Packages/com.unity.entities@0.51/manual/install_setup.html
@rustic rain seems to be fine
oh wait, I might've missed a step
yeah I did everything listed in there but I'm still getting the error
what unity version do you have?
2021.3.8f1
yeah it was recommended on some document
afaik this is deprecated package
I downloaded them with git url
oh I was following an outdated doc page
So while I'm at it, I'm gonna ask a question. I just recently started looking into DOTs and as far as I've seen, in order to create entities, most projects either use a conversion component on their game objects, or use a subscene that does the same thing behind the scenes. Surely this isn't the ideal way to build a scene with entities, right?
Subscenes are entirely the ideal way to build entities
subscene is the best
They are built AOT
They are very fast at loading/unloading
yes, uninstall dots editor. it's built in now
I can see some problems with this, including:
- Since Unity uses a monobehavior component for the conversion, it is done in realtime when the gameobject loads. It sounds very inefficient.
- Conversions can lead to unexpected results. I really doubt that every single GameObject in a complex scene will be perfectly converted just as I expect it to.
I think that subscenes are great, it's just the conversion part that I don't like. Why do I have to create a GameObject just do delete it and replace it with a similar Entity? It'd be much faster to just directly create an Entity.
are they converted before I build my project?
it's all happening at editor stage and serialized in an efficient format to load/unload
GOs can have very complex authoring scripts attached. it's up to you really.
I'm pretty sure that after you ship your game, the game program contains the game objects and they will be converted whenever you start the game.
the GO itself will be not exist during runtime. there are exceptions, like when you have the subscene open
that's not how subscenes work π there will be no GOs. especially not in a build
that only applies for component conversion
SubScenes are converted before you even hit run
no
all my authoring components are in editor only assemblies
subscenes are converted to giant blocks of binary data
and loaded from disk directly into the world
Where can I read more about how the conversion works behind the scenes? Every document I've read and video I've watched done a horrible job in explaining how it works.
when you build, these subscenes are stored in the StreamingAssets folder in individual files
as you point out, runtime conversion is slow and should be avoided and this is basically why subscenes exist
My main concern was the performance of converting in runtime, so I'm glad that it's not the case. But I'm still wondering if there are any alternatives to the conversion workflow?
You should look at the Gdc talk on this workflow in 1.0
you're alternative is to do it slowly with runtime conversion
or creating entities in code
both bad options
i still don't understand why all fresh dots developers instantly have a hate for subscenes
and it takes ~6months before they're converted
alternatives for what? what are you looking for? prefabs in the assets folder also work in subscenes. need to be referenced rhough to load
I don't hate subscenes, I hate the fact that I can't directly create entities within the editor. From what I've seen, subscenes have more uses than just converting entities.
they really are just for creating entities
This video covers the improved Editor tooling in the upcoming Data-Oriented Tech Stack (DOTS) 0.50 release, including the Hierarchy, Inspectors, Profiler modules, Systems window, and entities journaling. It also addresses a new Editor workflow, coming in Entities 1.0, which allows artists, gameplay programmers, and level designers to author with...
a subscene is exacty for that. creating entities in the editor π
watch this to understand what unity is aiming for
Can't I use them to create chunks for openworld maps with multiple LODs?
start at 17:40+ to see 1.0
in other words, can't you use them to create lots of entities and their LOD setups for large open worlds?
all you're doing is creating entities
i'm still on this one
works:```
var updateDurationHandle = new UpdateSpellEffect_Duration
{
SpellEffect_DurationEndTick_ReadHandle = GetComponentTypeHandle<SpellEffect_DurationEndTick>(true)
...
}.ScheduleParallel(mainEffectsQuery_Duration, Dependency);
var removalHandle = new RemoveSpellEffects
{
...
}.ScheduleParallel(mainEffectsQuery_Removals, updateDurationHandle);
Dependency = removalHandle;```
doesn't work:
{
SpellEffect_DurationEndTick_ReadHandle = GetComponentTypeHandle<SpellEffect_DurationEndTick>(true)
...
}.ScheduleParallel(mainEffectsQuery_Duration, Dependency);
var removalHandle = new RemoveSpellEffects
{
...
}.ScheduleParallel(mainEffectsQuery_Removals, updateDurationHandle);
var removalHandle2 = new RemoveSpellEffects_WithStats()
{
...
}.ScheduleParallel(mainEffectsQuery_RemovalsWithStats, updateDurationHandle);
Dependency = JobHandle.CombineDependencies(removalHandle, removalHandle2);``` RemoveSpellEffects_WithStats doesn't run because my test effect has no stats. maybe that causes the problems
We upgraded our game project from 2019.4 to 2020.3.38 and it's working fine -- except that builds fail, due to a bunch of errors about Collections, starting with this one:
Library\PackageCache\com.unity.collections@1.4.0\Unity.Collections\AllocatorManager.cs(237,37): error CS0246: The type or namespace name 'AtomicSafetyHandle' could not be found (are you missing a using directive or an assembly reference?)
The rest are similar, pointing to different scripts in Unity.Collections with the same issue. This is very strange since I did some test upgrades of the project and they had no trouble doing builds. Below are the packages installed. I found this thread from 2020 and tried what people suggested, but no help: https://forum.unity.com/threads/missing-references-in-the-collections-package.847027/
Any help would be much appreciated!
thanks
Dave
ENABLE_UNITY_COLLECTIONS_CHECKS
Do you have such define in settings?
yes, that's the last entry in scripting define symbols
can you try to turn it off?
oh, that define gets added back automatically -- that's expected?
is it added back to the project settings scripting define symbols? because that's usually not happening
yeah it should not exist in scripting defines
because unityengine itself will not include it internally
so all the safety will be stripped from unityengine
but you are including it in your code which is causing the issues
as far as i'm aware no unity library will add this to your defines so it's likely your code or a library you're using adding it
Ah okay! Will look into it. Thanks so much for the help!
something really weird is going on with this sytem and its dependencies. if i combine the updateDurationHandle it complains about another comp from the remove jobs. yet their handles are added. makes no sense. shit
you've broken something
it's likely nothing to do with your handles btw
exactly where is the error being thrown from
i can get it working when removing the RemoveSpellEffects_WithStats job
what does that job look like
ohhh, one step closer. the commandBuffer ```var updateDurationHandle = new UpdateSpellEffect_Duration
{
tick = tick,
SpellEffect_DurationEndTick_ReadHandle = GetComponentTypeHandle<SpellEffect_DurationEndTick>(true),
SpellEffect_Removals_WriteHandle = GetComponentTypeHandle<SpellEffect_Removals>(false)
}.ScheduleParallel(mainEffectsQuery_Duration, Dependency);
var removalHandle = new RemoveSpellEffects
{
LastSystemVersion = LastSystemVersion,
commandBuffer = commandBuffer.AsParallelWriter(),
Entities_ReadHandle = GetEntityTypeHandle(),
SpellEffect_Removals_ReadHandle = GetComponentTypeHandle<SpellEffect_Removals>(true)
}.ScheduleParallel(mainEffectsQuery_Removals, updateDurationHandle);
var removalHandle2 = new RemoveSpellEffects_WithStats()
{
LastSystemVersion = LastSystemVersion,
commandBuffer = commandBuffer.AsParallelWriter(),
Entities_ReadHandle = GetEntityTypeHandle(),
SpellEffect_Removals_ReadHandle = GetComponentTypeHandle<SpellEffect_Removals>(true),
SpellEffect_StatEntityBufferReference_ReadHandle = GetComponentTypeHandle<SpellEffect_StatEntityBufferReference>(true),
SpellEffect_StatElementIndex_ReadHandle = GetBufferTypeHandle<SpellEffect_StatElementIndex>(true),
SpellEffect_StatElementBufferIndex_ReadHandle = GetBufferTypeHandle<SpellEffect_StatElementBufferIndex>(true),
StatBuffer_Changes_ReadHandle = GetBufferTypeHandle<StatBuffer_Changes>(true)
}.ScheduleParallel(mainEffectsQuery_RemovalsWithStats, updateDurationHandle);
Dependency = JobHandle.CombineDependencies(removalHandle, removalHandle2);```
Unity.Entities.EntityCommandBuffer:AsParallelWriter () is throwing the error
yeah, damn. do i need two?
well in this case yes
because you aren't passing the job dependencies between the jobs
RemoveSpellEffects_WithStats and RemoveSpellEffects could both use the same command buffer at the same time
i thought this was okay with a parallelWriter
parallel writer is only safe
within the job
never with other jobs (nativequeue the exception)
silly me π
both jobs could use the same index
thanks so much! runs fine now
we really need stuff the equivalent of concurrent lists etc
not sure i agree
Why not? For example, It would be nice to pass a ConcurrentNativeList into a parallel job that can be resized.
no need for a parallel writer with no resizing abilities
use what all the time?
native list parallel writer
yeah but you cant resize the list
lists are supposed to resize. Of course NativeLists are not parallel-safe without the use of ParallelWriter which is fine. Just need an alternative that can be resized in a parallel job.
Yeah well, in the rare cases a resizable list or similar would be really nice to have.
only during a resize
it'd have to lock check
every time to see if it needs to resize
the same reason parallel nativehashmap
is so slow
16 threads on nativehashmap parallel writer adding can be slower than single thread for me
due to contention
and that doesn't even resize
it just has a shared buffer
there's nothing stopping you adding this container if you need
(well except it's extremely difficult to implement without lock)
you wouldn't, because you can interlock a pointer to an int that holds the current length, and a separate one for capacity.
yeah
so how do you lock the other threads
while you resize
and move the pointer
pointer indirection
and by lock check i mean interlocked
perfect use case
yes of course
but you still have to lock the threads
while do do a new allocation
remember, you can't use lock in burst
and you can't have 2 threads trying to resize at same time
and at this point, why not just use a nativequeue/nativestream
both which allow resizing
because they have per thread buffers
I could also do per-thread allocation instead of a single allocation for all threads to access
you've just invented nativestream!
and you want a non-deterministic version?
you can use my eventstream
which just allows you to write from any thread
without having to setup indices
or worry about thread safety
interesting
so you made the eventstream of what specific use case?
just those last two changes or what?
i can just write data arbitrarily from any thread
i use this for tooling
for example my draw tool from jobs
Draw.Line(x,y,z)
Draw.Circle
etc
ah ok I see
been meaning to make something that allows for me to draw gizmos a bit easier
rn I pass in a NativeList to write to, and then outside the job I append it to a gizmo drawing utility I made.
its fairly simple, but I would like to expand on it
I've suggested this a dozen times but
https://assetstore.unity.com/packages/tools/gui/aline-162772
basically same as my own tool
but save you weeks of development ^_^'
it's very similar to a nativestream. instead of allocating blocks it uses unsafeLists which can be allocated persistently to reduce some time
It would be interesting to try and replicate ALINE. Idk how do shaders or custom graphics, so I think it would be a good side project to learn
btw, if you assign to each job unique index offset you might use 1 buffer for all
I assume
don't think that's possible. the safety system complains long before i send anything to the buffer
the unique indices would work. i'm already doing that. the buffers work fine but I'd need to disable the safety system for it. considering how easy it is to just make a 2nd buffer it's not worth it.
Drawing isnt that hard. It's just so tedious to set up
@robust scaffold
Did you know about such constraints like
Unity.Burst.CompilerServices.Loop.ExpectVectorized();?
Yea? ExpectVectorized is a very rudimentary tool to check for vectorization if you're just starting out and learning to read the inspector.
Pretty much the only case where it works is when you're doing A[i] = B[i] + C[i].
I'm trying out the Physics package for the first time. On a blank dots project, inside of a subsystem, I created a ground with the default box GameObject. I then created a default capsule GameObject and gave it a PhysicsShape and a PhysicsBody. According to the tutorials I watched, the capsule should fall down and stop when it hits the ground, but for some reason it doesn't move at all.
Did I skip any important steps?
show your physics body component
the only thing that I can think of is that I didn't add a Convert to Entity component, but it shouldn't be a problem since I'm using a subscene
Just noticed this, maybe that's the problem
I'm not sure where to enable it though
found it and enabled it - It didn't fix the problem :/
i need to copy a buffer to a commandBuffer instantiated entity that already has the buffer (with a fixed internal capacity in chunk) did anyone already wrote an extension that takes an array instead of a single element like AppendToBuffer?
well, first of all make sure your entity indeed exists
they exist, I see them in the dots hierarchy
can you show inspector of that entity?
tags included
nothing happens when I manually change the translation component values, the object stays in place
yes
close it
closed and reopened, nothing happened
why reopen
well yeah, because you finally loaded subscene
why doesn't it work when I press play?
not sure, maybe physics is incompatible with live conversion
on the most basics entities it works normally
usually
yeah it worked in every document and tutorial I've seen
disabling live conversion doesn't seem to fix it
no I mean
you gotta close subscene
so it gets built
and loads as it is meant to be loaded in runtime
otherwise it constantly checks for changes and rebuilds entity (could be wrong on some details about that)
and when it comes to entities with complex authoring
it usually ends up with some mess
so ideally when I'm testing a complex project all of my subscenes should be closed?
for example if position is assigned in authoring - entity will be reset with position as soon as you modify it
when you test - yes
because this is 1 to 1 runtime behaviour
is there a way to make this happen automatically? When the subscene is closed I can't see and modify the objects inside it, but it'd be a chore to disable it whenever I press play and enable it when I finish running the game
you can see entities
in hierarchy
once it's built
that's basically all that matters after you close subscene
The current situation is that I need to uncheck the scene to get it to behave properly during runtime, but I have to enable it whenever I want to edit it in the editor.
Is there a way to make unity enable the scene in the editor but automatically uncheck it while the game is running?
uugh, that's some overcomplicated problem
sounds like basic UX to me
If I have a project with 10 scenes, it is unreasonable to ask me to uncheck all of them everytime I wanna run the game
but you don't want to have 10 subscenes open at the same time
you only want one you are working with
especially if it's large world
Oh yeah that makes sense
but that extra step of unchecking a subscene still sounds avoidable
probably doable with editor scripts
but I personally will most probably find that script inconvinient
which is why I it's weird that they didn't make it a builtin feature yet
because open subscene sometimes must be open for some cases
obviously it should be a togglable feature, maybe through the DOTS toolbar at the top of the window
absolutely, I probably won't need to toggle that feature very often
at least not as often as I'd need to uncheck my scene
also selection of what subscenes need that behaviour and etc
I really doubt that won't slow down workflow
if people don't want it they can keep it unchecked, but I can imagine that when I'll work on a subscene, I'll run the game every few minutes to see how things have changed. I can only imagine how many times I'll accidently run the game before I uncheck it
I don't suppose anyone knows why the DOTS.Physics.Plane doesn't have a Raycast method, how am I supposed to raycast to it then π
Wdym by raycast to it?
its a simple technique so you can get the position of a raycast at a specific distance
every collider has a raycast method in physics
if you just mean the regular raycast to plane, why not just use the one you always used
Raycasting isnt collider specific though. Unless you're trying to project a collider...
plane doesn't seem to π
Plane isn't the collider
Plane does have SignedDistanceToPoint though
is that all you need?
oh wait probably not
I mean I can just use the normal unity plane I guess but I thought I'd try and figure to use the DOTS one
or just implement it yourself
{
float a = Vector3.Dot(ray.direction, this.m_Normal);
float num = -Vector3.Dot(ray.origin, this.m_Normal) - this.m_Distance;
if (Mathf.Approximately(a, 0.0f))
{
enter = 0.0f;
return false;
}
enter = num / a;
return (double) enter > 0.0;
}```
all it's doing
Wait, shouldn't a raycast query the world bvh to determine collision?
he wants UnityEngine.Plane.Raycast method
I mean a plane isn't technically something that exists in the world
which is raycasting to a specific plane
you can cast to specific physics colliders with
PhysicsCollider.Value.Value.Raycast()
note collider is in local space though
hmm maybe it is better to raycast to colliders in the scene though π€
I will need to deal with different heights for the mousecursor
I'll try that, thanks for the help tertle π
Do you have a Physics World Index component? Should be added automatically from a Physics Body but I don't see it in your screenshot.
yes, the screenshot didn't cover everything
hmm, physics work fine for me regardless of whether or not the subscene is open.
I agree that it would be a pretty bad workflow to have to constantly open a subscene to edit and close it to run with it. That is definitely not the intended workflow for all use cases, although I could see it being beneficial for a large open world kind of project.
can any of you recommend a volumetric fog solution for urp?
@viral sonnet if you find a nice one ping me was also looking around for one
will do π
have you tried Ethereal? only one i've briefly looked at
have you used it? certainly looks like one of the better ones. also on heavy sale right now π
i think the stuff from the dev is quite messy/bloated. that's pretty much the reason why i haven't pulled the trigger on this one
HDRP does have volumetric fog built in if you havent tried that out yet.
then you have you use HDRP π₯²
It plays well with their global illumination supposedly.
HDRP is where unity is dumping millions of dollars. Might as well use it if you want these features.
HDRP is great, though kills performance
but it's great at realistic graphics
it's painful to use it for stylized work
If you're doing volumetric fog, I think performance has long since jumped out the window.
the perf has always been really questionable for me
just installing hdrp in a blank project halves my fps
from its overhead with a single plane and 1 directional light
now i can start adding a bunch of stuff to the scene without it changing much
also enzi was asking about URP
but the overhead is really rough
i personally never use any 3rd party plugins
Same. Makes me feel icky.
i might acquire them then rewrite them to fit my archetype / design goals
I code it myself or not at all.
but i find just dumping 3rd party libraries into my project just never quite fits or does what i want unfortunately
Coding things manually also allows me to know the exact limitations of the feature set I'm using. Since I was the one who set them. And if I ever wanted to push those limits out a little bit more, I know exactly where to begin editing / splicing.
it's a good learning experience as well
i don't need to come up with the algorithms myself, but taking someone elses work, pulling it apart and reworking it helps me understand what's going on
i also really hate hdrp's asset setting workflow. I honestly find it super confusing
Coding my own 2D physics engine made me really appreciate how smooth and well integrated unity's 2d physics is. Sure it's not deterministic but its ironclad functional.
URP's settings workflow is just why?
HDRP is integrated into the settings panel yet URP cant do that? why.
yeah it's all over the place
urp is the red headed stepchild but hdrp kinda feels like one too
yeah thats something that annoys me
URP/HDRP teams need to talk to each other
and unify things
seems like they're both re-inventing the same wheel sometimes
feels like my mess of a project, got multiple ecs particles, one based on vfx, one on particlesystem, another one where I used graphics.drawmesh, none talk to each other and all replicate functionality to a varying degree π
Looking at compiled compute shader code makes me wish the guys at burst inspector took a look at making a shader inspector as well
what's cool about it? i never looked at one
It's very similar to burst.
The issue is, no comments get transferred over so I'm stuck trying to figure out what line matches what command
oh, that's how you meant it. yeah, that looks bare bones as hell π
That's only for 5 lines of code. Actual shaders is just this blob:
Not sure if it's been shared here:
https://www.youtube.com/watch?v=V3UrSEnk5bo
https://prf.hn/l/ERLGO3O - Don't Miss the Unity Innovation Sale!
https://game.courses/beginner/ - Free GameDev Course for Beginners
https://bit.ly/3sKGagG - Game Architecture Course - Advanced Course
http://unity3d.group - Join the Group (facebook)
https://www.youtube.com/channel/UCX_b3NNQN5bzExm-22-NVVg/join - Join the Channel
Talking with Uni...
he mentioned dots so that's some good news
tldr: ?
I've only watched the beginning part but he mentioned dots briefly as there internal build strategy
I mean if there is still any dots doubters it at least means dots is here to stay
Still listening/pausing/working/listening..
One point he makes is on potentially commercializing or pushing DOTS a little early, before it was ready - i think hinting at the fact that people have essentially waited in the dark for long period to see more progress and updates from DOTS. However he counters that by saying that looking at the Steam charts 2 out of the top 20 PC games were DOTS games, and in fact 13 or 14 out of the top 20 were Unity games.
Overarching push for the engine is definitely - asset loading/pipeline performance, UI and stability, big focus on networking and multiplayer, and the render pipelines.
Well he said 2 out of the top 20 'last time he checked' were dots games, not necessarily the top 2 games
yeah i know
v-rising would have been 1
i don't know the other game that uses dots
i don't think cult of the lamb uses it
at least i see no reference to it
maybe the other one is that war game that was posted in the forums
ah i see what you meant there yeah
ok maybe its still in early access I was thinking Diplomacy is not an Option
that definitely uses dots but i'm doubtful it made top 20
it's done well but currently top 20 is games with 15-20x more sales
yeah
The Long Dark seems to use burst at least
was released in 19 though
well i've found a few upcoming games on steam that use entities
i guess it's possible some games are quietly using dots maybe for small but important workloads ie AI/networking/whatever.. he did mention Unity have literally hundreds of developers working directly with customers so there's a good chance of that i'd think.
Unoffensible
Operation Valor
both use subscenes
but definitely not what they were talking about
yeah I bet there is loads we don't even know about, dots is way to useful
not dots specifically but he name drops this dev who's doing some cool stuff with shaders/fx/pipelines - https://twitter.com/Sakura_Rabbiter
there is some bloody lovely stuff on there. it's these kinds of artists/devs that will propel the upcoming capabilities of unity right up there with the best looking game titles
maybe finally get past that whole 'unreal has better graphics' thing
she seems to be hinting at stuff that looks to be on a par with for example Death Stranding
its great when something just works and I'm not even sure how
just reused some old code and a couple of new lines and I have the new cursor obeying the different heights of objects
is this maybe the guy behind it, or one of:
https://www.youtube.com/c/melvmay
still confused about the collision filters though π
in ecs physics?
Yeah
it's just mask check
32 bits vs 32 bits comparison
for collision/trigger you need it to be > 0
I made two objects with same collision filters and I get different results when using them on a ray cast
for objects to collide
you need one object to have collides with, which overlaps with belongs to of other
if you make both filters everything
on both entities
they probably should collide
Yeah I want the ray cast to ignore certain objects
for raycasts i've just created a static class with some filters that just add to when needed and then grab inside OnCreate..
for prefabs etc i try and always use PhysicsMaterialTemplates rather than set layers inside the PhysicsShape component, to keep things as consistent and organised as possible
But I don't think you should define raycast layer
it's just something i've always done tbh, not sure if it's necessary
that layer is only ever used for raycasts, so i can set up the raycast knowing for sure i'm only going to get results from the CollidesWith mask
I'll have to try it that way, thanks midnightcow
Are you adding those collision filters to entities in code then
No i'm using the PhysicsMaterialTemplate assets for that - #archived-dots message
With the exception of the static in the above code called filter_Col_DeadRagdoll which i apply with code
For that i clone an existing collider and apply the filter to the clone
Interesting, I will definitely have to try that, thanks
No problem.. i just find it more manageable and cleaner to define all those raycast filters in one place.. they can then easily be edited or reviewed etc
Yeah I was starting to get confused with creating different special entities to deal with the collision filters
did I dream this? I thought not long ago a post was made about the hybrid renderer and it would be renamed Entities Rendering or something like that, but now I cant find it
Yes this was posted
They deleted the post. I was the first person to comment on it and I no longer have that comment in my profile history.
thanks, kinda thought I was losing my memory there
I really hope this means that they're just fixing some last minute bugs and not... re-entering development hell.
Ugh, I cant do it. mono is pain. Reinstalling dots...
heh tried to go back?
I'm gonna have to figure something out for conversion. Since I'm sticking with built in non-dots physics 2d, I wont be using the conversion system as everything will remain GO except for data components.
what happened to your physics system?
It functions, just not as well and as smoothly as I prefer. No continuous collision detection. Too complex.
I can do it except I just wanna move on ya know. I'm also trying to implement a real time fluid sim as well.
Bad performance. Might as well just use the GO version for same performance.
Which is what I'm doing.
Bad performance? Hhhm
My physics has phenomenal performance dont get me wrong. It's deterministic and very fast up to simultaneously colliding 15,000 entities. Beyond that it starts to chug a bit. But it's not very smooth
No friction. Only forces. No polygon decomposition.
I was referring to 3d
so do box colliders get auto converted into physics shapes?
into a physics collider, yes
damn because I need the box colliders but not the physics shapes because they are conflicting with physic shapes on other entities
what do you mean?
you're mixing physics?
I'm using the box collider in a weird way I'm converting and using that data as obstacles for a flowfield
you could write a conversion system to remove any converted physics components from it
yeah or delete it(I don't want to just in case) or I could add a physics shape and then exclude that object from any interactions I guess π€
ok adding the physicsshape doesn't seem to work
Hey everyone! Is there an analogy for Debug class for DOTS? I'm trying to debug systems and I can't make them send any output. I've tried to make a BurstDiscard function and debug from there but that didn't work (the Debug.Log is not called). Is there a debug output method provided by the developer? Or should I implement my own? (or is there someone who solved that problem and have released the code publicly?)
Debug.Log should work fine in bursted jobs if your using a string you have to use something likeDebug.Log($"Words here"), though
static strings are fine (your example would be fine without $)
but if you want to output something then yes you need to do it like that ($"Value = {value}")
That's funny, because this Debug.Log("Words here") throws and error
it shouldn't
what version are you using
it's been supported for over 2 years
and what's the error
Primarily, what's your burst package version
Oh... That's weird. I've just made this again and it worked.
No error, and it works fine.
-_-
Sorry, this is embarrassing))
you probably did something like Debug.Log(value)
where value != string
which is not allowed
you'd have to log it as
Debug.Log($"{value}")
Probably that what it was. Thank you for this information also!
I am having a slight problem with a memory leak when using a static class to store a NativeArray of floats (for rng) when recompiling or domain reloading. anyone know the correct way to approach this? basically I generate _0to1float = new NativeArray<float>(512, Allocator.Persistent); and then in [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] call dispose but anytime I recompile I seem to get the mem leak from the class
you should generally avoid statics with entities - especially with native memory
so now that I've tried to dissuade you and you'll ignore me and it might come back to bite in the future the easiest solution is just to subscribe to Application.quitting and dispose it in there
Anybody familiar with this - when placing one object on top of another, the object slides without any force applied?
Yes, but i still don't know why this happens
How can a box collider on an object that already has an physicsshape interfere with collisions?
is it possible for an entity to have more than one physics shape on it
add children to transform
without physics body
and it'll be combined shape
yeah I don't want to add or combine anything I just have an issue
I think if you have both a box collider and a physics shape on an object then it only converts the box collider
I'm using the box collider for my flowfield
no I can't control the collisionfilter on the box collider so I was hoping to add a physics shape so I could control it
you can change it
during conversion
not sure about consequences though, since you might have multiple shapes shared
yeah I was just seeing if I could do anything without coding first
simplest way is probably to just disable the entity
what are you even trying to achieve?
maybe you just need to set up game object layer?
which corresponds to bit that is what you look for?
yeah I'll figure something out, thanks
I had completely forgotten about this setting, but it fixes the sliding problem:
it is possible to create a box collider in code something like this:
BlobAssetReference<Collider> boxCollider = BoxCollider.Create(boxGeometry);
might be easier just to do that than messing around with conversion
@devout prairie @floral hazel its because Unity physics is stateless(docs should further explain this), havok doesnt have this problem
ahh yeah i guess that makes sense.. so i guess the Contact Solver Stabilization introduces a stateful component to solve this problem
yeah, can lead to some weirdness like if you move the bottom rigidbody out jenga style, it will continue to float there
i think
it does that? that's same class A minecraft physics
Hey everyone! Is there an opposite of RequireSingletonForUpdate function? Like DontUpdateIfSingleton? I can just add
if(HasSingleton()) return;
to OnUpdate, but I wonder is there a scientifically correct method?
Nope don't think so. One way around this is to set up a singleton that represents the absence of another singleton. Basically one singleton type per state. So when you remove one singleton, you add another.
You can also use RequireForUpdate and pass entity queries instead. These queries still need to match an entity, but you can match against an entity that specifically does not have your optional singleton component
Something like this:
// Run when MyOptionalSingleton is present.
RequireForUpdate(
GetEntityQuery(
new EntityQueryDesc
{
All = new[]
{
ComponentType.ReadOnly<MyAlwaysSingleton>(),
ComponentType.ReadOnly<MyOptionalSingleton>(),
},
}
)
);
// Run when MyOptionalSingleton is absent.
RequireForUpdate(
GetEntityQuery(
new EntityQueryDesc
{
All = new[] { ComponentType.ReadOnly<MyAlwaysSingleton>() },
None = new[] { ComponentType.ReadOnly<MyOptionalSingleton>() },
}
)
);
Thank you!
is it possible to use unity Starter Assets - First Person Character Controller in ECS? does it need any converting/porting work?
or failing that - what would be a good free FPS controller anyone might recommend to use in ECS please
No, I don't think that asset was built for ECS. I assume it relies on built-in physics and monobehaviors for everything. Assuming you are trying to make a mostly pure ECS game, you would need to convert it yourself. The only DOTS/ECS character controller on the asset store that I know of is this: https://assetstore.unity.com/packages/tools/physics/rival-dots-character-controller-195567
i see
wondering - do i need to make a mostly pure ECS game?.... ex; big open world scene with lots of collidable stuff like trees & rocks etc. as well as plenty of other objects & structures like cabins trailers tents beach balls tables chairs and more
~lots~ tons
i'm trying to target mobile so am hoping ECS might help boost performance for such an open world scene with lots of props & stuff in it
@whole gyro βοΈ
what is more accurate description of dots/ecs functionality:
"port all of your Update() processing off the main thread into worker threads, if you can fenagle all the relevant data into concise streamline-able chunks for blazing fast memory access"
well then if my scenes dont have 70000 moving objects or enemy minions etc., rather has mostly static props/objects/decorations with maybe some fancy vertex shaders at most but no specific Update() processing - then i gain nothing from ECS?
Or - if dots/ecs also does all your Rendering and Physics and other under-the-hood Unity stuff with blazing performance compared to non-ECS, then it will make a significant difference for my game too?
ECS is a great way of programming that makes your code much easier to expand. The increase in performance is just a pleasant bonus.
hm π€
working in the "easy for noob (like myself) to understand GameObject hierarchy" is also "much easier" for its own reasons... and if i only have pretty much just 1) player FPS controller, and 2) at most 20 or 30 enemies in scene at a time, and almost nothing else around that is running MonoBehavior Update() scripts at all, then perhaps i really have nothing to gain from ECS?
Probably. ECS is for advanced users and for bigger projects.
i'd love to find out that using ECS might give some awesome advantages in like how many graphic decorations i can have in my scene, or how much more i can fill my scenes graphically for Mobile performance, but if ECS's effectiveness is mostly in regards to Update() methods, and i dont have that many of those...
Well, if you mostly use static geometry then yeah
i think i might, in this particular project..
But if I'm not mistaken, every dynamic object has an update somewhere
"dynamic" as in? anything that's a GameObject with a transform? even if it has no script attached, it still has some Update() under the hood?
and if one were to use ECS then it "optimizes" that Update() out?
Well, i'm not sure. Again, how interactive they must be? If you just place them and turn them into a static mode, than they will be very cheep. If they are not set into static mode... Then how exactly they will be interactable? Will they move? Will they have physics?
physics yes, but most of them static, as in trees or rocks or huts etc which you cant walk through wood/stone/walls etc
maybe a few items to throw around like beach balls or such
but mainly the game is just 1) a scene as the playground 2) player 3) enemies, not much else
If I'm not mistaken ECS upgrades physics performance, although ECS physics is still work in progress.
No. Rendering is just Unity itself (as far as I know)
how about maybe using ECS for scene optimization computations/techniques etc? for example if my scenes are gonna be vegetation & prop heavy, loads upon loads of trees & grass etc., maybe i can deploy an army of ECS components+systems to do raycasts or run around the scene calculating occlusion and other culling techniques, enabling & disabling objects to achieve awesome performance optimizations? anything like that make sense to put into ECS processing? or that makes no sense and should only be done in regular scripting
It could be done in ECS, yes. It could be done in regular code also, using jobs, but ECS would do that in a more organized manner (and probably faster)
interesting
can ECS do a bunch of raycasts for me more performantly than regular FixedUpdate() code might?
more importantly: should i move my entire game into ECS for this, or would it be fine and be just as performant to have most of the game world in GameObject hierarchy and the "army of ECS optimizers" operating on them "from the side" so to speak?
from my experience converting an existing game without completely rewriting it into entities will end up running slower
you just end up with the overhead of both implementations and a really awkward interface between them
you'd be better off just using jobs/burst to optimize an existing game and ignore the entities side of it
you can use RayCastCommand https://docs.unity3d.com/ScriptReference/RaycastCommand.html
to do a lot of raycasts on default physics in parallel
right
actually in my case i havent built the game yet
still deciding which path to take
very cool
ECS is cool way to write project. But Unity ECS is alpha/beta state. So almost all thing you'll have to reimplement yourself. Project will be way more advanced compared to classic unity approach.
Performance wise Unity ECS is great. And it's the easiest way to write almost fully threaded project.
But to achieve that: say goodbye to classes and say hello to structs, allocators and pointers
i see
i would agree with Tertle and Issue above, especially if you are a noob ( i think you mentioned this ) - ecs is a great approach to learn and can catapult performance but it loses all of the benefits that make OOP in Unity so easy and accessible. I would probably suggest build your game in the usual way and then start looking at where you could benefit from jobs and/or ecs
I'd love someone ( or myself if i had time ) to do a full writeup of their experience of ECS and some comparisons showing clearly where ECS can potentially be better and faster to write and more organized, but also honest comparisons of areas that are just exponentially more complex and involved - i know both cases exist.
Is there another object like a nativeArray but that can have more than int.MaxValue elements on it? Or I'd have to make like multiple native arrays
isn't that like 8Gb of mem for one array already? π
I mean it's an array of bytes
So it's more than 2 GB
Or it could* be more than 2 GB
Sorry I donβt know the answer except Iβd be very surprised if thereβs an existing native container that uses eg a long for the length. You could try and make your own or yeaβ¦ multiple.
I have some questions about querying and iterating over entities:
I noticed that in many cases, people use lambda expressions over for/foreach loops. I'm used to thinking "lambdas = cool but inefficient", but I'm assuming that the burst compiler is making them as efficient as for/foreach loops?
I also wanted to know how the querying works behind the scenes. If I have a system that iterates over all entities with a certain component every update, how does it cache the queried entities between update calls? Does it save the query result in a separate collection?
lambda is codegen
they are generated into IJobEntityBatch which is fastest
thanks, I'll read about IJobEntity more in the docs
Is there any documentation on how to get the test runner to work for DOTS? I have subscenes that need to be loaded for a playmode test, but loading the scene using the scenemanager in either SetUp or OneTimeSetUp does not seem to load the scene correctly
Hello!! Is there any info comparing between Async and Jobs? What I got from my search is that Async doesnβt stop main thread while Jobs doesβ¦ is that the main difference?
jobs are burstable multithreading
async is just async code running asynchoniously
Still runs on the main thread right?
by default yes, but you can ship process to background thread afaik
in short
async code is for smth like UI code execution (so it doesn't block game process, while doing smth expensive)
while jobs are for game logic
and not only
Hmmm I see, I was wondering if there was a way to use jobs asynchronously because of it being multithreaded but still didnβt want to stop main thread while doing it
The simplest example to understand async (by my perspective) is:
async void Kek(){
OpenLoadingScreen();
await StartNewGame();
OpenGameScreen();
}
Just call the job inside a task and spin wait the task until the job is completed
so while your new game loads, loading screen will function normally
and once it's done open game screen
Whooo thatβs interesting!!!
Thank you so much for the help you all!!!
Iβve been searching but never understood well now I got the grasp of it hahah
yeah, understanding async is smth really new to some people
TOok me a while after reading microsoft tutorial 10 times xD
I imagine, it confused me so much the first time I saw an example of it XD
Here's a very barebones example: https://hastebin.com/hixiyejulu.csharp
It should be !handle.IsCompleted though, I missed an exclamation mark
Also since you asked this earlier, if you want to run non-job code outside of the main thread, you can use Task.Run
Is it efficient to add/remove entity components often in runtime?
There are more efficient ways, it depends on your requirements imo
as long as it's not every frame
because every time you do structural change - all caches for all queries that are affected is gone
which ones will be affected if I remove a component?
the queries related to the entity or just the ones that are related to that component?
I'm thinking about making something similar to a movement state machine where every state is represented by a component
Which means that everytime a character jumps or performs an action, I'll need to remove the existing component and create a new one
all that contained that entity
because those queries contain chunk where this entity is
or was
I feel like there are a lot of projects where the simple approach (e.g. bullet = entity) will cause the game to create and dispose entities every frame. I hope unity optimizes entities enough that this works for projects that don't have crazy performance requirements
but it's already ok
you don't create bullets every frame
Im using an "unsafelist" in one of my entities components... However, when i remove or add items to it, it only updates for that instance. Is this behaviour intended ?
A unsafelist isnt a value type, so it shouldnt require a .SetComponent operation ?
I hope my issue is clear, cant provide an example rn... On my phone
An unsafe list is a value type, so you need to pass it as a ref value incase you call functions like Add or Remove, since it contains a length field used to index the pointer to the heap memory
If you copy it as a value type, you will only modify the Length property on the copy, not on the original object, while still writing to the same memory location (unless you write so much that the list requires copying your contents to another buffer with more space, at which point both copies of the struct will point to different memory locations)
Ah thanks, that explains that mistery behaviour... So i actually need to call .SetComponent once more to make sure the updated list gets passed to the component
I mean it works well enough in nordeus to do so?
Yes, my point was that that should be the goal, since it is also what unity kind of alludes to in my opinion, with their demos where they spawn bullets as entities
There are lots of workarounds that are more performant, but harder to implement. The "easy" way should be the default one though imo
unsafe list updates it's pointer during usage, so gotta write back, or else old value will point to invalid memory
Are there official opensource repositories for Unity Physics and other first party DOTS-based systems?
oh sorry I should've phrased my question better. I meant to ask if any of these systems are opensource.
There 's an old one for animation too, but dots animation is on stand-by
Yes ? It's on github so you can explore the source
And you can see the packages cached in your Unity project too
Is that what you meant ?
by these systems I mean Unity Physics/HybridRenderer/etc...
can I fork it and make my own versions?
In legal terms, they aren't "open source". They come with the Unity Companion License. But the source is freely available and you can use the stuff in your own commerical games and unity assets.
Technically speaking yes, but check Unity licence
Yeah Graviton said it better than me
ok ty!
The two github repos linked by @karmic basin are for samples. The actual ECS, Physics, Hybrid repos are all private now (they changed their mind a year or so ago). Someone has mirrored all of the repos from the package manager into github repos like this one: https://github.com/needle-mirror/com.unity.entities You won't be able to see the issues, PRs, etc., but you can at least browse the code and fork all through github if that is what you are looking for.
Oh missed the fact they went private
I don't dots these days π
You can still inspect local packages files, right ?
I guess but you can't fork them unfortunately π’
yeah you can still browse them locally after installing the package
Which system handles loading the actual scene? Is it not SceneSystem?
If I manually tick the world a couple of times it should eventually load the scene right? as long as all systems are present
yeah
are there any other systems I need besides SceneSystem and SceneSectionStreamingSystem?
probably a few
ResolveSceneReferenceSystem at least
oh that might only be needed in editor
WeakAssetReferenceLoadingSystem
there's a lot of stuff in the scenes assembly
I think I'll just create whatever is in the scene manually
It's for testing purposes, this seems too complicated for that
TIL UnityEngine.Time.time != SystemBase.Time.ElapsedTime 
which was never an issue for me when I was creating worlds on start up lol
but became an issue when I deferred world creation and introduced subtle time bugs that took forever to track down π
is there anything else that needs to be done to add a physicsCollider from an authoring component in script other than just creating a (in this case box) BoxCollider and adding the componentdata to an entity?
var boxProperties = _shape.GetBoxProperties();
var col = Unity.Physics.BoxCollider.Create(boxProperties,filter);
var colComponent = new PhysicsCollider {Value = col};
physics world index
ahh yes! thank you i knew i was forgetting something
I'm having some issues with collider casts, for some reason it's not hitting the first object even if I have EarlyOutOnFirstHit is true
Actually, it seems EarlyOutOnFirstHit is set to false in the closest hit collector. How does it find the closest hit? By overwriting max fraction with the hits fraction until no hits are left, skipping those that exceed the current max fraction?
Ok, nevermind, with EarlyOutOnFirstHit set to false it works >_>
Hey everyone! I have a question about System Groups. From what I've read system group has a sync points at the beginning and at the end. Does it mean that I can through my systems into a group using [UpdateInGroup] attribute, and the group will await until all the jobs are done before moving forward?
SystemGroups don't cause a sync
(well technically they would if you added logic into them but generally you don't do that
the 3 primary system groups, initialization, simulation, presentation all have commend buffer systems at the start and end of them
that if you use, will cause a sync point
So, I have to write my own sync points, right?
dependencies are automatically handled with jobs/systems
if you have a systemA with a write dependency on X, and systemB updates after with a read dependency on X, systemB job will not execute until after systemAs job
if systemB dependency was on a different component though that systemA was not using
then systemB job is free to execute at the same time as systemAs job
Oh, ok. So, a lot of time I don't need to. I just have a thing where I need a bunch of systems to all finish the execution before proceeding to the next thing, and I couldn't find any other way to ensure that they are all finished except manually syncing them through job.Complete.
generally you should never need a sync point unless you need to do work on main thread
and they should be avoided
Well, I have a bit of logic that should be deterministic so I feel I wouldn't be able to do it all completely without some type of sync point. It's level loading sequence and currently it works a bit like coroutine with multiple "steps", containing multiple systems. The code execution should only move to the next step when all the systems from the previous one are finished. The coroutine will not work continuously. Only on demand.
I feel like that all goes out the window as soon as you have entities created or destroyed every frame, which means you need a sync point anyways
what about the scheduling do you think is non-deterministic?
entities is deterministic
Ok. Simpler question. SystemA.Schedule -> SystemB.Schedule -> SystemC.Schedule. I need SystemA and SystemB to finish their logic before the SystemC starts to execute. If I just Schedule one by one, will that work?
I feel like for your loading system it might make more sense to just create entities in each step that signal other systems to do work, instead of doing the scheduling manually. but it depends on performance requirements I guess
are you talking about the jobs scheduled in SystemC
or the Update() scheduled in SystemC
if you mean job scheduling as long as SystemC has any component dependency on A/B it's job won't start until A/B has finished
That's the problem, I can't know. I'm basically making a moduler system, where modules will put their own systems into loading pipeline and the pipeline doesn't know about any of them, so it can't have any dependencies. I'm currently solving this by making a sync point, putting job handles of each module system into it and then making handle.Complete. I can't find any simpler way.
yeah, I'm doing that too
my first thought is, something smells wrong
ECS principles are generally that systems shouldn't need to know about each other
as soon as that principle breaks i consider it a flaw in design
I mean there are even exceptions in unity's own systems
e.g. physics needing to know you are using collision worlds
they specifically stopped this requirement
by adding a component dependency
Ah cool
isn't artem designing a loading mechanic? i think having some system dependency is okay for that
I always thought that was weird
What's the component called?
you know how they have the whole this.RegisterPhysicsRuntimeSystemReadOnly();
yeah
all that does is add a dependency
/// Call in your system's OnStartRunning() method if you only want to read physics runtime data from the default physics world
/// </summary>
public static void RegisterPhysicsRuntimeSystemReadOnly(this SystemBase system)
{
system.GetSingleton<PhysicsSystemRuntimeData>();
}
/// <summary>
/// Call in your system's OnStartRunning() method if you want to read and write physics runtime data from the default physics world
/// </summary>
public static void RegisterPhysicsRuntimeSystemReadWrite(this SystemBase system)
{
var cData = system.GetSingleton<PhysicsSystemRuntimeData>();
system.SetSingleton(cData);
}```
on PhysicsSystemRuntimeData
Ah, I see. I never went to check what it actually does
Wait, how does this work exactly? Does SetSingleton add a write dependency for the component?
yes
Ah, I thought it just wrote the component as a sync point
all calls to GetEntityQuery, GetComponentDataFromEntity, GetComponentHandle, GetSingleton etc
adds that component to the system dependency list
So the physics system has just has a write handle on PhysicsSystemRuntimeData?
yes
on the build system
(which is what runs first)
i expect in 1.0 you'll be reading the physics world from the runtime component as well
instead of getting it from the system
i actually wrote my own version of this way back in 0.17 start of 2021
https://forum.unity.com/threads/automatic-dependency-management-and-isystembase-support.1045105/
Ok. Now I'm confused. I can't imagine how to implement some forms of sequential logic without making sure previous steps have been finished before the next one have started. Is there any example of full cycle level loader? By full cycle I mean an example where I can order a level loading, the game will save the player's progress, unload old level, clean up all the mess, load other level, load the player's progress and start the gameplay, all using exclusively Job.Schedule and no artificial sync points?
Or at least examples of something similar?
take opinions as guidelines and not fact. implement what you think is right. if it works, it works. refine as needed.
imo this is usually handled by event entities rather than system dependencies
i think netcode or the dots shooter has good examples how they handle it
but do whatever works for you
What's keeping you from just creating an entity after each step that the next system has a dependency on?
(also I am definitely a purist so take my advice with a grain of salt unless you have a strong strong interest in software architecture)
I'm doing that in fact. The problem is, some systems should work in parallel and some are sequential. So, using singletons as dependencies work for sequential logic but doesn't help with parallel stuff.
I'll look into that. Thank you!
I'm not sure I see why this is an issue? Just schedule them in parallel inside the system
i don't see the parallel problem. a single entity can trigger a system to run and that system processes a set of entities in parallel with another query. (that's expecting that the set of entities that are processed in parallel always exist. if not, and they are created in the loading chain, the single entity to trigger isn't even needed)
Since they don't have a write dependency all systems with a read dependency will be scheduled in parallel
It's more like five systems run their jobs in parallel, but system number six should ONLY start when all five have finished. I've asked this question before, and if I'm not mistaken you've suggested the solution. I'm using singletons and singleton dependencies to manage the sequence, and any time I need to run multiple systems in parallel, I just gather their job handles in a single system, call Complete, and then set the singleton for the next step in a sequence. It works, but I'm looking for more correct ways to write the code in dots. I feel that what I've done is at leas somewhat the way Unity intended it to be done, since I'm constantly see this trick in a lot of examples, including adding dependency to command buffer simulation system.
Just create a unique entity for each of the five systems and have system six acquire a dependency on all 5 entities
system six will only run once all others are done
yeah, i remember it was one of the suggestions. if you don't want to screw around with creating entities i would just use job handles as dependency. the only real problem is that with more systems, job handles have to be shared.
Ughhhhhh, I really want to return to DOTS but the fact that it doesn't work well with a custom rendering pass is absolute pain
Frankly, the main issue I'm going around in circles about is DOTS's support for a hybrid GO/Entities style moving forward.
I have to admit, after all these hours, Unity's 2d physics is very very nice. So is their sprite rendering pipeline. But is it worth squishing these two ecosystems together?
I think it depends on the project
I use the monobehaviour sprite system but use the DOTS physics system
I think for now until 1.0 is released, I'm gonna keep my dots-style monobehavior/GO setup. It'll be relatively painless to convert everything to DOTS when unity reveals their made-for-production hybrid pathway. That or they restart tiny development.
Tiny / dots physics 2d has infinitely better potential simply because they can pull the internal collider info from within the engine and not re-invent the wheel when trying to convert composite colliders.
Yeah I'm really interested in what 1.0 will bring on all fronts. ease of use, and all the non-code stuff that is still mainly missing (animation, sound, etc)
100%. All that non-code engine features is really key to what I need to do.
Yeah I'm pretty happy I have no special rendering requirements or anything, so I haven't really run into that issue
I just plan to use the normal sound stuff for sound
same for particles and stuff like that
Basically everything π
Hopefully this new guy working on the DOTS training samples will update their entities version to the latest internal so I can see what they've improved over the last month
particles and graphics is really annoying. render textures can be converted to ints but compute buffers require extern functions and thus must be classes.
Sprites are fancy enough graphics for me π
The only "fancy" thing I did is a 2D shadow system and that was like 3 lines of shader code
(which is where I hit my limits)
Pretty happy with how it turned out though
My 2d shadow system is the one bright spot in my entire code. Very happy how my system worked out. Hundreds of lines of shader code.
I just converted my light entities into a nativelist<data>. Easy enough to reverse it if DOTS 1.0 comes out amazingly
I only needed sun shadows, which not very many shadow systems can do (iirc I couldn't find any on the asset store), so I made a very simple version
this looked interesting but I did something else in the end
Interesting. My art style is 2.5D but i've coded my lights assuming top down 2D. Might be interesting to consider.
The project I'm working on is top down but the scene is 3D which makes lighting a lot easier
True. And built in global illumination that actually works. 3D is very tempting. Extremely just for GI. But then I would have to use HDRP...
I've never thought of using GI in a 2D game
But then I wouldn't have to invent everything myself. But there's no tilemap editor in 3d. Ughhh. So much to consider.
I mean you can use the normal tilemap editor as long as it's not truly 3D
at which point it would probably need to be mesh based anyways
2D GI can theoretically compute infinite light bounces. That's called 2d Radiosity and there's a lot of neat videos of attempts to code it online
I had to learn radiosity for a lecture but I never thought about it in non-3d space
However, realtime 2D radiosity relies on temporal AA as they're all largely raymarching algos and moving the camera is a definite no-no.
I've matched the effects of 2D GI soft shadow lighting by simply rendering in 16 or 32 lights in place of 1 point light but imitating wall bounce illumination has so far been the hardest challenge.
I like the approach of just putting more light in one place π
Yea. What is a light source other than an infinite amount of point lights?
true
whenever I think of complicated rendering projects I always think of this guy: https://www.youtube.com/watch?v=8ptH79R53c0
it's pretty nuts imo
It's mainly this guy I want to copy
Issue is, I think he might have kicked the bucket back in 2018. Or fallen completely off the internet then with the radiosity code still locked in his SSD forever lost to time
as is usually the case with these hobby projects
At least he released his fluid dynamics code with arbitrary walls. That's the only example of open source fully featured fluid sim I have ever found. Great reference
well he made a public github commit in oct 2021
That was dependabot
Yea. It's frustrating how fantastic his demo videos are and promises to open source it when he's happy with the results. Then nothing...
Something I'm also really looking for for DOTS 1.0 is some officially supported way for save states
what do you mean?
serialization?
yeah
i wouldn't hold your breath on that one
Im fairly certain you can serialize the entirety of a world then load it again.
Yea, as long as you dont use blobs
What's the easy way though? just iterate over everything and write it?
Simple enough, dont use blobs.
it breaks as soon as you make any component change though
also this ^
a single change in any StableHash and your binary data is dead
Pretty much. Iterate over what's important and write manually to a save file.
i will probably release my save library come 1.0
i've started testing in a more production environment recently - it's holding up well
You'd also have to write some additionally header stuff for prefabs I assume
imagine testing. I just release and say, this may work, this may not. It works on my comp. No support, no fixes other than what I want. Good luck.
there's an obituary for a thomas diewald but he would have been 66 in 2018. unlikely that's the guy
but yeah, strange he seems vanished. pretty sick repo/videos
Yea. What's there is fantastic. What's not is so tantalizing yet probably lost forever.
Something I was wondering recently, is there an easy way to "pause" the entire world without manually ticking systems?
GetExistingSystem<SimulationSystemGroup>().Enable = false
There's 3 main system groups. Select all three and set the enable to false.
That... makes sense
How are you storing prefabs in your save system? just doing something like netcode, storing a guid for the asset?
pretty much
i have unique identifiers per subscene (also a global one)
automatically calculated during conversion from unity's GlobalObjectId
My setup is so simple I think it should be pretty easy to make a basic serialization system
I only have a single subscene that I use, and everything is procedural
Main thing to watch out for is how to handle system state stuff
i require static archetypes like netcode
as in, by default you can only save what's on the prefab
you could write your own extensions easy enough
but my default auto save components/buffers just using the [Save] attribute
require this
also have migration setup for component changes etc
i did a lot of work on this
What's the reason for this?
well i believe you should have static archetypes to start with
and it makes everything super simple
and super fast
i can save 100k entities in 20ms
Yeah, I would do it just for simplicity purposes
i don't need to double buffer this or anything
and since I use netcode it's required anyways, like you said
i can do it in real time
i can do real time rollback
which wasn't the intention of the library
haha
i just saw the rollback post on forums and thought, yeah my library could do this
System wasn't designed for rollback but thought it'd handle it ok so gave it a test. 1875 cubes.
this was an early test
i've since significantly improved it
i grabbed unitys boids sample
increased boid count by 10x
and use that as my test now
I think youtube recommends your video to me each day
it's like a curse
which is odd since I already watched it
so satisfying to watch haha
what's the size of those save files?
im not writing to disk for rollback
but pretty big even after compression at that entity count
i wouldn't do more than a minute of data π
let's see if this works
yeah my bypass no nitro file limit trick π
Ah. I'm doing a large simulation and would love rollback capability. If you somehow magicked together some some or compression, I would've loved to see if it could work with deterministic netcode synchronization but if it's only on memory, oof
yeah it's literally serializing and just storing each frame in a native array of bytes
for rollback sample im not even compressing
yeaaaaaa, that's not gonna cut it for me sadly
this library wasn't designed for rollback
it stores entity, component pairs
for every component you're saving
instead of entity, all components
so it's not memory efficient at all
it's designed to be as fast as possible for serializing at the cost of deserializing with only minimal care for file size
rollback demo was just to test real time performance
Im looking at at minimum 21 1000x1000 textures. Possibly up to 3000x3000. Rollback on that would be miraculous.
damn, nativequeue has no UnsafeQueue. can't get a single pointer QQ
A queue is just an array + int.
well no, that's a stack
no, nativeQueue has 16k blocks
what ecs functions are you using to get the data for the serialization system?
just all data for a specific component type?
it works by simply adding an attribute [Save] to your component
if you want to save a component add that attribute
you can ignore a specific field on that component with [SaveIgnore]
yeah but I meant how are you getting the data from ECS
to get the data
π
reflection?
DynamicComponentTypeHandle
Oh, yea, those exists
the only reflection is getting all component types with the attribute in on create
{
var saveIdx = this.Serializer.AllocateNoResize<HeaderSaver>();
var compIdx = this.Serializer.AllocateNoResize<HeaderComponent>();
var entityCount = 0;
foreach (var chunk in this.Chunks)
{
var components = chunk.GetDynamicComponentDataArrayReinterpret<byte>(this.ComponentType, this.ElementSize);
if (components.Length == 0)
{
continue;
}
var entities = chunk.GetNativeArray(this.Entity).Slice().SliceWithStride<int>();
entityCount += entities.Length;
var chunkHeader = new HeaderChunk { Length = entities.Length };
this.Serializer.AddNoResize(chunkHeader);
this.Serializer.AddBufferNoResize(entities);
this.Serializer.AddBufferNoResize(components);
}
var headerSave = this.Serializer.GetAllocation<HeaderSaver>(saveIdx);
*headerSave = new HeaderSaver
{
Key = this.Key,
LengthInBytes = this.Serializer.Data.Length,
};
var compSave = this.Serializer.GetAllocation<HeaderComponent>(compIdx);
*compSave = new HeaderComponent
{
ElementSize = this.ElementSize,
Count = entityCount,
};
}```
thats my component serializer
And on deserialization you look up if the component exists on the entity from the entire block that was stored? or how does it work
deserialization writes it all to a hashmap then every entity iterates (within the block) and checks if it has saved data
this way you can remove data from an archetype after making a save
and it won't break
it will just cleanly remove it
i expected this type of lookup to be really slow
but it actually works remarkably fast for what it has to do
nice
so on deserializing it knows X entities of Y archetype was saved
so it creates that many entities
remaps the entity ids
would you recommend this approach (entity->component) or the other one (entity->componentS) if I'm mainly going for simplicity
then just looks up data for it
without all the extra features (migration, rollback) it sounds simple enough
entity->component is simplier
the reason im doing entity->component is for migration
if you make component changes
it's much easier to migrate if all components of a single type are stored together
i can just iterate that list of components, migrate the data
migration was the main thing i wanted to handle in this library
I'm guessing it works similar to DB migrations
no point having a save system if it breaks everytime you release a patch
public class TestComponentForMigrationMigrator : ComponentDataMigrate<TestComponentForMigrationMigrator.Before, TestComponentForMigrationMigrator.After>
{
public override ulong From => 1392796844747678277;
public override ulong To => 17841778420484547873;
protected override void Migrate(ref After newComponent, in Before oldComponent)
{
newComponent.Value = oldComponent.value;
newComponent.NewValue = 5;
}
public struct Before { public int value; }
public struct After { public int Value; public int NewValue; }
}
my slow version of migration
but minimal code
my fast version of migration but requires pointers
very cool
see this is something I would love to see from unity as part of DOTS
it's such a good fit for data oriented games
but some of these more complex features (migration, rollback) are difficult to get perfectly right
especially with stuff like editor integration
i have tools for editor as well
that store stabletypehashes
so you can see what you need to migrate from -> to
yeah I remember you showing them a few months ago
let me know if you ever release it, it sounds really neat
I just (re)discovered tuples. Holy shit are they fantastic. Love them. Shame they cant be used across main-job boundary
very convenient
I thought you can't use them in burst since they're auto layout-ed structs?
The integrated deconstructor inside of a foreach loop header is so nice.
you can use them in burst, you can't use them across the boundary
i.e. you can't pass in a NativeList<(int, int)> into a job but you could create this in the job and use it
Huh, I swear that wasn't possible a year ago
They probably AOT store the actual layout for the job but attempting to cross managed-unmanaged boundary during runtime is not reliable.
was added in 1.5
I think the tuple swap requires no temporary value according to IL code. No clue how they did that.
yeah, that's what I meant
Possibly through a blend op? I havent actually checked the burst output of a tuple swap.
are you sure it requires no temp value? the generated C# code uses one
or is this a burst feature
I read it off stack overflow that tuple swap compiles without a temp store var in IL output. And somewhere in my physics code that was actually a problem.
maybe it just creates a new struct?
swapping without a tmp value isn't really possible
I dont remember why it was a problem but I know I had to go back to the 3 line swap for a specific section due to no temp variable. Something with pointers maybe.
on an unrelated note, something I was wondering about. since blob assets can get pretty big, and you are forced to access the value contained in the blob asset reference as a ref, what happens if you then access another struct inside the ref, wouldn't that copy it to a local value, potentially copying a large chunk of data?
Once you make a blob asset, thats it. All you do with the ref is ensure that the pointer to that blob asset is communicated properly in safe code.
You never copy the blob asset. Only the pointers to the blob are being passed around.
I thought the intention was also to not constantly copy huge chunks of data
Well yeah, but the struct is stored somewhere
Yea. That's what it's there for.
It's stored in persistant allocation in one giant block.
All blob assets are stored in persistant in one massive singular byte array
So basically what I said earlier is correct, in that if you don't want to copy a large struct inside a blob to a local variable, you would also need to make it available as a ref struct?
do you temp store a struct from the blob? if so it gets moved to stack
I dont know if you can construct a ref struct from a pointer value...
e.g.
ref var blobValue = ref blobAssetReference.Value;
var someLargeStruct = blobValue.MyLargeStruct;
yeah that creates a struct on the stack
That copies to stack.
Ok, that's what I assumed
What's the correct way to handle this then, read the actual value?
ref var someLargeStruct = ref blobValue.MyLargeStruct;```
Will not
or always use refs I guess
depends, you want ro read it at some point
You cant write to the blob but if you want to customize the result of the blob, you need to remove the ref and copy to stack.
What do you mean by customize the result?
Actually, I think you can write to blob if you access the pointer.
Oh, you mean modify the value
My use case is more along the lines of something like this
var myInt = blobValue.MyLargeStruct.SomeOtherValue.SomethingElse.MyInteger
direct access is best
you can but ah, it's somewhat of a bad idea
MyInteger will be copied to stack but only MyInteger. If you want to just access it RO, use ref
I dont think anything explodes...
Is it worth caching the reference to the BlobAssetReference.Value property? or is the performance difference neglible
start reloading the subscene that you made changes to the blob
modifying a blob is better than creating a new one when you just need to modify one value.
You have to cache the reference. You can not directly access without using the pointer itself.
it just caches the pointer. pointer value is moved to stack
You can do this var myInt = blobReference.Value.MyLargeStruct.SomeOtherValue.SomethingElse.MyInteger
That will not work. Unity will throw an error.
Are you sure? I recall having that somewhere
i believe unity won't throw an error if you go deeper than the Value
yeah it just complains on .Value access if it's not a ref
But back to my question, is it worth caching the ref value if you plan to retrieve 2-3 values from the blob?
it was a very common issue people copying Collider to teh stack
and losing the per type info
Oh right, I have no wrapping structs around my values so I always direct accessed them
and breaking/not working properly
The ref is just a safe pointer. Cache or dont, it's already stored. Cache is just C# side and is identical IL side.
What kind of data are you storing in blobs that is just a single value?
Oh no, I'm storing shared component data. Well, not DOTS shared but shared as in multiple entities have the same component data so instead I offloaded it to a blob.
Ah okay, I was just wondering since I usually have a wrapping struct with many values per blob
My component data's are typically single values though or reinterpreted as such so yea, a lot of direct .Value accesses.
I mainly use them for storing more complex data layouts, since you can store deep lists and the like without resorting to funky unsafe stuff
My primary blob asset is the polygon vertices of a 2d polygon collider. It's a fixed buffer of float2s and is reinterpreted as a set of float4s when using pointers.
Actually, looking at the source again, i have no clue what im doing
If itemSettings is the only property of the reference, you can just do BlobWeightedArray<ItemSettings>
ItemSettings is a managed type
Ah. Huh.
It just stores the GUID to the scriptable object holding the data
Oh, it's a unity object. That makes more sense.
NativeQueue is actually FILO? Dequeue takes the last element. peek reads the last element. what is this. i can do the same thing with a list ...
Queue is FIFO. Stack is FILO
that's what i expected ```/// <summary>
/// Removes and returns the element at the end of this queue.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this queue is empty.</exception>
/// <returns>The element at the end of this queue.</returns>
public T Dequeue()
{
if (!TryDequeue(out T item))
{
ThrowEmpty();
}
return item;
}```
is this just worded awkwardly?
I think it's a typo tbh
I think is just English
Maybe
No, it's worded correctly. I think... Returning the element at the start of the stack sounds right as well.
"end" is always referenced in other methods too. so not a typo
