#archived-dots

1 messages ยท Page 8 of 1

rustic rain
#

allthough I probably should

timber ivy
#

I dont think it will be relevant for my use case my subscenes are only 100x100 meters

rustic rain
#

still better to have 1 subscene

#

if it's all connected world

#

rather than multiple

#

I think...

timber ivy
#

The only thing I see relating to sections in SubScene is IsSectionLoaded

#

am I missing something?

#

i guess you got to implement it yourself

rustic rain
#

yeah, kind of

#

just look at SceneSystem sources

#

it's all pretty clear what they do

#

to load scenes/sections

#

also

#

this

#

but it's all not burst compatible

#

found this component

#

maybe this is how you define sections

#

the downside I guess is that in editor you won't have any distinction between loaded sections

timber ivy
#

so you just add that to your scene entity?

rustic rain
#

you add this to objects in subscene

#

and they will get assigned to selected index section

#

parents will be parented

#

I mean

#

parent's section will be inherited by children

#

But I personally avoid using parenting for perfomance reasons

rotund token
#

i think in general better to have separate subscenes for the sake of editor performance

#

when editing them

#

however sections have some nice uses though

#

like interiors etc

#

things that might not need to be loaded from a distance

timber ivy
#

oh so you can use sections like layers so to speak

#

have the main shit load, then as you get closer the small details load

#

i like that idea

rotund token
#

each subscene optionally has a collection of sections

#

and you can load these individually

#

by default there is only 1 section

#

and most people only use 1 section per subscene

#

this is first discussion i've seen where sections have actually been discussed

#

but knowing about sections is important for loading via scripts/jobs

#

because you load the sections

rustic rain
#

from what I noticed

rotund token
#

each section gets it's own world bounds

rustic rain
#

0 section is root subscene

#

and is loaded always

#

is that true?

rotund token
#

ahh

#

i don't think so?

#

not unless you actually load the subscene

rustic rain
#

I tried to load subscene

#

but I can't unload section 0

timber ivy
#

So is all I got to do to create a subscene entity this?

            RequestSceneLoaded componentData = CreateRequestSceneLoaded(parameters);
            Entity entity = base.EntityManager.CreateEntity();
            base.EntityManager.AddComponentData(entity, new SceneReference
            {
                SceneGUID = sceneGUID
            });
            base.EntityManager.AddComponentData(entity, componentData);
            return entity;
rustic rain
#

only unloading subscene works

rotund token
#

how did you load it in the first place?

#

but yeah each subsection has it's own AABB

    public struct SceneSectionData : IComponentData
    {
        public Hash128          SceneGUID;
        public int              SubSectionIndex;
        public int              FileSize;
        public int              ObjectReferenceCount;
        public MinMaxAABB       BoundingVolume;
        internal Codec          Codec;
        internal int            DecompressedFileSize;
        internal RuntimeBlobHeaderRef BlobHeader;
    }```
>        public MinMaxAABB       BoundingVolume;
rustic rain
rotund token
#

oh you mean by editor?

rustic rain
#

after I unloaded section 0

#

it says this

rotund token
#

have you tried via code though?

rustic rain
#

so I'd assume subscene is simply unloaded

#

and now if I try to load section 1 with unloaded subscene

timber ivy
#
Notice that the default section 0 is always there (first line) even if it is empty. The "Section: 0" part of the name is omitted, but all other sections containing at least one entity will show up with their full name.
#
All sections can reference both their own entities and the entities from section 0. Describing the way this reference system works is out of scope here, but an important consequence is that loading any section from a scene requires section 0 from that same scene to also be loaded. The same constraint applies for unloading: section 0 of a scene can only be unloaded when no other sections from the same scene are currently loaded.
rustic rain
#

yeah

#

seems like Section 0 is root of Subscene

#

allthough they are created as different entities

rotund token
#

i have no issue unloading section 0

#

when section 1 is active

rustic rain
#

hmm

rotund token
#

right is section 0, left is section 1

rustic rain
#

maybe editor limitation

rotund token
#

now you don't see it

rotund token
rustic rain
#

I'd worry about it though

#

what if in future it'll be limitation of runtime as well? xD

rotund token
#

why?

rustic rain
#

Can simply be defined as pattern though

timber ivy
#

so if i do this


        Entities.WithAll<WorldChunkComponent>().ForEach((Entity e, ref WorldChunkComponent chunk) =>
        {
            if (math.distance(pos, chunk.position) <= 400)
            {
                Entities.WithAll<SceneReference>().ForEach((Entity e, ref SceneReference scene, in WorldChunkComponent chunk) =>

It will pass chunk from the first foreach to chunk in the second?

rotund token
#

You can't nest foreach

timber ivy
#

how would I check if an entity exists in a foreach loop then?

eager pawn
#

There's not really an example of using ecs and sqlite, not sure if a db makes sense to use for game data

#

Also I think I would like to preload all data a scene needs when you enter the scene

#

The database stores static data btw. So it's stores basehp, but not hp

#

I think I will make an authoring component hold db data and then convert it to an entity component

viral sonnet
#

get the KernelSlot by ref via ElementAt from the nativelist.

#

@rotund token what did you optimize in addition to removing the memcpy?

rotund token
#

for my spatial map stuff?

#

All I changed today was made the quantizing write direct to key values ptrs of the hash map then changed the job to just only do the bucket calcs

timber ivy
#
        var buf = sys.CreateCommandBuffer();
         Entities.WithoutBurst().WithAll<WorldChunkComponent>().ForEach((Entity e, int entityInQueryIndex, ref WorldChunkComponent chunk) =>
         {
             var system = World.GetOrCreateSystem<SceneSystem>();
             if (EntityManager.HasComponent<RelevantComponent>(e) == true)
             {
                 if (chunk.entity == Entity.Null)
                 {

                     buf.SetComponent(e, new WorldChunkComponent()
                     {
                         entity = system.LoadSceneAsync(chunk.hash),
                         hash = chunk.hash,
                         position = chunk.position
                     });
                 }
             }
             else
             {
                 if (chunk.entity != Entity.Null)
                 {
                     buf.SetComponent(e, new WorldChunkComponent()
                     {
                         entity = Entity.Null,
                         hash = chunk.hash,
                         position = chunk.position
                     });

                 }

                 
             }
         }).Run();

buf.SetComponent is throwing this exception anyone know why? I am already using a command buffer

Structural changes are not allowed during Entities.ForEach. Please use EntityCommandBuffer instead.

viral sonnet
rustic rain
#

oh wait

#

you can't

#

you need a system that resolves those chunks once, after they are loaded

#

there's absolutely no purpose for you to do that expensive stuff in actual runtime loop

timber ivy
rustic rain
#

oh

#

there's easy way

#

Object.FindObjectOfType<SubScene>()

#

xD

timber ivy
#

haha

rustic rain
#

it has guid

#

I actually do it like this

#

but I store references

#

in an object

#

can be done also unmanaged

#

you create a system that looks for all subscene/section entities

#

without your own tag

#

or whatever component you need

#

so and then you simply create your own data that references those entities

#

store them in array

#

map

#

or whatever

#

or create other entities

#

with reference to those scene entities

timber ivy
#

Yep that is what I planned. Just having some trouble with the dots api itself now x)

#

are you not able to do entities.foreach twice in one system update?

rustic rain
#

you can

#

but be ready for Dependency troubles

#

hehe

#

seems like you are new to this

timber ivy
#

new with dots yes

#

Some reason even when using a command buffer I am getting Structural changes are not allowed during Entities.ForEach. Please use EntityCommandBuffer instead.

#

guessing this is one of the dependency issues you mentioned

rustic rain
#

here my convo with tertle

#

about how Dependency works internally

rustic rain
timber ivy
#

awesome that will come in handy

rustic rain
#

during job that works with chunks

#

everytime you make structural change, all buffer references and chunks are basically invalidated

#

that's why the moment you do structural change in foreach loop you are basically done and you must return.
And that's why it's simply not allowed

timber ivy
#

So what can I do in this situation?

rustic rain
#

you can schedule structural changes through buffer

#

think of it this way

#

you make a foreach loop

#

and every time you trigger smth with check

#

you simply write it to List of tasks

#

and then once your loop is done

#

you do those tasks

#

EntityCommandBuffer is exactly this

#

but supports a large amount of actions

winged bane
#

You are looping on an entity that would already have this component. This is suspicious

timber ivy
winged bane
#

use

chunk = new WorldChunkComponent {...} 
#

if a ref goes into the the entity loop, its read/writeable

#

no need to set component

timber ivy
#

throws the same exception

rustic rain
#

no

#

you just change values

#

of it

timber ivy
rustic rain
#

what exception

timber ivy
#

Structural changes are not allowed during Entities.ForEach. Please use EntityCommandBuffer instead.

#

so I guess

#

its what you said before

timber ivy
rustic rain
#

you can't use EntityManager here

#

kek

#

you also do

#

LoadSceneAsync

#

which is also structural change

#

also that part is just ๐Ÿ˜…

timber ivy
#

why?

#

should I be using getExistingsystem instead?

#

and yep

#

that was the issue LoadSceneasync causing structural changes

#

time to do it with createntityinstead :/

#

rip

winged bane
#

ye I just saw that SceneSystem too

rustic rain
#

besides

#

you always should use GetExisting

#

because all of them are already created

#

by the time OnCreate is called

winged bane
#

@timber ivy This might be of help for you. I havent tested it but maybe it will give you some insight.

timber ivy
latent quest
#

Hi hi. I'm trying to get a grid partitioning or system into my game but I keep running into issues with nothing allowing NativeArrays, NativeLists, NativeHashSets, NativeHashMaps or seemingly anything that would make such possible. I tries this https://github.com/marijnz/NativeQuadtree but it seems to be pretty outdated and comes up with the same issues I'm running into. I can't seem to find anything online to help me figure out how to use Native-Things in anything but nothing that helps comes up. I seemingly don't understand the Native-Things at a fundamental level, so... what on earth am I doing wrong?

GitHub

A Quadtree Native Collection for Unity DOTS. Contribute to marijnz/NativeQuadtree development by creating an account on GitHub.

#

By "nothing allowing" I mean components and systems btw

robust scaffold
#

Use UnsafeList for example instead of native arrays or native lists. They should be added to SystemStateComponents as you need to manually dispose of them

#

Generally, you shouldn't be nesting or adding unsafe collections to components. Kinda wrecks the cache line for burst

viral sonnet
#

hm, going back to the physics discussion yesterday. any idea how i can selectively build a BVH. i don't want to enable/disable comps. some way to get the physics BuildPhysicsWorld to run at a later point and then skip, just build entities I select

latent quest
#

How would one do quad/octrees or such stuff without nesting collections? Iirc the ecs physics system has a native octree in it though not exposed.

robust scaffold
robust scaffold
viral sonnet
#

nope ... ๐Ÿ˜ฆ

robust scaffold
viral sonnet
#

that could work. let me think about it. otherwise, tertle said using the BVH is pretty simple. I never looked much into it. I just need it for raycasting

robust scaffold
#

The performance of building my tree is so god damn awful. 4.5ms for 10,000 bodies. I need to reduce it to 1/10 that for viable physics.

viral sonnet
#

oh really? i have 8.7ms for 250k

robust scaffold
#

Yea. Unity's is really optimized. Mine is hand written and very bad.

#

8.7 for 250k is good. That's what I want. If I scale to 250k, mine takes 90ms.

viral sonnet
#

the stateless nature makes it really slow

#

8.7 for not doing anything is horrible in my book

robust scaffold
#

It rebuilds every frame. Such is stateless

latent quest
viral sonnet
#

yeah but it's not colliding or smth. it's just idle.

robust scaffold
#

But IMO, float instability means things get changed regardless even if nothing moves

viral sonnet
#

stateless or not, you can't just ignore every optimization as excuse

#

yep, that's a problem. a change filter doesn't care about inaccuracies though

robust scaffold
viral sonnet
#

so they do check if anything has changed but then proceed to still write the same data to a persistent array ...

#

the change is only for BuildBroadphase

#

anyway, changing the worldIndex of an entity isn't that simple because it's a sharedcomp. would move to another archetype

robust scaffold
latent quest
viral sonnet
#

not that rotation does anything for a capsule collider. meh, have to introduce a quaternion dot to not write back all the time :/

robust scaffold
#

Solid green. I disabled the BVH builder so thats why it's so fast.

robust scaffold
rustic rain
robust scaffold
rustic rain
#

huh

#

1ms of gathering sprites

#

pretty good

robust scaffold
#

Yea, im not worried about performance of my sprite renderer. This is without culling which I probably should implement but it's not an issue.

viral sonnet
#

a whole BVH has to be rebuilt because one entity moved? is that a normal implementation?

#

or is this a stateless thing again? ๐Ÿ˜ฉ

robust scaffold
#

well no, there are insertion mechanisms that allow for partial rebuild

#

But that requires expanding the box around an entity by a set margin

#

If the entity doesnt move outside the box, it doesnt need to be rebuilt

#

The box is 0.1 world space units around the entity, hardcoded.

feral minnow
#

What are the best tutorials on ECS on YouTube? Preferably tutorials series of building demo game ๐Ÿ™‚

slim reef
#

that's a bit tough question with the ever changing API and outdated docs

#

watch all, read docs, watch them again and then have some usable knowledge

rustic rain
#

It's not YouTube

#

But it's the only series with full demo game in the end

#

I know of

feral minnow
viral sonnet
#

demo character controller touches trans/rot for change version. whole bvh is rebuilt

#

and something is still touching LTW. man that's annoying to find out

#

none of my systems are touching it. still, the check system reports it as changed. hm...

robust scaffold
rotund token
viral sonnet
#

i check for changes on trans/rot and they are false

rotund token
#

I was writing a tool the other week to track change filters

#

I never finished it as I solved my issue mid way

#

But I intend to at some point

#

The annoying thing is the inspector triggering filters when an Entity is selected (might be buffer only)

viral sonnet
#

so the weird thing. it's not my player. it's happening for my many instanced ai spellcasters. and it's not happening for every chunk but only 1. i've yet to figure out what's different about those

#

and man, now i know exactly what you mean with naming entities. i always have to close the subscene to get rid of names and can search for entity ids

rotund token
#

I believe there's a way to search by id if you have names, something like i:

viral sonnet
#

ok it's the chunk for enemies. should have realized this sooner ๐Ÿ˜„ still no idea what's up with ltw. it's not my pathfinding system either :/

#

and here i thought it's "id:" thanks a lot

robust scaffold
#

One nice benefit of rolling my own transform components is that I can be 100% certain only whatever I code is what will touch the ultimate local to world matrix

viral sonnet
#

haha, yeah ... i was under the impression this will be something i easily find out and i had a very obvious flaw for my player movement. but then it still happens and i searched for every ltw and nothing. :/ when trans/rot doesn't change, ltw can't change either, right? it must be something obvious i'm missing

robust scaffold
#

Hrmmmmmmm, looking into the source of Unity's BVH builder, I think I know why it's so fast. I'm gonna test it out on my version for a test though

viral sonnet
#

found the error. i'm a dumb dumb. parallel dot = 1 so my condition was wrong and i wrote rotation back. now, why ltw was reported and not rotation. i dunno! if it would have been rotation i would've known instantly where to look. so now i just found the right system via turning them off one by one. i have to say, pretty cool feature

viral sonnet
robust scaffold
#

huh

robust scaffold
# viral sonnet yeah

How long did you say a full BVH rebuild by Unity Physics took for 250k entities? Can you try with only 50k (my comp chokes quite hard on 250k).

#

And can you post what the profiler job distribution looks like

viral sonnet
robust scaffold
viral sonnet
#

yes

robust scaffold
#

Wow, that is 4x faster than my initial first level job.

#

huh

viral sonnet
#

i have a ryzen 5900x

robust scaffold
#

True, different comps. Hrm. The distribution looks the same though and how I expected looking at the source.

viral sonnet
#

so I've fixed the version bumping now . doesn't change the fact though that everytime something moves it spikes quite heavily :/

rotund token
#

you'd expect something to move every frame

viral sonnet
#

exactly!

rotund token
viral sonnet
#

it is

rotund token
#

just seeing all the stuff basically being in a single branch for second phase

viral sonnet
#

so that's why this is only 1 worker thread?

rotund token
#

it is using multiple

#

its just that 1 branch is taking a lot longer than the rest

#

the first step breaks up N branches on ST then these branches run in parallel

viral sonnet
#

ohhhhh good to know

#

because that's totally unrealistic

#

so what's the range here? can this even be measured by range?

robust scaffold
#

You might have a very sequential distribution of nodes. Like a staircase instead of a tree.

viral sonnet
#

oh wait, we're talking about BuildBranches. hm. thought this was about the BuildFirstNLevels because that job takes quite long

rotund token
#

also just a note because i saw you talking about this before, there are 2x bvhs. 1 for dynamic 1 for static.

#

only the dynamic is rebuilt every frame

#

the static is only rebuilt if you make changes

robust scaffold
#

Static is rebuilt based off a changefilter of static transform components yea

#

They have not yet implemented incremental rebuild of BVH tree on the dynamic tree but there seems to be hints that they plan to. It's illogical to not.

viral sonnet
#

eh scratch that, i also have a long buildbranches. just too many worker threads that don't fit on my screen haha.

viral sonnet
#

i see 23

robust scaffold
#

Pleb over here with only 10+1(main). Plz, some spare change threads.

viral sonnet
#

my old i7 also choked along with 8 ๐Ÿ˜„

robust scaffold
#

Yea, I think 3 of those are virtual. Im on intel i7 as well. Pain.

viral sonnet
#

so previous one was an i7-4770k and the new one is at least 1/3 faster

#

easy to measure, my timings were 30ms, now 20ms

#

looking forward to a proper incremental rebuild on dynamics. right now all my entities are static because i saw no difference

robust scaffold
#

Alright, turning off surface area heuristic split and cutting the number of initial splits to just the root (like what BuildFirstN job does) does result in similar performance:

viral sonnet
#

hah! similar! that's faster on a slower cpu

robust scaffold
drowsy pagoda
#

When you "Unload" a scene in inspector. Then try to access it via script, it becomes invalid, which is understandable. However, when you "Load" it back up, it still comes back invalid unless you recompile. Is there a way to validate the scene without having to recompile?

viral sonnet
#

@rotund token Am I missing something here? For a DynamicHashMap, not multi, this could be read linear and -1 just skipped. what's the bucketNext for in a single element hashmap? i thought this is only required in multiple elements per key.

rotund token
#

more than 1 key can have the same hash

#

and your key/value arrays can have holes in them

#

the ability to remove elements from a hashmap adds all these complications

viral sonnet
#

ok i see

#

thanks!

rotund token
#

if you guarantee you have not removed anything from the hashmap

#

and added it in a single thread

#

then yeah you could just grab the key/value arrays

#

this is the reason my batch add method is a
ClearAndAddBatch

#

because it's only safe on an empty hash map

#

i wrote this i think i called it, NativeLookup

#

which is basically just these native hash maps stripped back to disallow remove, parallelwriter etc

#

so it's guaranteed to just be a linear key/value

#

so i could do these type of things

#

that said i don't use it atm because it needs a bit of love ^_^'

#

some day

viral sonnet
#

meh, again I'm looking at this and I just think this can't be right ... some optimized debug compilation would be great. release is just all over the place. something seems wrong with summing up these timings

#

[rbx+630h] must be the tick from the job parameter

#

nearly 30% in a long job. just no ...

viral sonnet
#

hm, so the optimal target distance system would have the source/target position on the same entity. my problem is now, when 100 casters have the same target and the target moves. 100 target distance entities would need to be updated and that update wouldn't be that fast.

robust scaffold
#

Or one that it can see?

viral sonnet
#

nah, the caster already knows which target. just to get the distance between

robust scaffold
viral sonnet
#

the math is not my issue. getting the data is ๐Ÿ™‚

robust scaffold
#

There's no other option other than random access unfortunately. You aint gonna get a nice cache line going.

viral sonnet
#

i'm using random memory access to get the position of the target

#

yep, that makes me sad ๐Ÿ˜„

robust scaffold
#

100 casters to 1 target, how often does the target change for each caster?

#

It might be good to use a shared component to fragment your chunks then per chunk, conduct a single random access to find the target for all casters under it then calculate

viral sonnet
#

i don't think whole archetype changes is a good fit for this

#

targets can change quite erratically

#

the only optimization i can think of right now is to not use LTW and translation instead.

robust scaffold
#

Depends. If it changes rarely, over the course of seconds rather than frames, I would attempt to try out shared component fragmentation. Otherwise, if this isnt multiplayer, you can instead use a fragment shader with indices to leverage the GPU to calculate it really fast.

timber ivy
#

array[i] =

robust scaffold
#

Local to world should only be touched by those actually rendering things or requires full scaling and rotation values.

viral sonnet
#

hm, frag shader. i'd still need to upload/render all my casters then, right?

robust scaffold
#

If you want to roll your own rendering system then yea, the values are already on the GPU ready to be used.

#

I wouldnt recommend it though. Anything short of 50,000 positions is cheap enough to upload. Beyond that, might consider reusing buffers.

viral sonnet
#

does dots physics alreayd has a method for Quaternion.Angle?

rotund token
#

check out Unity.Physics.Math

#

they implemented a bunch of the UnityEngine stuff

robust scaffold
#

Doesnt look like it

#

It's just two lines. Ya can do that.

viral sonnet
#

oh thanks! i expected some internal call.

#

gotta love some magic numbres

rotund token
#

thats 1 radian

#

57.296Deg ร— ฯ€/180 = 1Rad

robust scaffold
#

actually, it's just 2 pi.

viral sonnet
#

man, i need to sleep ... that's the MB implementation. expected rads

robust scaffold
#

That moment when you press play and the game has 1.5 FPS because a single burst compile tag was uncommented.

viral sonnet
#

i'm starting to realize, pulling the trans/rot instead of the ltw doesn't give me any benefit. lookrotation is quite math heavy with 2 cross products

timber ivy
#
protected override void OnUpdate()
    {


        EntityCommandBufferSystem sys =
                World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();

        if (cam == null)
            cam = Camera.main.transform;

        // Create a command buffer that will be played back
        // and disposed by MyECBSystem.
        
        var ecb = sys.CreateCommandBuffer().AsParallelWriter();
        var pos = new float2((int)(cam.position.x/100), (int)(cam.position.z/100));


        Entities.WithBurst().WithAll<WorldChunkComponent>().ForEach((Entity e, int entityInQueryIndex, ref WorldChunkComponent chunk) =>
        {
            Debug.Log(math.distance(chunk.position, pos));
            if (math.distance(chunk.position, pos) <= 4)
            {
                if (HasComponent<RelevantComponent>(e) == false)
                    ecb.AddComponent<RelevantComponent>(entityInQueryIndex,  e);

            }
            else
            {
                if (HasComponent<RelevantComponent>(e) == true)
                    ecb.RemoveComponent<RelevantComponent>(entityInQueryIndex, e);
            }
        }).ScheduleParallel();
        sys.AddJobHandleForProducer(Dependency);
    }

why is this system so slow? Profiler is saying its taking most of the time on jobhandle.complete but im not even calling that

#

there are only 400 entities with the worldchunkcomponent

#

Ik you're not supposed to profile entities in editor but its making my editor run at 20 fps so I can't' really even use it

robust scaffold
robust scaffold
#

Parallel writing is not always faster than singlethreaded, try .Schedule() instead of parallel and see if it's faster.

#

Parallel is only really faster if you have pre-allocated and know exactly the range in which a thread will write to. This doesnt look like that case.

timber ivy
#

Schedule is slower

#

run is fine

robust scaffold
#

math.distance is expensive. It requires a square root calculation. Use math.distancesq and square the other side.

timber ivy
#

the delay is coming from addjobhandleforproducer ig

#

cause the profiler says its waiting on job.complete

robust scaffold
#

That's the ECB replaying on main thread.

#

Structural changes are always expensive. Try using a boolean property instead of adding and removing components if it's done often

timber ivy
#

Its not done often at all

#

maybe once every few frames

#

31 ms waiting on a semaphore yikes

robust scaffold
#

If you have a lot of entities undergoing structural changes, yep. That's expected.

timber ivy
#

that is when im standing still

#

and the entities arent changing at all

robust scaffold
#

Then it's probably not that job then.

#

Check the profiler timeline display, what jobs are being waited on

timber ivy
#

the profiler is pointing to that exact system tho

#

All the job is doing is looping through about 400 entities. if you have moved to a new area add a component to the entity

#

but im not even moving and its at max 15-30 entities that this system is even adding components to

robust scaffold
# timber ivy

Thats a lot of red. That means you have a lot of memory allocation.

#

The debug.log has been removed right?

timber ivy
#

yes

#

and

#

where am I allocating?

#

i dont see anything other than that debug.log(which has been removed)

robust scaffold
#

ECB is actually, IIRC, a multi hash map just with specialized keys and values.

timber ivy
#

so am I better of just doing this in .Run() then?

devout prairie
#

definitely burst compilation enabled under menu?

timber ivy
#

Yes its enabled

devout prairie
#

i think for HasComponent, maybe pass in the ComponentFromEntity rather than use HasComponent inside the job

robust scaffold
#

If you're doing structural changes, it's typically best to do so on the main thread anyways.

timber ivy
#

LOL safety checks

#

was the issue

robust scaffold
#

Huh

devout prairie
#

"GetComponentDataFromEntity"

timber ivy
#

im back to 600 fps after disabling safety cchecks

robust scaffold
#

That is a wild amount of safety checks. I wonder why

#

I have safety checks on by default and I never see any significant amount of performance loss. Then again, I'm passing around raw pointers everywhere.

timber ivy
#

from 32 ms down to 0.032

devout prairie
#

i was just about to explain..

#

not sure if it will make any difference tbh but the way i do that would be:

robust scaffold
#

I think the lambda code gen already optimizes it to chunk.HasComponent<>

devout prairie
#
protected override void OnUpdate()
    {


        EntityCommandBufferSystem sys =
                World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();

        if (cam == null)
            cam = Camera.main.transform;

        // Create a command buffer that will be played back
        // and disposed by MyECBSystem.
        
        var ecb = sys.CreateCommandBuffer().AsParallelWriter();
        var pos = new float2((int)(cam.position.x/100), (int)(cam.position.z/100));
        var relevantComps = GetComponentDataFromEntity<RelevantComponent>(true);

        Dependency = Entities.WithReadOnly(relevantComps).ForEach((Entity e, int entityInQueryIndex, ref WorldChunkComponent chunk) =>
        {
            Debug.Log(math.distance(chunk.position, pos));
            if (math.distance(chunk.position, pos) <= 4)
            {
                if (!relevantComps.HasComponent(e))
                    ecb.AddComponent<RelevantComponent>(entityInQueryIndex,  e);

            }
            else
            {
                if (relevantComps.HasComponent(e))
                    ecb.RemoveComponent<RelevantComponent>(entityInQueryIndex, e);
            }
        }).ScheduleParallel(Dependency );
        Dependency = sys.AddJobHandleForProducer(Dependency);
    }
viral sonnet
#

yep, safety checks are costly. that's by far the biggest increase I've seen though

devout prairie
#

so i've just changed HasComponent to passing in GetComponentDataFromEntity

#

but yeah as KF says possibly it would get optimized to that anyway

timber ivy
#

ah yeah ill see if this does any better in the profiler

#

kinda lame the safety checks are hitting so hard to performance

robust scaffold
timber ivy
#

and i have a really good pc

robust scaffold
#

It's not a PC issue for that big of a difference

viral sonnet
#

i dunno, the timeline is all pink, not green. was that still from the debug log?

devout prairie
#

also you don't need the WithAll as it's already in the lambda

robust scaffold
#

With colorblind mode or something possibly.

timber ivy
#

I have colorblind mode on

devout prairie
#

ah wait..

viral sonnet
#

oh, ok ๐Ÿ™‚

devout prairie
#

i think you also need to chain the dependency of the ecb to the job, i've added that in the above code ^

#

Dependency = Entities.ForEach..

#

and ScheduleParallel(Dependency);

timber ivy
#

Ok I guess it was just some editor bug

#

restarting the editor

robust scaffold
timber ivy
#

and it isn't lagging with safety checks on now

devout prairie
#

i always do it but useful to know i guess

#

sometimes chaining together multiple jobs in one system so i guess it's good practice either way

robust scaffold
#

For systembase lambdas and IJobEntity, dependency declaration and chaining is done at code generation so no need to do it manually

devout prairie
#

ah ok, thanks for that i didn't realise

robust scaffold
#

For system structs, yea. gotta do it by hand

timber ivy
#

System structs?

robust scaffold
#

It looks nice and slick though

robust scaffold
# timber ivy System structs?

The alternative SystemBase. It's in a struct form with all the inherent properties passed into the OnUpdate in a (ref SystemState state) property.

#

The benefit is that you can burst compile the main thread scheduling and whatever code you have as well as the jobs.

#

The con is no code generation and everything needs to be written out manually

devout prairie
robust scaffold
#

Like magic. It's like GC

devout prairie
#

ah right

#

hah ๐Ÿ™‚

#

is that built in to dots or your custom allocator?

robust scaffold
devout prairie
#

ohhh

viral sonnet
#

hm, can't find anything on that subject. can a quaternion be flipped like a vector by 180 degrees without multiplying?

robust scaffold
#

You can use update allocator (seen at the top of that screenshot) for all containers but it has built in special support for NativeArrays and NativeLists (not really a list though as it cant expand).

devout prairie
viral sonnet
#

not sure about that. quat inverse is used for reversing multiplications ie. to divide

devout prairie
#

in some cases i dispose of arrays between lamda jobs in the chain inside a system, so i guess it can be handy to have the option of manual or using that allocator to just handle it

viral sonnet
#

inverse has a dot product. :/ issues issues. fk it. let's go back to ltw

robust scaffold
#

Read Bunny's comment at the end.

#

quat is just weird. Im gonna stick with my 2D quats which is just sincos

#

I can do all sorts of wild things with 2d quats, like logical inversing

viral sonnet
#

ok, that's the long answer for what i said ^^

#

i'd have to multiply and yeah, i'll stop now. this is getting too math heavy for what is already precalculated in ltw

robust scaffold
#

I think... i dont know

viral sonnet
#

inversing in itself isn't really useful unless you'd translate from world to local rotation or smth

devout prairie
#

yeh you're right inverse is basically just, say you have a euler of 3/3/3 it'll create -3/-3/-3

#

i think useful for relative rotations and as you say local to world etc

viral sonnet
#

the easiest to explain is when you have a rot and apply a 90 degree rot. inversing the 90 degree rot and multiplying by the result would give you the base rot again

devout prairie
#

yeah

viral sonnet
#

quats have no division. that's why the inverse is golden

devout prairie
#

so why do you need to rotate 180?

#

i think what kf's link is saying you end up with the same rot anyway right

viral sonnet
#

i'll test this quickly.

devout prairie
#

was interesting reading back over the past few hours discussion re bvh etc as i'm looking at exactly that at the moment

#

i think it makes sense in my case to just leverage physics bvh as my units are already rigidbodies

#

so to get for example, current list of enemies in range, i guess i have two options:

#

the first i was trying was have a large collider that is event only, and collect those events, but it's painful and i think someone mentioned events are slow

#

second is basically, do a sphere cast after the broadphase and collect the results

#

so if i understand correctly, doing a sphere cast will leverage the built physics bvh anyway right

viral sonnet
devout prairie
#

i always think of raycasts etc as slow coming from a mono/unity background

viral sonnet
#

going back to unity5. god damn! it's fast

devout prairie
#

but i think in the case of unity.physics and dots it's pretty much just dipping straight into the broadphase bvh

robust scaffold
#

For nearest neighbor query, spatial grids are fastest but what if you wanted the nearest neighbor not behind a wall? Or the nearest neighbor in a certain direction? That's where BVH edges ahead.

devout prairie
#

not sure if it's helpful

#

what exactly is happening there?

viral sonnet
#

yeah, multiplying rot with 0,0,1

#

the green line is the forward and the red one is the inverse of the rotation

robust scaffold
#

For 50k. not... good

viral sonnet
#

and why i need the flip: var angleFromTarget = Angle(-dirToTarget, targetForward); is to figure out if the target is in front, flank or behind of the source.

devout prairie
#

i really struggle with those maths though, so there maybe some dot shortcut!

robust scaffold
viral sonnet
#

that's basically the angle method ^^ private float Angle(float3 vecA, float3 vecB) { var dot = math.dot(vecA, vecB); var angleInRadians = math.acos(dot); return math.degrees(angleInRadians); }

robust scaffold
#

Yes.

#

The dot product is magical. You can do so much with it

#

You can probably figure out the flanks from a range of the dot product without needing acos if you dont need the exact angle.

viral sonnet
#

dot is really nice, yeah ๐Ÿ˜„

robust scaffold
#

dot is so good, unity named their new technology DOTS.

viral sonnet
#

lol

#

yeah, flank could be defined <0.7 and > 0.3 or smth

robust scaffold
#

Like if the dot product falls between 0.5 and -0.5, the angle of the target would be roughly 60 degrees to -60 off tangent.

#

Use cos((deg) * pi/180) to find the decimal cutoff for a degree you designate as flank. Then you dont need the acos lookup table.

#

Hrm

#

Well, I need the AABB. Thats the entire reason why I'm building this BVH

#

I think I understand why Unity glued together 4 AABBs together

devout prairie
#

obviously it's an offline renderer, but interesting of them to do that

robust scaffold
devout prairie
#

Hehe i always thought that multiple day per frame render times seemed excessive for what they were getting

#

but to be fair, they've contributed a lot.. Pixar created open subdivs which was an open source realtime subdivision algorithm

#

basically it's like tesselation, but for 3d content creation apps and render engines

robust scaffold
#

They were pioneers in the field dont get me wrong

devout prairie
#

and as far as i understand it, i think they also started the whole PBR rendering thing, and release the PBR algorithms to standardize that

#

PBR has revolutionized even game engine rendering

viral sonnet
#

weren't they also involved in blendshapes?

devout prairie
#

not sure on that one

#

definitely a lot of joint efforts there with like fbx evolving to support different stuff like morph targets, blend shapes, mats, skinning etc and then other formats coming along like DAE, collada etc.. all of it helping to just standardize all of this stuff across different pipelines

#

and now unreal with USD or whatever, universal scene description i think

#

actually USD was Pixar also ๐Ÿ˜› Didn't realise

#

Open Subdivs is quite an interesting one to look at in terms of it's fast hierarchical data storage/access

#

I'm not exactly sure how it works ( been a few years since i was looking into it ) but it's a super optimized tree type structure for realtime use

timber ivy
#

Is SceneSystem.LoadParameters.Priority implemented at all?

#

I dont see it anywhere

robust scaffold
#

But it would make sense.

timber ivy
#

Its there

#

but I dont see where its being set

#

def not in scenesystem

#

gonna dig through the code some more

#

ah its used by gameobjectsceneutility.LoadGameObjectSceneAsync

robust scaffold
#

There's no comments on priority though

timber ivy
#

My guess

#

its working like priority does on AsynOperations

#

and being passed to whatever they are doing to load the actual scenes owned by the subscene

viral sonnet
#

i think the most frustrating thing in todays programming is that it matters so little how many calculations you need for something. 95% is spent with waiting for data. optimizing an acos away is like, great, you saved 2ns

eager pawn
#

should i do all my data access during build time and create authoring components from the tables? i'm not writing to the db, just reading.

or should i create entities directly from db data during runtime?

rustic rain
#

You should use subscenes as much as you can

#

Because this is next gen loading

#

Can create prefabs in subscenes and then instantiate in runtime

eager pawn
#

What if it's an ItemChest containing an Item and it's possible for the player to not open it? Would the Item be created during runtime then?

rustic rain
#

There are infinite ways how this can be implemented

#

You can create item during conversion and add disabled tag to it

#

Or make a prefabs pool

#

And save reference to it in chest

#

Once it's open you randomly instantiate item

eager pawn
#

It's not random, but yeah I think I get it

drowsy pagoda
#
var sceneSectionComponents = new List<SceneSection>();
EntityManager.GetAllUniqueSharedComponentData(sceneSectionComponents);

I got the shared components. How do I iterate each chunk per shared component from here?

rustic rain
#

Get chunks

#

Repeat foreach

drowsy pagoda
#

Ah.

#

Thanks

rustic rain
#

I do wonder when all sections are actually loaded

#

I mean their entities

#

And I also wonder whether auto loading of it checks whether entity is already created in you do it manual t

drowsy pagoda
#

NativeArray<ArchetypeChunk> chunks = query.CreateArchetypeChunkArray(Allocator.TempJob);
If I set shared component filter, I am to assume all the chunks are of that same Shared component data right?

rustic rain
#

Yeah

#

Also

#

Use jobified chunk creationf

#

If you want to jobify it

#

Potentially can make it fully threaded too

#

Allthough...

#

I just remembered

#

Ah nvm, for a second I had brainfart xD

#

If you have lots of chunks

#

Jobified should be used probably

drowsy pagoda
#

I see

timber ivy
#

is it valid to cache Entity/other components in a component? or is there some special steps I must take?

robust scaffold
#

Ugh, multithreading is pain

rustic rain
#

with entities there's a problem of checking tho

#

you'd need to check whether entity still exists

timber ivy
#

alright

#

just wondering in some ecs it is not valid to do that

#

for example in leo ecs you must use ecspackedentity

#

then call pack/unpack to get the actual int representation of the entity

robust scaffold
#

Entity in DOTS is just 2 uints in a single struct

rustic rain
#

yeah, basically kind of a pointer to chunk

#

in it's own way

robust scaffold
#

Singlethreaded, works perfectly fine and stable BVH tree. Multithreaded, all over the place. Ugh.

timber ivy
#

huh weird my entites auto generated by subscenes dont render in the game view

#

only in scene view

latent quest
#

Why would one be unable to use a custom struct in a job? Currently I'm using a .ForEach in my code to collect all entities that are to be processed but it's telling me The UNKNOWN_OBJECT_TYPE has been deallocated, it is not allowed to access it. Apparently this is something that happens when modifying an entities which has been invalidated but I'm not editing the entity period in the code.

prims = new NativeList<BVHPrim>();
Entities.ForEach((Entity ent, in Translation translation, in WorldObject worldObject) => {
  var pos = new float2(translation.Value.x, translation.Value.z);
  prims.Add(new BVHPrim { pos = pos, entity = ent, bounds = new float2(2, 2) });
}).WithoutBurst().Run();
rotund token
#

prims = new NativeList<BVHPrim>();

#

you haven't allocated your list

latent quest
#

allocated?

rotund token
#

yes all native memory needs allocation

#

what you passed into the job is just a void pointer

#

look at the constructor for NativeList

#

the constructor must always be used

latent quest
#

Huh, okay then, it seems to have worked now. I always used Allocator whenever it complained and told me to. I don't really know how exactly it works in all honesty ( ; lvl)y. Thanks!

#

I'll read up more on Allocator for the future.

winged bane
#

it all gets easier after hitting your head against the wall several dozen times

rustic rain
#

can confirm

#

hmm

#

don't quite understand why debug collider drawing is not working

#

it did create those 2

#

but nothing is drawn

#

not in scene mode, not in game mode

rustic rain
#

hmm

#

seems like it doesn't draw if there's only 1 body

rustic rain
#
        protected override void OnCreate()
        {
            base.OnCreate();
            _centerField =
                typeof(PhysicsShapeAuthoring).GetField("m_PrimitiveCenter",
                    BindingFlags.NonPublic | BindingFlags.Instance);
        }

        protected override void OnUpdate()
        {
            Entities.ForEach((PhysicsShapeAuthoring shape) =>
            {
                var value = (float3)_centerField.GetValue(shape);
                value.z = -shape.transform.position.z;
                _centerField.SetValue(shape, value);
            });
        }

I don't get it

#

why it works with open subscene

#

but when it's closed

#

offset is wrong

#

I am trying to make literally all PhysicsColliders

#

at 0 on Z axis

#

by adding center offset

#

from go's position

solemn hollow
#

try OnStartRunning instead of OnCreate

rustic rain
#

this is COnversion System

solemn hollow
#

oh i see. did you refresh entity cache?

rustic rain
#

I reimported several times

#

restarted editor

#

several times

#

entities cache didn't help either

#

ok

#

I realised what's wron

#

somehow I change Z value of entity

#

oof, I need custom inspector for Colliders

#

seeing nothing is annoying

#

finally

#

@robust scaffold here's what I meant regarding 2D constraints btw

#

even though sprites on different levels, their colliders are fixed on same axis

#

so this is pretty much how you can construct 2D shapes out of 3D ones

rustic rain
#

oh wow

#

that's pog, thank you

rotund token
#

i havent got around to doing mesh yet but everything else is there

#

provides this

#

oops just noticed typo

#

should be vertex1

#

๐Ÿ˜„

rustic rain
#

hmm

#

GetHash

#

for type T

#

seems like your internal method

rotund token
#
            where T : struct
        {
            return blobAssetReference.m_data.m_Align8Union;
        }```
#

nothing special

#

you probably don't even care about seeing the hash

#

it just requires internal access

#

i just didn't want to remove something that was previously shown

solemn hollow
#

Im a bit confused atm.
Is entropy supposed to go up if i remove the most unlikely value of a list of possibilities? My limited understanding is it should go down with less possibilities.

rotund token
#

well if it's unlikely it's probably not adding much uncertainty?

solemn hollow
#

exactly. but it adds some. so if i remove it the entropy should decrease slightly right?

rustic rain
#

hmm

#

who do I need to give internals access to

#

So files in Editor folder

#

can access it?

#

Editor namespace didn't work

rotund token
#

i just have an assembly with asmref to basically everything

#

this is just unity.entities

rustic rain
#

hmm

#

I can't get it to work, weird

#

can't get internals

#

for custom assembly

#

in Editor folder

rotund token
rustic rain
#

idk, it just doesn't work

#

I declared asmref

#

created reference to Entities

#

and created [assembly; InternalsVisibleTo("nameOfasmref")]

#

aaaaand, still can't see internals

rotund token
#

And get hash is in nameofasmref?

rustic rain
#

yeah

#

both in same file in same namespace

#

holy

#

finally

#

made it work

#

now another trouble

#

nvm

#

Rider broke everything

#

kek

devout prairie
#

what would be an alternative approach to events?

#

like say i have bullets colliding ( just as an example ) and i want to spawn some effect

#

i think previously where i had bullets i was using raycasts anyway to detect collisions and avoid pass through

#

but in this case actually i'm looking at melee weapon collision, and say generating a hit effect and assigning damage etc

#

would i be better off doing an overlap query every frame for every weapon orrrrr

rotund token
#

really depends on frequency

#

we use overlap sphere for our attacks though

#

but we only do 1

devout prairie
#

i mean say a unit swinging a melee weapon

#

i could optimize by only doing the collision query during swing

rotund token
#

yeah we only do 1 overlap sphere for melee attacks

#

not like constantly while traveling

#

just has a trigger point when we fire it

#

(i didnt write this system just letting you know how it works)

devout prairie
#

i guess best idea would be to test against collecting events and compare, i'm leaning towards doing the overlap queries though as it's simpler

#

yeah that's fair

#

i'm using ragdolls here so i kinda want some accuracy

timber ivy
#

is it possible to write to a native array in an entities.foreach job?

#

cause this is throwing dependency errors

devout prairie
#

yeah just use Allocator.Temp rather than TempJob

timber ivy
#
var chunks = new NativeArray<Cell>(9, Allocator.TempJob);
        int index = 0;
        for (short x = -1; x <= 1; x++)
        {
            for (short y = -1; y <= 1; y++)
            {
                short tX = (short)(cell.x + x);
                short ty = (short)(x + cell.z + y);
                chunks[index] = new Cell(tX, ty, size);
                index++;
            }
        }
        Entities.WithAll<WorldChunkComponent>().WithBurst().ForEach((Entity e, int entityInQueryIndex, ref WorldChunkComponent chunk) =>
        {
            
           
            chunk.isRelevant = chunks.Contains(chunk.cell);
devout prairie
#

Pass the Array in with WithReadOnly

timber ivy
#

oh

#

let me try that

devout prairie
#

but if it's parallel and you're writing to it ( not just reading ) you need to treat as an unsafe parallelwriter and be very careful you're not overwriting from different threads

#

just reading is simple tho

#

Pass it in like this:
.WithReadOnly(chunks).WithNativeDisableParallelForRestriction(chunks).

#

Also, you don't need WithBurst()

#

ForEach is automagically bursted

#

But yeah if you're creating the array outside of the job/foreach, use TempJob like you've done ( it holds the allocation for four frames, to give the job time to play out and use the array ), and then remember to call Dispose() on it after the ForEach

timber ivy
#
 var chunks = new NativeArray<Cell>(9, Allocator.Temp);
        int index = 0;
        for (short x = -1; x <= 1; x++)
        {
            for (short y = -1; y <= 1; y++)
            {
                short tX = (short)(cell.x + x);
                short ty = (short)(x + cell.z + y);
                chunks[index] = new Cell(tX, ty, size);
                index++;
            }
        }
        Entities.WithAll<WorldChunkComponent>().WithReadOnly(chunks).WithNativeDisableParallelForRestriction(chunks)
            .ForEach((Entity e, int entityInQueryIndex, ref WorldChunkComponent chunk) =>
        {
            
           
            chunk.isRelevant = chunks.Contains(chunk.cell);
            

        }).Schedule();

        chunks.Dispose();
The system TagWorldAreasAsRelevant writes WorldChunkComponent via TagWorldAreasAsRelevant:TagWorldAreasAsRelevant_LambdaJob_0_Job but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.
#

still throwing the exception

rotund token
#

chunks.Dispose(Dependency);

#

you can't dispose that until you finish the job

timber ivy
#

ah

devout prairie
#

Dependency = Entities.ForEach and also ScheduleParallel(Dependency)

timber ivy
#

Doesn't codegen do that?

devout prairie
#

Although KornFlakes tells me this is handled automatically now

rotund token
#

yes

timber ivy
#

tyvm!

rustic rain
#
            _playerSingletonQuery = state.GetSingletonEntityQueryInternal(typeof(PlayerTag));
        }

        private EntityQuery _playerSingletonQuery;
#

huh

#

that works

#

with internal access

#

let's you burst getting entity

#
        [BurstCompile]
        public void OnUpdate(ref SystemState state)
        {
            state.EntityManager.SetComponentData(_player, new PhysicsVelocity());
        }

Anyways found a simple way to make Dynamic Bodies Kinematic with one simple constraint xD

#

hmmm

rotund token
#

ah

#

you realize there is a component you can add

#

to just do it right

rustic rain
#

is there a way to create children of physics bodies

rustic rain
rotund token
#

PhysicsMassOverride

rustic rain
#

hmmm

rotund token
#
    /// Add this component to a dynamic body if it needs to sometimes switch to being kinematic.
    /// This allows you to retain its dynamic mass properties on its <see cref="PhysicsMass"/> component, but have the physics solver temporarily treat it as if it were kinematic.
    /// Kinematic bodies will have infinite mass and inertia. They should also not be affected by gravity.
    /// Hence, if IsKinematic is non-zero the value in an associated <see cref="PhysicsGravityFactor"/> component is also ignored.
    /// If SetVelocityToZero is non-zero then the value in an associated <see cref="PhysicsVelocity"/> component is also ignored.
    /// </summary>
    public struct PhysicsMassOverride : IComponentData
    {
        public byte IsKinematic;
        public byte SetVelocityToZero;
    }```
rustic rain
#

oh

#

๐Ÿ˜…

rotund token
#

so just add that component and toggle it on/off as required

rustic rain
#

yeah

#

Sooo, any idea regarding children?

#

basically

#

I want to have 1 body

#

with main collider

#

and additional

#

but so that they trigger their own trigger events

#

I basically want to have an object with top side collider and bottom collider
If player touches top - he jumps
if player touches bottom - smth else happens

#

so that Unity does not unchildren it

rotund token
#

physics does not support children

#

it uses translation and if it's on a child it's in local space

#

they need to be separate and you just need to make them match positions

rustic rain
#

๐Ÿค”

rotund token
#

or just use a compound collider and figure out what part it hit

rustic rain
#

even if both bodies kinematic?

rotund token
#

doesn't matter

#

unity transform system uses translation is local space

rustic rain
#

I assume static bodies simply won't even move their colliders with LTW

rotund token
#

only static colliders use LocalToWorld

#
            {
                All = new ComponentType[]
                {
                    typeof(PhysicsVelocity),
                    typeof(Translation),
                    typeof(Rotation),
                    typeof(PhysicsWorldIndex)
                }
            });```
#
            {
                All = new ComponentType[]
                {
                    typeof(PhysicsCollider),
                    typeof(PhysicsWorldIndex)
                },
                Any = new ComponentType[]
                {
                    typeof(LocalToWorld),
                    typeof(Translation),
                    typeof(Rotation)
                },
                None = new ComponentType[]
                {
                    typeof(PhysicsVelocity)
                }
            });```
rustic rain
#

but do static move with LTW?

rotund token
#

static colliders don't move

#

they're static ^_^'

rustic rain
#

huh

#

Debug view makes them move

rotund token
#

?

rustic rain
#

I move static bodies

rotund token
#

that's a bad idea

#

you have to rebuild the static world every frame then

rustic rain
#

is it much worse than rebuilding kinematic world?

rotund token
#

there's no point in making a collider static if your'e going to move it

#

you're slowing yourself down

rotund token
#

now you're building static + dynamic world

#

you have 0 optimization

rustic rain
#

well, there is... I can use parenting xD

#

but I don't really have dynamic world

rotund token
#

sure but you're extremely limiting number of colliders you can have now

rustic rain
#

besides 1 entity

#

in that case

rotund token
#

so you're not really using physics

#

you're just using it as a spatial map

rustic rain
#

kind of

#

tbh

#

same perfomance

#

all I have in this case for physics: need to get trigger events

#

nothing else

#

all bodies move

#

by a same value

#

and there's only 1 dynamic body

rustic rain
rotund token
#

as long as you're sure you never want collisions

#

then i guess sure

devout prairie
rustic rain
#

ground and player

#

and only when player "dies"

#

basically a fancy death animation xD

devout prairie
rustic rain
#

it's not really modification, it's just... using smth not the way it was meant to be used

devout prairie
#

but i think they were setting everything as static and maybe manually rebuilding when needed, or something, and moving static colliders around

#

yeah

rustic rain
#

and tbh

rotund token
#

there really wasn't much 'dynamic' in v-rising tbh

rustic rain
#

it can be manipulated further

#

with different simulations

#

indices

rotund token
#

the entire world was mostly static

devout prairie
#

i think something latio does or plans to do is introduce multiple ie rather than just static and dynamic there would be different dynamic for each collider group or something along those lines

rotund token
#

unity physics implemented the whole physics index in 0.50

#

but hasn't really used it

devout prairie
#

as at the moment you're polling the entire dynamic world for a specific set of collision pairs rather than say, each unique set of interactions having it's own bvh maybe

rotund token
#

with a little work you can build some nice query only physic simulations without needing to rebuild

devout prairie
#

i see

#

so how might that work?

rotund token
#

but yeah they definitely have something planned for this, not sure what yet though

devout prairie
#

i think someone was saying it looks like they might plan on making the world partially rebuild also, where there's say a bunch of colliders that don't move, rather than rebuilding the entire thing each frame

#

rebuild is a killer when you have a ton of bodies

#

even just having the sleeping thing in havok makes a big difference

timber ivy
#

what is the new version of IJobForeachWithEntity?

#

I need to be able to have Entity and a component as parameters for a job is that still possible?

rustic rain
#

ForEach loop or IJobEntity

#

both are codegen

#

and IJobEntityBatch in a nutshell

rustic rain
#

bruh, again troubles with filters, types and etc

#

static bodies don't raise trigger events?

rustic rain
#

nvm they do

drowsy pagoda
#

Alright back to moving entity into another scene at runtime. By using EntityManager.SetSharedComponentData both SceneSection and SceneTag it's not working. It's as if some other system is reset the data the moment I change it. Or at least I think I changed it. I confirmed in debug log that the data in SetSharedComponentData is indeed correct (representing the target scene I want to move them to). Someone else have any experience with moving entities to scenes at runtime, please let me know.

viral sonnet
#

why is BelongsTo in CollisionFilter important?

rustic rain
viral sonnet
#

isn't that all defined in CollidesWith

rustic rain
#

then you'd be somewhat limited with CollidesWith

#

meanwhile with 32 bit version you can literally have any layout you want

#

for example, let's say you have player

#

and you want some unique interactions with him

#

but you also want to have some interaction that doesn't know about player

#

or any other layers

#

so instead you just assign player to that layer, that some interaction works with

#

and voila

thorny halo
#

Hello, I'm looking to save a NativeArray to disk without copying into a managed type, however, I can't seem to find resources on how to reinterpret the array to a managed type, which is what Streamreader/File from the System library requires. Perhaps unity has some packages for saving and loading NativeArrays to/from disk?

rustic rain
#

Aand you can't do that anyway

#

managed array would need new allocation

#

can't be done on top of native

viral sonnet
rustic rain
viral sonnet
#

yeah, i can't read ๐Ÿ˜„ no idea why that matters.

#

still, can be done in a non-bursted job

#

just read the nativeArray

#

non-bursted because that gives you access to system.io reader/writers

rustic rain
#

I mean, simply ToArray is probably enough

#

I'd think it's batched so

viral sonnet
#

i need to invest into some ordered chunks. i'm getting pretty sick of references

#

if the order is the same i can reference correlating chunks via a chunkcomponent. then i can just access by entityIndexInChunk

#

this all should be deterministic, so i think it's quite possible to do so

devout prairie
#

you lost me at 'i'

rustic rain
#

yeah me too

viral sonnet
#

haha ๐Ÿ˜„

#

i have a spellcaster entity and a physics entity. i could merge them but physics takes up a lot of chunk space so i think it's for the best. spellcaster has no position or anything. both entities reference each other. there are multiple occasions where the spellcaster or the physics entity needs data from one another. i have to do a costly lookup to get the data then. but, every spellcaster has a physics entity and vice versa, so they should align in their respective chunk.

#

you getting my drift dogs?

rustic rain
#

well, I'd say

#

you should just make your costly calculation async

#

whatever entity that needs result of that calculation makes a request

#

systems run

#

it reads result of request

#

this way your heavy calculations can be done with chunk iteration

#

and you can store all data you need in request component

viral sonnet
#

making a request means a write action. that's not making it faster

#

the lookup isn't that costly. it's a CDFE after all. i just find it superfluous to do a lookup for something that's known and every time the same

rustic rain
#

well, it depends on how heavy your calculation is

viral sonnet
#

my current implementation does lookups and caches them in pointers. this takes 0.3ms for 250k

devout prairie
#

whats the difference between that and the CDFE version?

viral sonnet
#

at least that way i only need to do 1 per frame

#

hm, not that much on the surface. it's more for advanced usage then. i can memcpy whole comps for example. i can't do that with CDFE

#

like, copy every position from the physics LTW to the spellcaster translation

devout prairie
#

i often wonder what the impact would be of say.. splitting up components into just single value components, and only passing in the comps/'values' needed.. ie rather than having say a health component that has health/maxhealth/whatever, split those up into individual components.. would there be a benefit to that.. or for example if ECS only pulled in the values used from components inside jobs

viral sonnet
#

there's quite the benefit of single value comps with simd

devout prairie
#

yeah i do wonder about that.. so thinking in terms of values rather than components that are groups of values

viral sonnet
#

and with my proposed method i'd be able to get a whole nativearray of the referenced data. 1 lookup per chunk

#

i see it this way, we are game devs. we always deal with references in some sense. the naive ways suck pretty hard. :/

#

something i'd really like to figure out how to do better

#

and my first idea of aligned chunks goes way back ^^

devout prairie
#

it's funny i'm looking at a similar problem myself at the moment and i'm thinking, rather than worry about efficiency i'll maybe for now just lump everything into a single component, just to get things up and running, and then split it up later.. in one case i'm doing similar, a CDFE for get 'parent' values while iterating over 'children' and i'm thinking is there a better way.. in other case i'm splitting my values into two different components but actually i'm pretty much always using those two components together anyway

#

i'd be curious how your proposed idea would work, tbh i know very little about the under the hood technicalities of chunks etc and work pretty high level with dots

#

at some point i'll look deeper into all that, utilization etc, but for now, the task at hand is complex enough without micro optimization ๐Ÿ˜›

viral sonnet
#

i made a test quite recently. the job used all the data i was merging. and i merged all into 1 exact 64byte struct. to my surprise the job was significantly slower

devout prairie
#

same data but merged into a single comp and it was slower?

viral sonnet
#

yep

#

all data was touched

devout prairie
#

i wonder if it gets optimized out

#

ahhhh

#

interesting

#

how is that possible i wonder

viral sonnet
#

i didn't really figure it out why. i was using refs too for writing.

devout prairie
#

hmm maybe it's a layout thing in some way, not sure

viral sonnet
#

anyway, 1 value comps are king. tbh ecs and simd expects that

devout prairie
#

not sure the cache implications of either approach, ie large comp vs split into smaller comps

#

right

viral sonnet
#

that's why i made it 64 bytes. to get all in 1 cacheline

devout prairie
#

would be very interesting to test, split comps up into a bunch of single values

#

under different circumstances

#

i do remember reading it's better to split up heavy calculations etc into multiple smaller jobs than do it all in one, if possible

#

i think even if it's working on the same data.. but again, would be interesting to test that out

#

see the thing is with Unity, a little bit of community engagement and they could have people doing all this work for them

#

running tests, benchmarking different approaches, etc

#

a lot of the things we chat about on here are problems that should have been solved already

#

just go the Blender model and open source Unity 2.0 ECS ecosystem and let us build it together

#

they can still monetize the ad platforms etc etc all they want

viral sonnet
#

yep, they are really hands-off when it comes to community. wasn't always the case. before going dark they were pretty open and interested

rustic rain
#

I am sceptical on this one

devout prairie
#

fair enough to be sceptical, i do look at the success of blender though and think, why not.. blender is sitting right on the bleeding edge of tech, is rapidly evolving, and the model seems to work ๐Ÿคทโ€โ™‚๏ธ

#

it's beating the hell out of the competition hands down, with the exception of maybe houdini

viral sonnet
#

reading data is costly too, so you want to do it only once and keep it in stack.

#

my first iteration of the project was based on this. no idea who started that claim ^^

devout prairie
viral sonnet
#

ok, yeah I'm pretty sure they expect to work on seperate data. tertle did mention the same thing, that he started merging jobs and it helped a lot

devout prairie
#

i do think at times, should i just merge all this logic into one job or one system rather than splitting it up just for the sake of being more organized and modular

#

obviously doing that might mean also merging some components into bigger comps, or even the opposite actually try splitting data into multiple smaller or even single value comps, why not

rustic rain
#

I finally came to a point I need it aaaand... It uses your private UnsafeListPtr<T>

rustic rain
#
                    var e = buffer.Instantiate(prefab);
                    spawner.lastSpawned = e;
                    var prefabDepth = ltws[prefab].Position.z;
                    buffer.SetComponent(e,
                        new Translation
                        {
                            Value = new float3(spawnerPos.x,
                                spawnerPos.y + spawner.random.NextFloat(spawner.maxHeight),
                                prefabDepth)
                        });

hmmmm

#

is there a way I can do smth like that?

viral sonnet
#

i don't see why not. the only problem i see is spawner.lastSpawned. does it get patched?

rustic rain
#

this is runtime

#

and it doesn't work

#

kek

#

I get tons of this

viral sonnet
#

spawner would need to go through buffer.SetComp to be ptached

rustic rain
#

probably because field is not remapped

#

uh huh

#

I guess this is the moment when logic separation is required

#

hehe

viral sonnet
#

where is the error coming from? from the lastSpawned?

#

the rest looks fine

rustic rain
#

it comes from accessing this entity

#

so yeah

#

I guess it needs remapping

#

and logic separation

viral sonnet
#

just do buffer.SetComponent(spawnerEntity, spawner)

#

it'll get patched at the end of frame then

rustic rain
#

well, that's a lot of data

#

to pass

#

I'll move that field to separate component

viral sonnet
#

makes sense

rustic rain
#

oh god, smth went really wrong xD

viral sonnet
#

lol, i'm always amazed how easy it is to rewrite stuff in ecs ๐Ÿ˜„

#

run this query on other entities, add some data here, copy it there. and no care in the world that it would break something else. what a relief

#

in bigger OOP projects I nearly went mad what every change implicated

#

guess it's easier when your mental image of a project is just a fraction. a blissful state, but when not, man, pretty exhausting

worldly isle
#

How do I do a simple trigger with unity Dots? I have been reading through the physics sample and all I can see is raycasting or collider casting. I just want a simple box trigger zone and I want to apply a tag to anything that is inside that box trigger

#

I can't seem to find anything about this in the documentation nor the source examples

drowsy pagoda
#

Is there a dots equivalent to UnityEngine.Bounds.Encapsulate() but with AABB ?

rotund token
#

MinMaxAABB has the method

#

AABB stored as Center/Extents
MinMaxAABB stored as Min/Max

#

they can be implicitly converted between depending on your required operation
there is the cost of calculation for converting hence they have different methods and the one you use should be dependent on the operations you do most frequently

#

e.g.
a lot of encapsulations? keep it in MinMaxAABB
a lot of contains? keep it in AABB

drowsy pagoda
#

got it, thanks

viral sonnet
#

hey tertle, have you read what i wrote about aligned chunks?

#

and i can't remember, did you ever successfully use an unsafelist in a chunkComponent?

rotund token
#

as for aligned chunks dont recall reading anything

viral sonnet
#

and this is a chunk that always exists, right?

rotund token
#

oh wait sorry

#

i replaced my unsafelist

#

with an UnsafeParallelHashSet

#

for some optimizations

viral sonnet
#

i got the conceptual problem with this idea how to dispose the unsafeList

rotund token
#

i just dispose in OnDestroy

#

private NativeQueue<UnsafeParallelHashSet<ArchetypeChunk>> chunkLists;

        {
            while (this.chunkLists.TryDequeue(out var list))
            {
                list.Dispose();
            }

            this.chunkLists.Dispose();```
viral sonnet
#

other than aligned chunks, i could also call them parallel chunks. all i need would be a list of chunk that are parallel because the chunk capacity could differ and a startIndex of the entityIndexInChunk

#

the goal is to reduce reference lookups to 1 per chunk when entities are linked or have linked data

rotund token
#

how do you intend to force all entities in 1 chunk reference all entities in another chunk?

#

this was one of my bottlenecks i had to solve when testing 100m

#

i had 650 entities/chunk

#

but each chunk referenced ~145 other chunks on average

viral sonnet
#

i haven't thought this through for more than 1 reference tbh. starting small ๐Ÿ˜„

#

would require a list of 2 levels. 1 for the reference type, 1 for the chunks involved

rotund token
#

the only solution I thought of to improve this was shared components

#

but this doesn't really work until unmanaged ones

#

doing 1:1 shared components is not memory viable

viral sonnet
#

yeah