#archived-dots
1 messages ยท Page 8 of 1
I dont think it will be relevant for my use case my subscenes are only 100x100 meters
still better to have 1 subscene
if it's all connected world
rather than multiple
I think...
The only thing I see relating to sections in SubScene is IsSectionLoaded
am I missing something?
i guess you got to implement it yourself
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
hm
found this component
maybe this is how you define sections
yyep
the downside I guess is that in editor you won't have any distinction between loaded sections
so you just add that to your scene entity?
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
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
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
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
from what I noticed
each section gets it's own world bounds
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;
only unloading subscene works
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;
oh you mean by editor?
have you tried via code though?
so I'd assume subscene is simply unloaded
and now if I try to load section 1 with unloaded subscene
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.
yeah
seems like Section 0 is root of Subscene
allthough they are created as different entities
hmm
right is section 0, left is section 1
maybe editor limitation
now you don't see it
what i'm saying!
I'd worry about it though
what if in future it'll be limitation of runtime as well? xD
why?
Can simply be defined as pattern though
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?
You can't nest foreach
how would I check if an entity exists in a foreach loop then?
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
get the KernelSlot by ref via ElementAt from the nativelist.
@rotund token what did you optimize in addition to removing the memcpy?
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
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.
ah alright, i think i was still awake for that ๐
can't you just create your world chunks in conversion?
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
I have paused that for now until I ccan get something work with loadsceneasync
haha
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
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?
you can
but be ready for Dependency troubles
hehe
seems like you are new to this
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
In case you have troubles with Dependency
#archived-dots message
here my convo with tertle
about how Dependency works internally
no this is actually an error that says that you can't change world structure
awesome that will come in handy
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
So what can I do in this situation?
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
You are looping on an entity that would already have this component. This is suspicious
im trying to set the value of the component
use
chunk = new WorldChunkComponent {...}
if a ref goes into the the entity loop, its read/writeable
no need to set component
throws the same exception
same exception
what exception
Structural changes are not allowed during Entities.ForEach. Please use EntityCommandBuffer instead.
so I guess
its what you said before
just can't do it ccause I got another job messing with these entities
you can't use EntityManager here
kek
you also do
LoadSceneAsync
which is also structural change
also that part is just ๐
why?
should I be using getExistingsystem instead?
and yep
that was the issue LoadSceneasync causing structural changes
time to do it with createntityinstead :/
rip
ye I just saw that SceneSystem too
just cache it in OnCreate -_-
besides
you always should use GetExisting
because all of them are already created
by the time OnCreate is called
@timber ivy This might be of help for you. I havent tested it but maybe it will give you some insight.
Oh awesome I will give this a look over in a bit when I am home. Thank you for the example
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?
By "nothing allowing" I mean components and systems btw
If you're trying to nest collections, use the Unsafe X variants.
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
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
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.
Check the source (I deleted it once I finished) to see if there is a none component query to gather the initial data for the BVH construction.
Dots physics has a BVH tree, two of them, one for static and one for dynamic objects to reduce rebuilding cost. A BVH tree is just 2 native arrays sized N bodies * 2 - 1.
nope ... ๐ฆ
Oof, well uh, maybe selectively remove and add physics world index?
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
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.
oh really? i have 8.7ms for 250k
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.
the stateless nature makes it really slow
8.7 for not doing anything is horrible in my book
It rebuilds every frame. Such is stateless
Is the n * 2 - 1 for interlacing values or am I misunderstanding? How would queries work if you can't grab the partition without looping the whole array? Sorry for all the questions ;-v-)y
yeah but it's not colliding or smth. it's just idle.
It needs to first figure out if something is colliding. Idle should be handled by the change filter though
But IMO, float instability means things get changed regardless even if nothing moves
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
Just google BVH, it is originally a rendering tree for ray tracing.
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
I just duplicated my test entity to 250k and ran a root node AABB calculation. It takes 4ms just to calculate it. Are you sure that's right?
Wow, this is incredibly fascinating. Thank you a tonne for helping! I had no idea BVH even existed until now and I had been searching it with Unity while you were mentioning it at first and couldn't find much ( ;-v-). I'll be working on implementing this now :P. You've been super helpful! Thanks~!
going down to the root of it. my ai job touches rotation every frame so there's the issue it's rebuilding ๐
not that rotation does anything for a capsule collider. meh, have to introduce a quaternion dot to not write back all the time :/
Solid green. I disabled the BVH builder so thats why it's so fast.
how many entities?
250,000
you mean 250k sprites?
yea. A single sprite = 1 entity
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.
a whole BVH has to be rebuilt because one entity moved? is that a normal implementation?
or is this a stateless thing again? ๐ฉ
yep
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.
What are the best tutorials on ECS on YouTube? Preferably tutorials series of building demo game ๐
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
Look up moetsi
It's not YouTube
But it's the only series with full demo game in the end
I know of
can you give me a link please? ๐
is that implemented? that's not working for me
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...
Huh, scanning the full docs now that I finished lunch, it's not implemented. BVH from Box2D has that functionality but not Physics.
If anything touches tras/rot then that'll forward onto ltw
i check for changes on trans/rot and they are false
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)
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
I believe there's a way to search by id if you have names, something like i:
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
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
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
Trans, Rot, and Scale = LTW. If anything even does a GetNativeArray to any component, then it gets marked as changed.
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
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
You can turn off systems?
yeah
huh
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
For 50k?
yes
i have a ryzen 5900x
True, different comps. Hrm. The distribution looks the same though and how I expected looking at the source.
so I've fixed the version bumping now . doesn't change the fact though that everytime something moves it spikes quite heavily :/
you'd expect something to move every frame
exactly!
is all your stuff really close together?
it is
just seeing all the stuff basically being in a single branch for second phase
so that's why this is only 1 worker thread?
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
ohhhhh good to know
because that's totally unrealistic
so what's the range here? can this even be measured by range?
You might have a very sequential distribution of nodes. Like a staircase instead of a tree.
oh wait, we're talking about BuildBranches. hm. thought this was about the BuildFirstNLevels because that job takes quite long
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
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.
eh scratch that, i also have a long buildbranches. just too many worker threads that don't fit on my screen haha.
Oh. How many threads?
i see 23
Pleb over here with only 10+1(main). Plz, some spare change threads.
my old i7 also choked along with 8 ๐
Yea, I think 3 of those are virtual. Im on intel i7 as well. Pain.
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
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:
hah! similar! that's faster on a slower cpu
This job would only produce 2 parallel jobs. This will produce 8:
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?
@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.
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
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
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 ...
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.
Optimal target? As in closest one?
Or one that it can see?
nah, the caster already knows which target. just to get the distance between
dot the positions together, dont square root it. Very cheap.
the math is not my issue. getting the data is ๐
There's no other option other than random access unfortunately. You aint gonna get a nice cache line going.
i'm using random memory access to get the position of the target
yep, that makes me sad ๐
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
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.
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.
array[i] =
If you have no inheritance, translation should be the component you read from.
Local to world should only be touched by those actually rendering things or requires full scaling and rotation values.
hm, frag shader. i'd still need to upload/render all my casters then, right?
Yea, you're already requiring uploading of the caster's LtW to the GPU already. However, that's probably buried inside the rendering system / hybrid.
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.
does dots physics alreayd has a method for Quaternion.Angle?
It deals with the wrap around at 2 pi.
actually, it's just 2 pi.
man, i need to sleep ... that's the MB implementation. expected rads
That moment when you press play and the game has 1.5 FPS because a single burst compile tag was uncommented.
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
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
Oh, if you need to rotate things, definitely use LTW. The matrix multiplication is definitely faster than doing cross products.
You dont need with burst, it's on by default.
Debug.log will murder your performance, remove it when profiling.
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.
math.distance is expensive. It requires a square root calculation. Use math.distancesq and square the other side.
the delay is coming from addjobhandleforproducer ig
cause the profiler says its waiting on job.complete
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
Its not done often at all
maybe once every few frames
31 ms waiting on a semaphore yikes
If you have a lot of entities undergoing structural changes, yep. That's expected.
Then it's probably not that job then.
Check the profiler timeline display, what jobs are being waited on
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
Thats a lot of red. That means you have a lot of memory allocation.
The debug.log has been removed right?
yes
and
where am I allocating?
i dont see anything other than that debug.log(which has been removed)
ECB is actually, IIRC, a multi hash map just with specialized keys and values.
so am I better of just doing this in .Run() then?
definitely burst compilation enabled under menu?
Yes its enabled
i think for HasComponent, maybe pass in the ComponentFromEntity rather than use HasComponent inside the job
If you're doing structural changes, it's typically best to do so on the main thread anyways.
Huh
"GetComponentDataFromEntity"
im back to 600 fps after disabling safety cchecks
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.
from 32 ms down to 0.032
What do you mean by this btw?
i was just about to explain..
not sure if it will make any difference tbh but the way i do that would be:
I think the lambda code gen already optimizes it to chunk.HasComponent<>
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);
}
yep, safety checks are costly. that's by far the biggest increase I've seen though
ah does it
so i've just changed HasComponent to passing in GetComponentDataFromEntity
but yeah as KF says possibly it would get optimized to that anyway
ah yeah ill see if this does any better in the profiler
kinda lame the safety checks are hitting so hard to performance
It's only 400 entities. No clue what's going on.
and i have a really good pc
It's not a PC issue for that big of a difference
i dunno, the timeline is all pink, not green. was that still from the debug log?
also you don't need the WithAll as it's already in the lambda
I think Russell had customized his editor colors.
With colorblind mode or something possibly.
I have colorblind mode on
ah wait..
oh, ok ๐
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);
Not for lambdas in fact. That's automatic.
and it isn't lagging with safety checks on now
oh really ๐
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
For systembase lambdas and IJobEntity, dependency declaration and chaining is done at code generation so no need to do it manually
ah ok, thanks for that i didn't realise
For system structs, yea. gotta do it by hand
System structs?
It looks nice and slick though
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
it does.. where are your nativearrays being disposed?
Allocator automatically disposes of it.
Like magic. It's like GC
Built in. It's under World.UpdateAllocator
ohhh
hm, can't find anything on that subject. can a quaternion be flipped like a vector by 180 degrees without multiplying?
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).
you can do math.inverse(quat) i think is equivalent?
that's useful
not sure about that. quat inverse is used for reversing multiplications ie. to divide
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
inverse has a dot product. :/ issues issues. fk it. let's go back to ltw
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
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
I think inversing the LTW is just applying a negative identity matrix.
I think... i dont know
inversing in itself isn't really useful unless you'd translate from world to local rotation or smth
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
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
yeah
quats have no division. that's why the inverse is golden
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
i'll test this quickly.
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
yep, and it's pretty ideal
i always think of raycasts etc as slow coming from a mono/unity background
going back to unity5. god damn! it's fast
but i think in the case of unity.physics and dots it's pretty much just dipping straight into the broadphase bvh
BVH is specifically built for raycasts. It's originally a raytracing tree. In fact, it's still used for raytraced lighting.
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.
there is a way to get Forward from quaternion i think
not sure if it's helpful
what exactly is happening there?
yeah, multiplying rot with 0,0,1
the green line is the forward and the red one is the inverse of the rotation
ah!
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.
so i think convert the target to source space maybe
i really struggle with those maths though, so there maybe some dot shortcut!
Use the vector formed from subtracting the position of the target with the source. Dot it with the forward vector of the source. If it dot is negative, it's behind. If it's positive, it's in front. Then for the flank, arccos the dot product to find the radian angle.
this guy
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); }
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.
dot is really nice, yeah ๐
dot is so good, unity named their new technology DOTS.
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
Apparently dreamworks are making their render engine open source btw:
https://www.youtube.com/watch?v=wk-WztzAjGE
obviously it's an offline renderer, but interesting of them to do that
Pixar and dreamworks are amazing because of the artists they have, not the quality of their engine frankly.
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
They were pioneers in the field dont get me wrong
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
weren't they also involved in blendshapes?
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
Never heard of that no.
But it would make sense.
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
There's no comments on priority though
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
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
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?
Depends
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
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?
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
It's not random, but yeah I think I get it
var sceneSectionComponents = new List<SceneSection>();
EntityManager.GetAllUniqueSharedComponentData(sceneSectionComponents);
I got the shared components. How do I iterate each chunk per shared component from here?
Get entity query, apply shared component filter
Get chunks
Repeat foreach
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
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?
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
I see
is it valid to cache Entity/other components in a component? or is there some special steps I must take?
Ugh, multithreading is pain
yeah, why not
with entities there's a problem of checking tho
you'd need to check whether entity still exists
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
Entity in DOTS is just 2 uints in a single struct
Singlethreaded, works perfectly fine and stable BVH tree. Multithreaded, all over the place. Ugh.
huh weird my entites auto generated by subscenes dont render in the game view
only in scene view
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();
allocated?
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
Might want to have a quick read of: https://docs.unity3d.com/Packages/com.unity.collections@1.4/manual/allocation.html
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.
it all gets easier after hitting your head against the wall several dozen times
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
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
try OnStartRunning instead of OnCreate
this is COnversion System
oh i see. did you refresh entity cache?
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
i havent got around to doing mesh yet but everything else is there
provides this
oops just noticed typo
should be vertex1
๐
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
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.
well if it's unlikely it's probably not adding much uncertainty?
exactly. but it adds some. so if i remove it the entropy should decrease slightly right?
hmm
who do I need to give internals access to
So files in Editor folder
can access it?
Editor namespace didn't work
i just have an assembly with asmref to basically everything
this is just unity.entities
hmm
I can't get it to work, weird
can't get internals
for custom assembly
in Editor folder
How comes?
What does editor folder have to do with it?
idk, it just doesn't work
I declared asmref
created reference to Entities
and created [assembly; InternalsVisibleTo("nameOfasmref")]
aaaaand, still can't see internals
And get hash is in nameofasmref?
yeah
both in same file in same namespace
holy
finally
made it work
now another trouble
nvm
Rider broke everything
kek
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
really depends on frequency
we use overlap sphere for our attacks though
but we only do 1
i mean say a unit swinging a melee weapon
i could optimize by only doing the collision query during swing
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)
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
is it possible to write to a native array in an entities.foreach job?
cause this is throwing dependency errors
yeah just use Allocator.Temp rather than TempJob
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);
Pass the Array in with WithReadOnly
doing that throws an exception telling me to use TempJob
oh
let me try that
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
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
ah
Dependency = Entities.ForEach and also ScheduleParallel(Dependency)
Doesn't codegen do that?
Although KornFlakes tells me this is handled automatically now
yes
_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
is there a way to create children of physics bodies
which one is it?
PhysicsMassOverride
hmmm
/// 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;
}```
so just add that component and toggle it on/off as required
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
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
๐ค
or just use a compound collider and figure out what part it hit
even if both bodies kinematic?
I assume static bodies simply won't even move their colliders with LTW
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)
}
});```
but do static move with LTW?
?
I move static bodies
is it much worse than rebuilding kinematic world?
there's no point in making a collider static if your'e going to move it
you're slowing yourself down
well instead of building just dynamic world
now you're building static + dynamic world
you have 0 optimization
sure but you're extremely limiting number of colliders you can have now
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
so, do you think it's an ok case for such mutilation of physics engine? xD
oh i hadn't seen this either
only between 2 bodies
ground and player
and only when player "dies"
basically a fancy death animation xD
i think that's kinda along the lines of what the VRising guys were doing, although i think they modified the physics engine itself
it's not really modification, it's just... using smth not the way it was meant to be used
but i think they were setting everything as static and maybe manually rebuilding when needed, or something, and moving static colliders around
yeah
and tbh
there really wasn't much 'dynamic' in v-rising tbh
the entire world was mostly static
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
unity physics implemented the whole physics index in 0.50
but hasn't really used it
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
with a little work you can build some nice query only physic simulations without needing to rebuild
but yeah they definitely have something planned for this, not sure what yet though
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
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?
bruh, again troubles with filters, types and etc
static bodies don't raise trigger events?
nvm they do
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.
why is BelongsTo in CollisionFilter important?
because if layers don't overlap no collision will happen
isn't that all defined in CollidesWith
well, if you only had 1 layer, like classic physics
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
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?
why copying is an issue in the first place?
Aand you can't do that anyway
managed array would need new allocation
can't be done on top of native
NativeArray has ToArray which is managed
but that's still a copy. I assume it matters to him somehow
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
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
you lost me at 'i'
yeah me too
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?
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
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
well, it depends on how heavy your calculation is
my current implementation does lookups and caches them in pointers. this takes 0.3ms for 250k
whats the difference between that and the CDFE version?
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
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
there's quite the benefit of single value comps with simd
yeah i do wonder about that.. so thinking in terms of values rather than components that are groups of values
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 ^^
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 ๐
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
same data but merged into a single comp and it was slower?
i wonder if it gets optimized out
ahhhh
interesting
how is that possible i wonder
i didn't really figure it out why. i was using refs too for writing.
hmm maybe it's a layout thing in some way, not sure
anyway, 1 value comps are king. tbh ecs and simd expects that
not sure the cache implications of either approach, ie large comp vs split into smaller comps
right
that's why i made it 64 bytes. to get all in 1 cacheline
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
ahem
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
I am sceptical on this one
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
i think he was talking about this. and yeah, that's a myth.
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 ^^
yeah i'm pretty sure i read this in the docs recently, in passing
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
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
I finally came to a point I need it aaaand... It uses your private UnsafeListPtr<T>
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?
i don't see why not. the only problem i see is spawner.lastSpawned. does it get patched?
spawner would need to go through buffer.SetComp to be ptached
probably because field is not remapped
uh huh
I guess this is the moment when logic separation is required
hehe
it comes from accessing this entity
so yeah
I guess it needs remapping
and logic separation
just do buffer.SetComponent(spawnerEntity, spawner)
it'll get patched at the end of frame then
makes sense
oh god, smth went really wrong xD
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
useful
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
i just linked the important scripts here. it's best to load up and look at these samples
Is there a dots equivalent to UnityEngine.Bounds.Encapsulate() but with AABB ?
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
got it, thanks
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?
i only have 1 chunk component and it uses an unsafe list
as for aligned chunks dont recall reading anything
started throwing the idea around here: #archived-dots message
and this is a chunk that always exists, right?
oh wait sorry
i replaced my unsafelist
with an UnsafeParallelHashSet
for some optimizations
i got the conceptual problem with this idea how to dispose the unsafeList
i just dispose in OnDestroy
private NativeQueue<UnsafeParallelHashSet<ArchetypeChunk>> chunkLists;
{
while (this.chunkLists.TryDequeue(out var list))
{
list.Dispose();
}
this.chunkLists.Dispose();```
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
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
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
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
yeah