#archived-dots

1 messages ยท Page 187 of 1

zenith wyvern
#

I wouldn't say ECS is unstable or buggy

#

Usable....highly questionable

safe lintel
#

incomplete is how i would phrase it. ymmv depending on your ability to overcome whats missing

median glen
#

What about Unity's new multi-player solution

#

When will THAT be ready

#

Lmao

safe lintel
#

i cant answer that

median glen
#

No one can lmao

safe lintel
#

simple questions of when its ready you should bring to them on the forums

median glen
#

It probably doesn't even exist

#

Imma become a conspiracy theorist to expose unity

sand prawn
#

I found NetCode didn't suit my purposes, but DOTSNET was good enough (and quite performant on the server side)

tired mulch
#

I'm also having some thoughts about if I should use NetCode or not, or if I might go with a different approach.
I'm currently writing a 2d shooter game with ECS, where I create pretty much everything from code (custom renderer etc).

NetCode as I've seen does everything with prefabs when it comes to creating players / objects that should be predictable (Ghosts) etc.
Is there some form of workflow where I won't need to create prefabs for everything, because that doesn't really fit the creation of a 2d game using spritesheets with a custom renderer etc.

I thought about possibly using Unity Transport to create my own custom solution and maybe borrow some concepts from NetCode.
Any advice would be appreciated!

stoic monolith
#

Ok just wanna confirm.
U can NOT interact with unity default physics (physx) from Jobs, right?

stoic monolith
#

What are ParallelForBatch for?
I wanna update all my PS particles in a single big nativearray for locality, is this possible? Like, give array of particleSystem as input for the job?

zenith wyvern
#

If you mean IJobParallelForBatch it lets you a define a batch size, so the scheduler will spawn one job for each batch size until it hits length

#

So you could have a bunch of jobs running over N different elements of a single container

stoic monolith
#

But the ParallelFor also got a "minIndicesPerJobCount", what's the difference?

#

Oh wait, so parallelFor actually executes per index, while batch executes a range of index

zenith wyvern
#

Exactly

stoic monolith
#

Ok im still trying out the different jobs

But really, my case is, i got on average 100 PS at a time, just 30 particles each
If each PS schedules its own job, im kinda suspecting it's not very efficient?
That's why i'm looking into how to combine all the particles from all the (registered) PS to be handled in a bigger "batch".

Bcoz well, in my case the max batch size for each of the PS will only be 30 and that's kinda small i guess?

zenith wyvern
#

I would say it would be better if you could combine a bunch of your particle systems and feed them into fewer jobs, yeah. No idea how you would do that though, sorry

stoic monolith
#

Yeah i did this in the past. At least in the actual game, the same "Skill" just asks the particle manager to spawn x amount normall (to make use of the spawn parameters) then offset by the pos/rot requested

Anyways hmm, yeah i'll have to think about this a bit

#

Oh wait just another confirmation

So the difference between the ParallelFor and the Batch, in terms of use case, is i guess..

ParallelFor works on each index. So i assume this is better for a "heavier" element in the array
Whereas the Batch is more for the "smaller" element arrays, a single Execute can zip through a bunch at once so its better for bigger element arrays

zenith wyvern
#

Yes, parallelfor is for when you need to do a lot of work per index. ParallelForBatch is for when you need to do less work but have a lot of indices to go through

#

You wouldn't want to use ParallelFor for very large arrays since you'd be creating a lot of overhead from all the job scheduling

stoic monolith
#

In the context of particles, then i'd say i'd have to really do some weird stuff on single particles to really make use of the ParallelFor, i guess?

zenith wyvern
#

I would think doing everything in a single job would be fine, especially with burst

#

Don't underestimate how fast it can tear through linear arrays

#

Even huge ones

stoic monolith
#

Im testing gradually to 1 job for 3000 elements
Yes it reaches 200fps eventually(the highest out of all the numbers), but always starts slow on the fps. Like it needs to warm up

zenith wyvern
#

I've heard burst jobs won't compile for the first couple of runs. So it will run slow a couple of times then go insanely fast

#

That's been my observation with my pathfinding library

stoic monolith
#

2job x 1500array, gets to 200fps in like 20secs
1job x 3000array, wow really slow. 5fps for 30secs, 100fps in 1 min, and now like 1.30 mins finally gets to 200

gentle osprey
#

Hey, is there any constraints I could put on my generics that would make this possible? I have some places where I need to convert stuff from UInt16 to Int32, etc, and would like to avoid having to type out all the permutations

        public struct ConvertJob<T, U> : IJob 
            where T : struct
            where U : struct
        {
            [ReadOnly]
            public NativeArray<T> Src;

            [WriteOnly]
            public NativeArray<U> Dst;

            public void Execute()
            {
                for (int i = 0; i < Src.Length; i++)
                    Dst[i] = (U)Src[i];
            }
        }

Like, some where T : Castable<U> or something.

zenith wyvern
#

Are you sure you're running with burst on and safety checks disabled?

stoic monolith
#

But my profiler still looks like this
(Yes i'm dealing with unity physx so that must be the big overhead)

zenith wyvern
#

Hahah...yeah it certainly looks like physx is your bottleneck there

#

I don't think there's a way to add castability to generic constraints

#

C# generics are pretty limited

gentle osprey
#

I see, shame. Thanks anyway :)

zenith wyvern
#

@gentle osprey UnsafeUtility.MemCpy(Src.GetUnsafePtr(), Dst.GetUnsafePtr(), Dst.Length); You could try something like that...I'm assuming that wouldn't end well

#

But maybe something along those lines

gentle osprey
#

That would break due to different memory representations no?

zenith wyvern
#

Almost certainly

#

What about...

#

var arrayOFU = Src.Reinterpret<U>();

gentle osprey
#

Would break for the same reason as MemCpy.

zenith wyvern
#

Oh yeah that seems potentially promising

gentle osprey
#

Though, I don't get what the documentation is trying to say, because incrementing the destination with both destination and source stride makes no sense to me.

zenith wyvern
#

Yeah I'm staring at it trying to make sense of it. No idea

stoic monolith
#

Can i have a continuously running Job, without the the main thread ever needing any nativearray access (or not even use any nativearray at all)

#

So i dont have to schedule every frame whatsoever. Only once, or "once in a while" ?

dusty sleet
#

Hi guys, I found that if I don't restrict local native array as readonly, I can't access its elements other than the the same id as entityInQueryIndex one. Why is that?

stiff skiff
#

Likely because it doesnt know if you're reading or writing there

#

It just checks if the index is outside of it's allowed range

#

which is fine when reading, but could cause race conditions when writing

dusty sleet
#

so if I do want to write, I can't write to other index of that container?

stiff skiff
#

Pass in a copy of the same array

#

To give a clearer example of the issue here. Lets say your array had 4 values. index 0 1 2 3.

#

Lets say this is split over 2 jobs

#

then job 0 will be reading from 0, then write to 0. Then read from 1 AND 0, and write to 1

#

job 1 will read from 2 AND 1, then write to 2, then read from 3 AND 2, then write to 3

#

Notice how job 1 is reading from 1, while job 0 is writing to this

#

if this happens at the same time, you have a race condition and stuff breaks

dusty sleet
#

oh I understand, so the read and the write happens on two arrays. so no problem

odd cipher
#

In ECS, is using 'in' instead of 'ref' any faster?

deft stump
#

yes.
the burst compiler can expect to just read the data.

karmic basin
#

In is readonly, ref is to update. Si yeah prefer in if you only need to read a var

amber flicker
#

always want to use in where you can - if you test it in isolation it might not appear much/any faster but it makes a massive difference at scale due to the scheduling

odd cipher
#

Alright nice

stoic monolith
#

I have Mathematics installed but can't do using the namespace?

amber flicker
#

are you using asmdefs? Have you added a reference to the package if so?

stoic monolith
#

Ah that's probly it

#

Sorry another question (since dots people deal with package headaches often)
How do i uninstall package, if it's not showing in the package manager?
This is Newtonsoft json, apparently it's conflicting bcoz i have 2 of them?

amber flicker
#

if it's not showing in the package manager you may just need to enable 'show dependencies' in the project settings but the easiest way is just to edit the manifest file directly

#

which is in the `Project/Packages' folder

stoic monolith
#

I still cant find it in manifest..

#

A very recent problem it seems

amber flicker
#

hmm haven't seen that, are you using some 3rd party thing with a version in? If you haven't tried it yet, it's always worth trying a complete rebuild of your library.

odd cipher
#

I'm trying to make a quick utility to make it easier to instantiate entities from prefabs but it for some reason gives an error saying that the 'settings' variable is null. I'm not sure why it's null. ```csharp
static EntityManager entityManager;
static BlobAssetStore blobAssetStore;
static GameObjectConversionSettings settings;
static Dictionary<GameObject, Entity> prefabsAsEntities;
static bool initialized = false;

public static Entity Instantiate(GameObject prefab) {
if (!initialized) {
World defaultWorld = World.DefaultGameObjectInjectionWorld;
entityManager = defaultWorld.EntityManager;
blobAssetStore = new BlobAssetStore();
settings = GameObjectConversionSettings.FromWorld(defaultWorld, blobAssetStore);
Debug.Log("A");
}

if (!prefabsAsEntities.ContainsKey(prefab)) prefabsAsEntities.Add(prefab, GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, settings));
return entityManager.Instantiate(prefabsAsEntities[prefab]);

}

amber flicker
#

would recommend you avoid statics - my guess is you will almost certainly run into problems trying to e.g. store a static of the BlobAssetStore like that

odd cipher
#

I suppose that makes sense, I'll make it into a GameObject instead and see if that works.

amber flicker
#

hmm static methods are fine but I'd suggest e.g. passing in the EntityManager as a parameter

#

actually, I'm not sure you want to be creating a new blob asset store like that

odd cipher
#

It's how I've done it before and it worked so I'm not sure why it wouldn't work now

#

but as I mentioned the error is that the settings variable is null even though that line that sets it gets executed.

amber flicker
#

try passing in null instead of blobAssetStore

#
Entity entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObject, GameObjectConversionSettings.FromWorld( World.DefaultGameObjectInjectionWorld, null));
``` works for me
odd cipher
#

Nope, same error.

amber flicker
#

paste the error - also when are you calling this?

odd cipher
amber flicker
#

according to what you pasted line 18 is saying nullrefexception for prefabsAsEntities[prefab]

odd cipher
#

Ah yikes, I thought it was referencing the settings but the problem was that I never created the dictionary

#

well, that's embarrassing

stoic monolith
#

Hi guys
So i'm doing some IJobParticleSystem, and the docs suggests to call this in OnParticleUpdateJobScheduled bcoz that's when the default PS simulation would already be scheduled.
Is it possible to simulate fast forward the default job inside ur job?
So if normally i schedule a "move particle towards a pos" job per frame. I wanna do 5 seconds worth of this (5 x framepersecond) taking into account the default PS simulation

Possible?

odd cipher
#

So for context, I need to be able to find the closest entity with a certain component from another entity. And there are thousands of those entities. I'm not sure what a good way would be to go about this without causing lag problems. I suppose something like a quadtree could work but I do not know how that would work in DOTS. I do use the Physics package so that might have something, dunno.

olive kite
#

Is anyone else experiencing emission not working after converting to entity?

deft stump
odd cipher
#

Do you think you could explain the 'query first a singleton entity' a bit further? I'm not sure I understand

karmic basin
#

I think he meant "single" entity ?

#

Try YouTube Channel of Code Monkey, he has a good spatial search tuto with quadtree

odd cipher
#

Oh! I didn't know he had a video on that, I saw the original Find Target video which wasn't very efficient in my case, Hopefully this will be much better.

#

Thank you for mentioning it

karmic basin
#

You're welcome. Happy coding.

stoic monolith
#

How do i debug this?

I have LeakDetection Full Stack Trace and there's no difference

deft stump
#

do you have any Native Containers that are set as TempJob?

#

check if any of those aren't being disposed

stoic monolith
#

Yeah it was an error elsewhere.. ๐Ÿ˜„

stoic monolith
amber flicker
#

@stoic monolith because you're comparing 3 elements - you can use e.g. math.all(tr == float3.zero)

stoic monolith
#

Is that the same as this btw?
tr.Equals(float3.zero)

amber flicker
#

that's also good yup ๐Ÿ‘

stoic monolith
#

Ive been using Allocator.Persistent most of the time
So i have a single PS for a shot skill, it can last anywhere between 1sec to 20sec
I have nativearray<byte> to store the state of each particle, bcoz it's relevant for the whole lifetime
Then i also have array for positions of all particles. It used to be TempJob but now i'm changing it to Persistent too
Is this... appropriate?

maiden delta
#

how do i use MotionVelocity to apply forces to rigidbodies in unity/havok physics?

#

but when i try to get it as component data i get an error that it's not component data parameter 'velocityMotion' has type MotionVelocity. This type is not a IComponentData / ISharedComponentData and is therefore not a supported parameter type for Entities.ForEach.

#

and if it's not component data, how do i use it?

hollow sorrel
#

@maiden delta the component is called PhysicsVelocity i think

compact robin
#

Hey, is there anyway to do Physics.Simulate() in DOTS?

scarlet inlet
#

@compact robin probably more than one

#

what we do is to create a world dedicated for the physic and then do world.update

#

ofc this may not work in your case

compact robin
#

What does world.update do?

scarlet inlet
#

it updates all the systems in the world, which for us are basically only the physic systems

#

it ticks them

compact robin
#

Like it calls Update()?

scarlet inlet
#

yes

compact robin
#

But isn't Update() automatically called

#

Or am I missing smth?

scarlet inlet
#

yes it is, we disabled it

#

so it's quite different from the standard

compact robin
#

Oh how do you disable it?

scarlet inlet
#

you must disable the auto system creation and add the system manually in the world

#

when you do that, you just don't put it in the update system

#

if you don't know what I am talking about , I will show you some code

compact robin
#

Yes pls lol I'm new to DOTS

scarlet inlet
#
var physicsWorld = new World("Default");
            
            World.DefaultGameObjectInjectionWorld = physicsWorld;

            physicsWorld.AddSystem(new YourSystem());
#

it is actually straightforward how the systems are managed inside the world

#

if you want to get the standard systems, including the physic ones you do:

#
 world = new World("Svelto<>UECS world");

            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
            World.DefaultGameObjectInjectionWorld = world;
#

tbh unless I would do something very simple, I prefer to use the manual way

#

much more control

compact robin
#

Oh

#

Ok so the first one is adding your own system, while the latter is like the default?

scarlet inlet
#

the latter adds to my custom world all the default systems

#

then I can add mine too

compact robin
#

Meaning it calls update() on its own?

scarlet inlet
#

you know what? I am actually not sure what calls Update() automatically since I have never used it ๐Ÿ™‚

#

but nope, when you do it manually, it's not called

compact robin
#

Oh

#

Do I have to run World.DefaultGameObjectInjectionWorld = physicsWorld;

#

If I just wanna create a secondary world to simulate physics

scarlet inlet
#

no that's only for when you want to use the world from inside monobehaviours that is not a great thing to do anyway

#

you can have only one default world

compact robin
#

Isn't DefaultGameObjectInjectionWorld the world GOs are injected into during the start of the game?

scarlet inlet
#

as far as I understood is a naive way to access to a world from inside a monobehaviour

#

I don't think it's used for GO to entity conversion, but I may be wrong

#

it shouldn't be used IMO

compact robin
#

hmm

#

Ok nice, but I still don't get how to call OnUpdate() manually

scarlet inlet
#

at that point you do physicsWorld.Update()

#

which is what we do as we want complete control over the ticking

compact robin
#

Ohh

#

Rip Im so confused tbh

scarlet inlet
#

I don't blame you, as the automatic system hides too much logic

compact robin
#

Like I wanna step forward by 0.25f

scarlet inlet
#

but in reality is quite simple

compact robin
#

Every call

scarlet inlet
#

time?

#

0.25sec?

compact robin
#

Physics.Simulate(Time.fixedDeltaTime);

#

Which is 0.25 I think

#

By default

#

Like an ECS version of this

scarlet inlet
#
            var currentElapsedTime = Time.ElapsedTime;
            World.SetTime(new TimeData(currentElapsedTime, UnityEngine.Time.fixedDeltaTime));
#

that's what we do

#

you can override the time used inside the systems

compact robin
#

So that steps time forward by 0.25?

#

Or whatever fixedDT is

scarlet inlet
#

you have control on what you want to do

#

yes

#

you don't need to use fixedDeltaTime

#

we do only because we read the value from the editor settings

compact robin
#

Hm

#

This is gonna be hard xd

scarlet inlet
#

yes there are reason why it can get hard of course

compact robin
#

I think its the lack of documentation tbh

#

ECS as a concept is not hard imo

scarlet inlet
#

this in fact is not about ECS

compact robin
#

Yeah

scarlet inlet
#

it's confusing because with the auto ticking/creation you don't know exactly what is going on

#

but studying it is useful

compact robin
#

Ok so just to reemphasize

#
var physicsWorld = new World("Default");
            
            World.DefaultGameObjectInjectionWorld = physicsWorld;

            physicsWorld.AddSystem(new YourSystem());
#

This wouldn't auto-tick right

#
world = new World("Svelto<>UECS world");

            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
            World.DefaultGameObjectInjectionWorld = world;
#

But this will

distant imp
#

Let's say I want to have 1000 quads in different colors, my code would look like this:

for (var i = 0; i < 1000; i++)
{
  var entity = EntityManager.CreateEntity(quadArchetype);
  var mesh = CreateRandomSizeMesh();
  var material = CreateRandomColorMaterial();
  EntityManager.AddSharedComponentData(new RenderMesh { mesh = mesh, material = material });
}

As far as I know SharedComponent makes the entity unique if the value is different making it take a chunk for itself. With the code above, I end up with 1000 chunks with only 1 entity in it (assuming all quads will have different size and color). Is there any way to optimise such case?

hollow sorrel
#

@distant imp you def don't want to create 1000 different materials for that case

#

if you're using hybrid renderer look into material overrides

#

it should have an example scene but not sure

#

for the meshes you could reuse the same quad mesh and scale them differently if you want random sizes so you only need 1 rendermesh sharedcomponent

distant imp
#

@hollow sorrel I've been trying to find info about material overrides, but they only seem to be available using custom shader graph. However we write our own custom shaders and create our materials in the code, and I can't find any info on how to do it in code.
Good tip on using scale on quad sizes though, thanks!

hollow sorrel
#

yea you can use them in code too

#

having a hard time finding docs on it atm but from what i remember you just add the component you want to override to your entity and it should just work

#

i think BaseColor is the one for color

#

gotta set its value too

#

for custom materials/shaders there is also a way to create new override components in code

distant imp
#

Thanks! I read through the thread, and it seems I have to create a shader graph and a material in the Editor. I will try and reverse engineer the generated shader and see what I can figure out from there. Thanks again!

dull copper
#
Unity Technologies Blog

The Unity Burst Compiler transforms your C# code into highly optimized machine code. One question that we get often from our amazing forum users like @dreamingimlatios surrounds in parameters to functions within Burst code. Should developers use them and where? Weโ€™ve put together this post to try and explain them a bit more in detail. [โ€ฆ]

#

meanwhile, wondering how the DOTS blog post is coming along ๐Ÿค”

safe lintel
#

Maybe this is it ๐Ÿ˜€

pliant pike
#

stupid basic question but how do I get a specific entity from an entitymanager in a monobehaviour?

#

neh mind I think I got it CreateEntityQuery then ToEntityArray

odd cipher
#

Hello, I'm wondering how I could avoid the Structural Changes error on the main thread, I want to add something to a DynamicBuffer Element on the mainthread but that same Element gets altered in a System which runs every frame parallel. Which causes the mentioned error.

deft stump
#

look up EntityCommandBuffer

#

also

#

I see a struct called nativestring

#

is this a way to pass a string into a native container?

low tangle
#

yes, but use FixedString<number>

#

nativestring was the previous name, fixed string is the newer ones that can be appended and what not

deft stump
#

nice nice

compact robin
#

Hey guys, what's the FixedUpdate() equivalent of DOTS?

pulsar jay
#

Can anybody explain CollisionFilters to me? The docs only have an example colliding with all layers which isnt helpful. I dont really get why I need a BelongsTo for a raycast and setting both (BelongsTo and CollidesWith) does not change anything. It still returns every collider regardless of its layer:

{
    BelongsTo = 1u << 1,
    CollidesWith = 1u << 1,
    GroupIndex = 0
};```
#

As the first layer is called 0: (Undefined Physics Category) is it 0u or 1u << 1 in code?

pulsar jay
#

Ok found it: Layer 0 is actually 1u

#

And one has to be really specific on each object about what can collide with what

compact robin
#

I wonder what's the diff between EnableFixedRateSimple(ComponentSystemGroup, Single) and EnableFixedRateWithCatchUp(ComponentSystemGroup, Single)

compact robin
#

Oh I see

#

I'm still confused as to why OnUpdate() is not called for Worlds I manually create @_@

lean raptor
#

What is the Unity Job equivalent of Physics.OverlapSphere?

karmic basin
#

With or without ECS ?

lean raptor
#

I don't use DOTS if you mean that, but the every day GameObjects

karmic basin
#

With ECS there's an example on the manual, I can show you the link.
Without, I'm not sure it's supported, you would have to do so in main thread but you probs want multithreading so you might need to make your own distance check

lean raptor
#

With ECS there's an example on the manual, I can show you the link.
Can you post the link please?

#

Maybe I found something useful that I can use outside ECS

rancid geode
gusty comet
#

Hello, I wonder how could I pass particle system to a entity?

lean raptor
#

Ok, I'll see

karmic basin
stray yoke
#

i'm new in DOTS and i want to know where i can find resources to learn

compact robin
#

I wonder as well :c

karmic basin
#

CodeMonkey has a lot of Youtube videos on the topic

#

But first I recommend reading the official manual

#

Well not a lot of videos, but good ones on programming with ECS

compact robin
#

I'm trying to make multiple worlds in which I can simulate physics in, but I can't seem to find resources on that @_@

karmic basin
#

Alright try the Unity Official github

#

they have many physics with ECS axamples

#

maybe they did multiple worlds simulations, otherwise the Physics package manual should give you a starting point I hope

compact robin
#

I don't think they did unfortunately :c

karmic basin
#

@compact robin Check out the pool example

#

they seem to predict balls motion

distant imp
#

I want to remove a component from an entity that is referenced by a component I'm iterating on, how do I go about it?
This doesn't seem to work:

var commandBuffer = _endSimEcbSystem.CreateCommandBuffer().AsParallelWriter();

Entities.ForEach((Entity                   entity,
                  int                      entityInQueryIndex,
                  in MyComponentWithEntity component) =>
                 {
                     commandBuffer.RemoveComponent<ComponentIWantRemoved>(entityInQueryIndex, component.Entity);
                 })
        .ScheduleParallel();
#

Never mind, it seems to work now ๐Ÿค”

pliant pike
#

don't suppose anyone knows the syntax for the nativearray contains method?

#

the docs don't seem to make any sense or make it clear it seems it's like this currentnativearray.Contains<Entity, 0>(0);

#

but that doesn't work

distant imp
#

It should just be currentnativearray.Contains(0); assuming your native array is NativeArray<int>

#

It's the same as saying currentnativearray<int, int>.Contains(0)

odd cipher
#

@karmic basin I'm having some trouble converting the Quadrant system from his video to the new way ECS works, There was a comment on the video with a Github link to a working version for how it works now but still not sure how to get that working either.

pliant pike
#

thanks, Jonah I guess the problem is the native array is of type nativearray<Entity>

karmic basin
odd cipher
#

Mhm, it's making it quite a bit difficult for me to remake it.

pliant pike
#

not sure what I would use for that, I just need to figure out if the native array contains any entitys at all

karmic basin
odd cipher
#

A quadtree to make it more efficient to find the nearest entity. But I'm not sure if it's a great solution.

karmic basin
karmic basin
odd cipher
#

True but it seems a bit difficult to implement for ECS

karmic basin
#

Easiest way is to have a double for loop and check distance between each object against each other object in the scene, keeping only the lowest one, but please dont do that if you have many objects ๐Ÿ™‚

odd cipher
#

Yes that's the problem. It's what I am doing currently but it is way too slow for what I need.

karmic basin
#

ANother solution is, if you have a maximum range, to use a sphere around origin object position, and check if something inside. Using Physics so might not be more simple in the end :p

odd cipher
#

Yeah I am using Physics and I would like to have a maximum range so that might be the best solution? not sure.

karmic basin
#

Alright, I got a link for you to study, gimme a sec

#

CHeck the "Collider casts" example

#

sorry link was wrong

#

^^

odd cipher
#

Alright

karmic basin
#

they cast a sphere and check if any entity collide with it

odd cipher
#

Do you know how performant this is?

compact robin
distant imp
pliant pike
#

awesome, thanks @distant imp

karmic basin
#

Oh right the length is preallocated, my bad

pliant pike
#

yeah, I should have said I did try length

karmic basin
odd cipher
#

Alright

compact robin
#
        var World = new World("Test 5");

        var CSG = World.GetOrCreateSystem<Test5SystemGroup>();

Can someone tell me why the system is not showing up in the Systems Debugger?

deft stump
#

when did they say that enable/disable components is going to be released?

opaque ledge
#

i think they mentioned that 2 months ago

deft stump
#

yeah iirc, it's going to be relased on december right?

opaque ledge
#

i dont think they gave any release date

deft stump
#

ah found it

#

q4 2020

#

so next year

#

wew

#

I can work on other parts of my game

opaque ledge
#

arent we in q4 2020 rn ? ๐Ÿ˜„

compact robin
#

Lol I thought I was the only one who found it weird

#

๐Ÿง

karmic basin
compact robin
#

Yes

#

Both .Update() and without Update() doesn't work

#

Apparently it only works if I add it to playerloop

#

But that's not what I want

#

Besides, that approach only works for 1 world @_@

karmic basin
#

ANd if you choose an arbitrary systemgroup and AddSystemToUpdateList() in that group ?

compact robin
#

Yes

#
        var World = new World("Test 4");

        var Systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
        
        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(World, Systems);
        
        World.EntityManager.MoveEntitiesFrom(World.DefaultGameObjectInjectionWorld.EntityManager);
        
        var SysGrp = World.GetOrCreateSystem<SimulationSystemGroup>();

        World.DestroySystem(World.GetExistingSystem<PresentationSystemGroup>());
        
        World.DestroySystem(World.GetExistingSystem<InitializationSystemGroup>());
        
        var Sys = World.GetOrCreateSystem<Test4System>();
        
        SysGrp.AddSystemToUpdateList(Sys);

Btw do you think this is a good idea if I just need to like simulate physics

deft stump
compact robin
#

Ignore the MoveEntitiesFrom() btw, that's just to test if physics work

karmic basin
#

Nah I dont think so. Might be better to use Physics.Simulation like in the pool example

compact robin
#

I can't

#

Because I need to rewind time

#

And simulate

karmic basin
#

I know you can control the step of simulation at least in the future. You're saying it doesn't work in the past ?

#

backwards

compact robin
#

No like I wanna do some sort of client prediction

#

And it needs to rewind time and check if the prediction is accurate

#

Also some lag compensation server-side

karmic basin
#

oh more like network orediction then ?

#

oh ok

compact robin
#

Something like that

#

And I don't think Physics.Simulate() or whatever it was called would work out

#

I want a custom physics world where I can update at a fixed rate

#

Or on demand

karmic basin
#

Did you check the official DOTS multiplayer FPS example ? they stopped support but implemented all that

compact robin
#

They use some ghost authoring comp which I don't quite understand tbh

#

I bet they use a separate world as well

karmic basin
#

I didnt dig that project that far so couldnt tell, looks like you studied it more than me

compact robin
#

Tbh no

#

I'm not certain

#

I'm really new to all this ECS stuff

#

Struggling cuz there's lack of documentation

#

Like what could be easily implemented in monobehaviour objects would take hours of research and / or asking here

karmic basin
#

Yeah it's still early and lot of boilerplate

compact robin
#

I mean it has been 2 years, no?

karmic basin
#

Probs... Time flies by so fast

compact robin
#

Oh yeah

#

My above code works so far, but I'm concerned as to whether

        World.DestroySystem(World.GetExistingSystem<PresentationSystemGroup>());
        
        World.DestroySystem(World.GetExistingSystem<InitializationSystemGroup>());

Would have any form of negative repercussions

#

Like I don't need any of the drawing

#

But idk what InitializationSystemGroup is for

karmic basin
#

Ok so the main idea it that your server is authoritative and compute the physics simulation in another world. And for lag compensation you can invalidate the simulation and make another one, right ?

#

Honestly I think it's overkill yeah

#

But I never implemented what you're trying, so...

compact robin
#

For lag compensation you have to rewind time

#

Because the client input is always behind due to latency

karmic basin
#

Yeah but you can do it in a standard way

compact robin
#

How? I don't get it

karmic basin
#

Weither you simulate another world or not

#

is not relevant I guess ? Unless you encountered a blocker

compact robin
#

Because I don't want to affect my present world

#

the present world still runs

#

I just want to rewind time when like say, a player shoots another player

#

And I think a separate world is the best way to do it

#

Or rather easiest

#

xd

karmic basin
#

I think I dont understand why you want to rewind time.
I would assume server is authoritative so whatever data it sends to the client, the client override its own, eventually interpolating so it doesnt teleport. And then prey for low ping :P
What am I missing in your project ?

compact robin
#

Because the client's requests are always behind time

#

Due to latency

#

Like say if the client has 100 ms round trip to server

#

The req would be 50 ms behind present server time

#

That might make shots inaccurate, so we need to rewind to 50 ms from before

#

And see if like say, a raycast actually hits

karmic basin
#

Ok that looks like a standard network concern. I don't think the whole simulating in another world is relevant

compact robin
#

But I also want to keep current simulation on-going while that happens

compact robin
#

I also don't have to affect my current world

karmic basin
#

But current simulation is invalidated if you receive new input ?

#

Ok I fear I'm not sure I understand what you need, sorry

compact robin
#

Requests will always be behind server time

karmic basin
#

You want movement prediction on the cliet then ?

compact robin
#

So I need to rewind :c

north bay
#

A world just to do backwards reconciliation sound really overkill to me

compact robin
#

What is the suggested approach then?

#

Overkill as in it would incur more overhead?

north bay
#

What physics backend are you working with?

#

Or what's your 'rewind' use case?

compact robin
#

I'm trying to use Unity ECS as a server

#

And also a client

#

LOL

north bay
#

Do you only need to rewind them to process the request? And what do those requests look like?

compact robin
#

Basically like some raycast direction

#

And frame number

#

Like when someone shoots

north bay
#

So how are you doing the raycasts?

#

Through dots physics or unity phtsics?

compact robin
#

Dots

north bay
#

Or a custom implementation?

compact robin
#

I plan to do it via dots

#

I want to like rewind time server-side, raycast and do stuff if it hits

karmic basin
#

You mean your simulation has to be deterministic based on frame number ?

north bay
#

Well then you are pretty good to go already.
The Netcode package has an assembly that is called Unity.Netcode.Physics which makes use of a class called PhysicsWorldHistory which stores the PhysicsWorld for the last x ticks.

compact robin
#

But what if I don't want to use the netcode package?

north bay
#

Than you grab that assembly from the package cache, copy it into your assets and uninstall the package

#

Modify the code of it so it takes your time logic

#

Should be fairly straight forward

compact robin
#

Hmmm

#

So its like a bad idea to make a new world just for physics?

karmic basin
#

Not always, but not suited to your network case

compact robin
#

Why?

north bay
#

Cause you would clone lots of none essential data

#

How would you set that up? You would have to sync between that physics world, your simulation world and your presentation?

compact robin
#

I mean its sole purpose is just to see if a shot hits

north bay
#

If that's all you want to do I highly recommend to check the PhysicsWorld of the Dots Physics package out, or the PhysicsWorldHistory of the netcode package

compact robin
#

Hmm

#

Is it possible to copy PhysicsWorld then?

north bay
#

Yes, that's what the PhysicsWorldHistory does based upon ticks

compact robin
#

Wow interesting

north bay
#

The PhysicsWorld struct has a method called clone if i remember correctly

compact robin
#

:o

#

Yeah now my "solution" sounds overkill LOL

#

Not to sound dumb, but is it possible to step like a physicsworld forward by x amount of steps

#

If what I'm asking even makes sense xd

karmic basin
#

yes it is

compact robin
#

Oh how?

#

Because I need that for reconciliation

karmic basin
#

you can .stepImmediate() or smthg like that, check API reference

compact robin
#

simulation.stepImmediate?

#

I saw that in the pool example

karmic basin
#

yeah

compact robin
#

The problem is Unity docs don't really explain how to use them

#

:c

#

Though I do have a rough idea

#

I just hope it works xd

north bay
#

That's the nature of DOTS docs ๐Ÿ˜‰

compact robin
#

Yeah the lack of documentation is why its hard to use

#

Sadly

#

I have a theory they are just doing this on purpose so braindead people like me don't spam their forums with stupid shit xd

#

Like they want people who actually know their stuff to use it

#

๐Ÿง

#
World.DestroySystem(World.GetExistingSystem<PresentationSystemGroup>());
        
World.DestroySystem(World.GetExistingSystem<InitializationSystemGroup>());

Back to my original question though, are there any repercussions as to doing this

#

Because even if I don't have an additional world to simulate physics, I still want a world whereby I can tick my own time

odd cipher
#

@karmic basin I'm having some trouble understand how to get CollisionFilters to work. They seem to be the problem.

CollisionWorld collisionWorld = World.DefaultGameObjectInjectionWorld.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld.CollisionWorld;
collisionWorld.CalculateDistance(new PointDistanceInput() {
    Filter = new CollisionFilter() { 
        BelongsTo = 1 << 1, CollidesWith = ~0u, GroupIndex = 0 
    }, 
    MaxDistance = 50, Position = position 
}, out DistanceHit hit);
if (hit.Entity != Entity.Null) UnityEngine.Debug.Log(hit.Distance);

This is how it's set on the entities I want to find.

#

The debugged distance is always -0.5 for some reason.

karmic basin
#

Try bitmask 1 << 0 ? If I'm not mistaken

odd cipher
#

Nope didn't work either

karmic basin
#

Alright and when you set to everything in Inspector and in filter it works as expected ?

odd cipher
#

I'm unfamiliar with bitmasking but I'm guessing ~0u means everything. If so, no it doesn't work either. It might be that -0.5 is the distance to the ground entity.

karmic basin
#

yeah it's all 1's on a Byte so everything

#

Shot in the dark, do you have objects inside each other ?

odd cipher
#

No

karmic basin
#

Just to pinpoint the problem, try Filter = CollisionFilter.Default ?

odd cipher
#

Nope same thing

karmic basin
#

Yeah maybe the CollideWith everything grabs the ground then...

#

try 1 << 1 for the COllidesWith bitmask ?

#

sorry too lazy to launch Unity

odd cipher
#

Now it looks like this Filter = new CollisionFilter() { BelongsTo = 1 << 0, CollidesWith = 1 << 1, GroupIndex = 0 }
though no difference

karmic basin
#

Filter = new CollisionFilter() { BelongsTo = ~0u, CollidesWith = 1 << 1, GroupIndex = 0 }

odd cipher
#

Didnt work either.

karmic basin
#

I'm confused right now. I'd have to try myself to find source of the problem.

#

Wait if it's unsigned it supposed to be 1u << 1, could you try that ?

#

but I thinnk that wont help

odd cipher
#

nope, no difference

karmic basin
#

I you debug log hit.Entity it says it's the ground ?

odd cipher
#

I'm not sure how to differentiate it, it says its (3:1)

karmic basin
#

iit's the index in your entity debugger window

odd cipher
#

I'm guessing it's referring to a entity with index 3 then?

karmic basin
#

yeah it should be the third in your entity debugger

odd cipher
#

if its the one with index 3 then it's referring to itself.

karmic basin
#

ok so distance starts from center position of entity and collides with itself... we should ignore layer 1

#

Just to make sure, you have an entity looking for food, so you distance check on your Layer 1 ?

odd cipher
#

Yes

karmic basin
#

OK maybe I'll try myself later (Unity not installed on my new SSD right now)

stoic monolith
#

How do u deal with nativearray has not been disposed when exiting play mode?
I tried to dispose them in OnDestroy (and calling Complete first if needed) but still throws those error

amber flicker
#

I think you may potentially have issues if they're static but if not, you should be able to just dispose them - any better if you use OnStopRunning() (I think that's what it's called)?

#

tbh I'd expect OnDestroy to work fine - do you have a small repro?

stoic monolith
#

No..

#

Wait i found the bug

amber flicker
#

virtual? Isn't this in a system? Is that ever being called?

stoic monolith
#

Virtual for all unity callbacks are ok

#

Im only using jobs btw, not ecs..

amber flicker
#

if it was in a system I'd expect to see protected override void OnDestroy() - if that's not in a system then yea that's different

stoic monolith
#

Weird i cant recreate it now @_@

I thought it only happens when i Pause, and then stop Play (instead of just stop Play)
But yea, not happening anymore

odd cipher
#

How would I set specific indexes in a DynamicBuffer in a Parallel ForEach? ```csharp
Entities.ForEach((ref Translation translation, ref DynamicBuffer<InputNeuronData> inputNeuronData, in HealthData healthData, in DNAData dnaData) =>
inputNeuronData[0].SetNeuronValue(ref inputNeuronData, 0, healthData.energy);
inputNeuronData[1].SetNeuronValue(ref inputNeuronData, 1, closestFoodDistance);
}).ScheduleParallel();

I'm trying this but it doesn't work due to racing conditions. (Cleared up some of the code for the snippet, some missing variables)
#

.SetNeuronValue() is just a quick short cut to make the code shorter

public void SetNeuronValue(ref DynamicBuffer<InputNeuronData> neuronData, int index, float value) {
    neuron.value = value;
    neuronData[index] = this;
}
karmic basin
#

@odd cipher For the -0.5 value earlier i did some tests: the way I understand it, it gives you the distance you would have to move the collided entity so it stays at the surface of the other entity collider, instead of getting inside it.
It's negative so you go outwards the shape, and it's 0.5 because yo might test with a capsule of scale 1 for example ?
So from the center you have to move minus 0.5 to get the point on the surface.

odd cipher
#

@karmic basin I'm not sure I understand, though the entities that are trying to find targets are capsules of size 1 and the targets themselves are small cubes

karmic basin
#

Im gonna show you a screenshot

odd cipher
#

Alright

karmic basin
#

your food is the yellow sphere (scale of 1) so you would have to move -0.5 unit from center to be at the purple point

#

if your player would like to collide with it

#

In the end it's not what you're looking for

odd cipher
#

Ah yeah

karmic basin
#

I still think a distance check and eventually an octree for performance is the way to go

#

or an overlapSphere

odd cipher
#

The problem is I don't know how to do either of those things. I have a usual distance check against all food entities but it's verryyy expensive and doesn't really allow for a max distance.

karmic basin
#

how many food can there be at a time ?

#

like thousands ?

odd cipher
#

Yeah, in the thousands.

karmic basin
#

ok I see

#

did you have time to try to jobify it and use burst ?

#

or you just dont want to try that route ?

odd cipher
#

I haven't been able to get it to work with Burst no, but I'm sure it's possible. Not exactly sure how though, I can share the code if you want it.

karmic basin
#

Nah I wont go this far ๐Ÿ™‚ just giving you ideas

odd cipher
#

Hm well, I'll try and get the already existing method I have to work with Burst and see from there.

odd cipher
#

Yeah no, I'm completely stuck.

karmic basin
#

You can keep this (or do the spherecollider way) for now, knowing you will be able to optimize later when you're more confident with ECS

#

the most important at the beginning is that it works

#

Also you can look at the official Unity Boids demo to get more inspiration

#

this one has A LOT of boilerplate though and probably outdated now

#

I'll do an octree for my own project, but not before next year sorry

odd cipher
#

Hm yeah, I looked at the boids example and it's quite out of my expertise. I'll take a break from trying to optimize it for now and focus on other things. I'll come back to it later I suppose.

karmic basin
#

yeah as long as it work you can keep you project momentuum ๐Ÿ™‚

frigid onyx
#

Is there any means to run a system only when a query does not return any matches?

#

.WithNone<>() will return every entity that doesn't have a given component, that's not going to work.

#

I'm looking for a RequireForUpdate() where the EntityQuery result length == 0. Like oh, hey, geeze, an entity with such-and-such component doesn't exist, I'm going to go build one

karmic basin
#

Do the query with those components as usual, then count them and early-exit if you find any ?

#

Or encapsulate in an if statement

frigid onyx
#

Yeah, it's just annoying to have to have the system running at all, checking every frame when this is a really rare occurrence in the game's logic

karmic basin
#

That wont overload your game

#

If it really is that rare, you could check count only when destroying these entites for example, because otherwise tehre's no way the count change

frigid onyx
#

I'm going to try it the first way you suggested, in the OnUpdate do a CalculateEntityCount() and then only run if I don't find any that match. I'm probably just overthinking it.

#

thanks

hollow sorrel
#

if you just want to check any matches you can just query.IsEmpty, it's more efficient than calculatecount

karmic basin
#

Yeah dont try to optimize until you see it in the Profiler

hollow sorrel
#

and also it's pretty much the same what systems currently do to detect if they should run or not

#

even if you think a system doesn't "run" because it doesn't meet its query requirements, it's actually still doing an onupdate just with a check for if the query is empty or not, before checking if it should do the user onupdate

karmic basin
hollow sorrel
#

yeah

karmic basin
#

nice

hollow sorrel
#

oh seems they're actually using query.IsEmptyIgnoreFilter which should be even faster because it ignores filters, but not sure what filters means in this case

karmic basin
#

you can specify query filters but didnt use them yet

#

looks like advanced usage

frigid onyx
#

Awesome, thanks

#

Interesting. Apparently when you destroy an entity, it doesn't automatically destroy its children? Or am I doing something wrong?

zenith wyvern
#

Only if they're in a linkedentitygroup

safe lintel
#

Need linkedentitygroup to include children and any other entities you want to link in destruction or instantiation

zenith wyvern
#

Also it's a bit weird, the first entity in the buffer needs to be the "parent"

compact robin
#

Yo, is there anyway to copy a collider of an entity to another?

zenith wyvern
#

Assuming the collider is just a component, just assign the collider to a variable and pass it to SetComponent

compact robin
#

So would it copy the shape over

#

Like say if its a box collider

#

And the other entity's a sphere collider

zenith wyvern
#

Oh I'm not sure, I haven't messed with the physics system too much. Based on my limited knowledge of it yes i believe it would

compact robin
#

Oh ok thanks dude

zenith wyvern
#

If I understand it right it would overwrite the shape, since the "shape" is just stored as a header on the component

compact robin
#

Wow epic

#

Wait does that mean we can no longer have two types of colliders on a single obj

#

Not talking about nested ones in children

zenith wyvern
#

I don't know much about it but no I don't think you could. Unity's ECS has a hard limit of one component type per entity, and all physics shapes share the same component

#

But the physics system definitely does do compound colliders, so you'd have to do some digging to see how they do it

#

Like if you create a gameobject physics shape with multiple colliders, convert it and see what the component/entity structure looks like

compact robin
#

I see

#

Thanks again :>

karmic basin
#

Yeah I dont know how they would convert it, because they incite you to build compound GOs for colliders

glacial berry
karmic basin
compact robin
#

Yo Mr K, does PhysicsWorld store the transform of all entities?

#

Or anyone

glacial berry
karmic basin
compact robin
#

Isn't translation the transform values

#

๐Ÿง

karmic basin
#

Translation is position

#

Transform is pos + rot + scale

#

scale is not yet exposed as far as I know, but you can mess with the transform matrix

#

Still trying to duplicate entire worlds ? ๐Ÿ™‚

karmic basin
#

looks like there's a scale component now :p

compact robin
#

So in this case

#

Does PhysicsWorld store ALL Translations?

#

Cuz I find that a waste

#

Say if I have thousands of ents

#

But only like 20 are players

#

And as such, require rollback

#

Wouldn't it be a waste to store the entire physicsworld

#

Per tick

karmic basin
#

Well if you want your players to collide with other ents (ants?) they should live in the same world ?

compact robin
#

Yes I want them to collide

#

But remember the rollback system

#

We spoke about yesterday

#

I don't have to rollback certain stuff

#

Especially static objs

#

They still need to collide

#

But I don't need to store their positional data

karmic basin
#

You still clone the whole relevant physics world, then update ECS data on the cloned world I guess

#

Dunno never tried

#

I guess it's not that simple

compact robin
#

No the thing is

#

Cloning physicsworld works

#

But I think it includes lots of unnecessary data

#

I only need positional datas of certain entities

#

They account for less than 5% of the total entity count

#

Which I think is why I wanted to make a simulation world

karmic basin
#

Yeah. I don't remember what we talked about yesterday (my memory is as crap as this) but I wouldnt clone. I would just have an authoritative server and client update positions without asking questions

compact robin
#

You mind if I recap?

karmic basin
#

Sure go ahead

compact robin
#

Ok

#

So basically

#

When there's network connection involved

#

There will always be latency

#

As such, sent reqs are always behind server time

#

So the server needs to store data every tick

#

So that it can rollback

#

Say 1 tick is around 25 ms

#

And the round trip is 100 ms

#

So it would take around 50 ms for req to reach server

#

That means the data is 2 ticks behind server time

#

So the server would rollback to data 2 ticks from before

#

So the suggestion yesterday was to clone physicsworld every tick

#

Which works

#

But if physicsworld contains translation and velocity data of ALL entities

#

I find that its a waste

#

Say I have 10 k entities

#

And only 20 of them are players

#

I don't have to store data of non-players

#

Since they are mostly static

#

I only need to store data for stuff I shoot

karmic basin
#

Ok so it really is a network concern

compact robin
#

I just wanna know if physicsworld

#

Would store data of all entities

karmic basin
#

I dont see how you problem is different from other games

compact robin
#

It isn't

#

The thing is

#

If physicsworld stores everything

#

I might as well make a new world

#

And then send required data for simulation to it

#

And simulate there

#

Instead of storing physicsworld every tick

#

So basically players have a dynamic buffer of prev datas

karmic basin
#

I'm really not fan of cloning the world each time you receive a network message

compact robin
#

No

#

Its only once

#

I reuse the world

#

The world pools entities

#

And whenever I need to simulate

#

I send a set of data for the particular tick

#

To the world

#

It takes an entity in pool

#

Sets its component datas

#

And a raycast is performed

#

To see if stuff hits

#

That saves memory cuz I just have to store prev tick data for the 20 players

karmic basin
#

DId you try setting the component data but on a non-cloned world ?

compact robin
#

In the main world

karmic basin
#

It does, and becomes your new reality

#

there's only one true world

compact robin
#

That's not what I want

karmic basin
#

That's what I dont understand in your game

compact robin
#

Current world should keep ticking

#

And never go back

#

Whereas a separate world

#

Is responsible for going back in time

#

And verifying if a raycast would hit

#

At a given tick

karmic basin
#

oh yeah because different latencies

compact robin
#

Yes

karmic basin
#

I'm tired -_-

compact robin
#

It goes back by Round trip / 2 ms

#

Storing physicsworld is a cool concept

#

But it stores a lot of irrelevant data

#

Say minecraft

#

I would ideally have each block as an entity

#

But I don't need them to store prev pos

#

Cuz they are mostly static

#

And I dont shoot them

#

I'm not saying cloning and storing physicworlds don't work

#

I'm trying to find a better way

karmic basin
#

I would need to check again the DOTS online shooter demo to remember how they manage that

compact robin
#

They have something called PhysicsWorldHistory

karmic basin
#

I think they dont care and override the world for everyone

#

with interpolating and such

compact robin
#

Which is basically cloning and storing physicsworld every tick

#

Which is inefficient for my case

#

Since it stores a lot of redundant data ( Or at least I think so )

karmic basin
#

I never saw that, try it

compact robin
#

It works

#

But I want a more efficient way

karmic basin
#

I know of PhysicsWorld.Bodies and DynamicBodies (rigidbodies)

compact robin
#

Yeah but if I do PhysicsWorld.Clone()

#

it just clones the entire struct

karmic basin
#

CHeck inside PhysicsWorld.DynamicBodies ?

compact robin
#

No what Im saying is

#

Say if you have 10 k entities

#

PhysicsWorld would contain data for all 10k ents

#

I think

#

So whenever I clone

#

it would clone all the 10k data

#

When I only need like 20 of them

#

So my current plan is -

  1. Players have dynamic buffers of a certain size ( Based on max amount of ticks you should rollback )

  2. A raycast req is received, which contains a tick number

  3. A job finds all entities with the buffer, and then grabs the relevant tick data, then stores them in a native array

  4. Data is sent to simulation world, which sets data to the ents

  5. Simulation world does a raycast

#

I think that's better since I only need to like store 20 sets of data every tick

#

As opposed to the entire physicsworld

#

Also storing just the physicsworld is flawed in the sense that

#

Should I require other data

#

Say data of a comp previously

#

Storing a physicsworld wouldn't help

#

What I plan to do is to store my own struct of tick data

karmic basin
#

PhysicsWorld.NumBodies (total)
PhysicsWorld.NumStaticBodies (PhysicsShape, no PhysicsBody component)
PhysicsWorld.NumDynamicBodies (PhysicsShape + PhysicsBody)
PhysicsWorld.Bodies -> NativeArray of rigibodies
PhysicsWorld.DynamicBodies

#

do these help ?

compact robin
#

No because when you do PhysicsWorld.Clone(), all of those get cloned

#

I just need players' data

karmic basin
#

then only clone dynamic ones ? but it means your own implementation

compact robin
#

And how would I do physicsworld.raycast then

#

Besides physicsworld doesn't include custom component data I believe

karmic basin
#

I mean working with data and not cloning

compact robin
#

So I can't check for previous state

compact robin
#

I need the physicsworld

#

If I clone to another world, then I could use the physicsworld of that world

#

To raycast

#

And I only copy 20 set of data

#

Instead of 10k

#

I can also copy custom component data

#

Say if a player is invulnerable in tick 20, but not in tick 21

amber flicker
#

Fwiw I think you'll have more luck on the dots netcode forums (unless you've already tried). Unless someone here has actually tried doing netcode and physics I think you'll be limited to fairly general advice. I'm surprised it the teams aren't thinking quite a lot about these kind of issues but perhaps I'm wrong. Apologies for not taking the time to fully understand your problem. Having not done any serious networking myself I lack the experience but I wonder if you're approach is a little untypical? I.e. I think you would normally send the users inputs to the server and the server would simulate (with rollback and prediction) then tell client whether e.g. a raycast hit.

compact robin
#

server would simulate (with rollback and prediction) is what I'm trying to achieve

#

So my plan is

#
So my current plan is - 

1) Players have dynamic buffers of a certain size ( Based on max amount of ticks you should rollback )

2) A raycast req is received, which contains a tick number

3) A job finds all entities with the buffer, and then grabs the relevant tick data, then stores them in a native array

4) Data is sent to simulation world, which sets data to the ents

5) Simulation world does a raycast
amber flicker
#

ah so you're not using netcode and want to roll your own?

compact robin
#

Yes

#

According to a guy named Script

#

Their impl is

#

PhysicsWorldHistory

#

Which is basically cloning PhysicsWorld every tick

#

But I find it a waste

#

Cuz say if I have 10 k ents

#

And I only need to rollback 20 of em

#

Why would I want to clone data of all 10 k?

#

Besides the physicsworld approach constraints me to only physics related data

amber flicker
#

if they're physics bodies, how do you know they don't interact?

compact robin
#

Say minecraft

#

We have blocks

#

But we dont need to shoot them

#

Hence I dont have to rollback data

#

And as such, I don't have to store data about them

#

Every tick

#

Things like maps won't move

#

And are static

amber flicker
#

then why would they be in the physics world?

compact robin
#

Doesn't the physicsworld include everything

#

That has a rigidbody

amber flicker
#

afaik... it contains a representation of all the colliders but doesn't contain e.g. meshes and all the entity stuff

#

but surely everything in a physics world can in theory interact with everything else in the world

compact robin
#

Yeah like their translation

#

But I don't need to store previous translations

#

Of static stuff

#

Only for stuff I need to rollback you see

#

In present time, I need data of all ents

#

But only specific ents need to be rollbacked

#

For instance, players

#

Because they can be shot

#

But due to latency, the req would always be behind server time

amber flicker
#

So.. this is a concern about performance right? Trying to minimise memory usage?

compact robin
#

Yes

#

Haha

#

Cloning physicsworld works

#

As mentioned earlier on

#

But have two main drawbacks

#

Or at least I think they do

#
  1. I have to clone all 10k
#
  1. If I need custom comp data, I need a separate collection
amber flicker
#

So out of these 10k, how many do you imagine being static?

compact robin
#

20

#

Oops

#

10 k - 20

#

Which is why its a horrible idea

amber flicker
#

I assume that any clone of physics world would just clone some blob data of the static colliders - which will likely just be a pointer

#

that could be worth asking on forums/checking if that would alleviate your concerns

#

is this a problem you've measured or theoretical?

compact robin
#

Probably transform data, but it has a pointer to colliders

#

That's my theory

amber flicker
#

Seems like a lot of work you're giving yourself if it doesn't prove to be a problem. I would also have expected the teams to have considered this.

#

I would check your assumptions on the forums.

compact robin
#

Not really I find it easier tbh

#

Cuz I can just copy entities to a separate world

#

And set their data

#

And simulate from there on

north bay
#

Do you actually want to simulate the rollbacked entities or only do queries on them?

compact robin
#

Raycast

#

And maybe simulate

#

and I may need to store prev data of some comp data

#

Which is why physicsworld may not work out

#

And I don't want to clone redundant data

north bay
#

They did a similar approach to what you suggested as your 'plan'.

compact robin
#

Like a separate world?

north bay
#

They didn't use a separate world, that was before Dots Physics. They had their own raycast implementation.

compact robin
#

So would my impl be better?

north bay
#

Idk

compact robin
#

I feel its much less work than cloning physicsworld every tick

#

Should I have a ton of entities

#

Which is the whole point of ECS

north bay
#

Cloning the physics world doesn't have a real cost to it

#

That's literally a memcpy

compact robin
#

Isn't it the same for cloning comp / entities

north bay
#

What do you mean?

compact robin
#

Like cloning entities

#

Is it also a memcpy under the hood?

north bay
#

Cloning the world doesn't iterate over the individual entities.

compact robin
#

You're right hm

#

But the copying process

north bay
#

The data inside the collision world is already linear, cloning just copies the content of the CollisionWorld and DynamicWorld into a new location

compact robin
#

Like what about the copying process

#

Since I only have around 20 ents

#

Which can be rollbacked

#

Its not gonna be that slow as well

karmic basin
compact robin
#

Yes

north bay
#

Yea, they might did some changes to it compared to the NetCode version. Haven't checked that out

compact robin
#

The thing is, it is going to copy data of all 10 k ents

#

Which means more memory

amber flicker
#

if most of those are static, I don't think it will create copies

compact robin
#

Idk what unity means by "static" tbh

#

My def of static is basically stuff that don't have to be rollbacked

#

Even though that's not what static means xd

north bay
#

You can also just copy your entities and do the approach that you suggested. It really just depends on your requirements.

compact robin
#

Nice

#

Oh yeah, do you think its faster to like say remove all components of an entity, and then set comps, or just create a brand new one with all the comps needed?

#

Sorry for the ton of qns btw

amber flicker
#

I'm not sure how those things equivalent? Likely creating an entity from scratch is fastest (provided you use an archetype and ideally batch create) than using e.g. 'RemoveComponent'

compact robin
#

Nice

#

Cuz I planned to pool ents in simulation world

#

And reuse them

#

But since such is the case, I should just destroy them all

#

And recreate

vagrant surge
#

@compact robin as a rule of thumb

#

changing an entity (adding/removing comp) costs the same as deleting the entity and creating a new one

compact robin
#

Or maybe pool them for similar archetypes

amber flicker
#

Caching an entity itself is a bit like caching an index of an array to my mind.

vagrant surge
#

and everything inside the ecs is already pooled, so its completely useless to try caching it

compact robin
#

No like say in my simulation world

#

I already have an ent

vagrant surge
#

an entity is literally only an integer

compact robin
#

With a certain archetype

#

Instead of destroying them

#

I could reuse them

#

If I need to simulate an ent of a similar arch

vagrant surge
#

but then you have to add code to check if the entities are alive or not

compact robin
vagrant surge
#

so it becomes trickier

compact robin
#

I could store them in managed arrays

#

Like a queue

#

Where T is the particular arch

vagrant surge
#

ive done simulations where i was deleting and creating entities hundreds of times per second and there was no need for any pooling

#

sorry

#

hundreds of thousands

#

per second

compact robin
#

But if I can avoid deletion why not lol

vagrant surge
#

this is the scale we are talking about

#

because it costs more

#

to try to avoid deletion

#

than to just delete it

compact robin
#

I see

#

In that case

#

Is it better to remove ALL comps and readd

vagrant surge
#

full delete

compact robin
#

Or just destroy and recreate

#

I assume removing comps is O(N)

vagrant surge
#

it is

compact robin
#

Hm

#

Right sounds cool

vagrant surge
#

the problem is that removing comps is done "individually"

#

so you remove one component by component

#

deleting the entity "clears" the entire thing in 1 go

compact robin
#

Yeah precisely

#

But I thought creation / deletion is significantly more ex

vagrant surge
#

im not fully sure if they added batching or something, but it wasnt there last time i looked

#

no

compact robin
#

Looks like I'm wrong

vagrant surge
#

in the unity ecs model creating and deleting is cheaper than adding components to an entity

compact robin
#

Because they have to move them to another chunk

vagrant surge
#

well, kinda bout the same

compact robin
#

Right?

vagrant surge
#

yes

compact robin
vagrant surge
#

yes

compact robin
#

Ok nice

vagrant surge
#

you should allways init directly on the archetype

compact robin
#

Oh

vagrant surge
#

creating an entity and then modifying it is a lot more expensive

compact robin
#

I see I see

vagrant surge
#

as commented, each component change is a bit like destroying the entity and creating it into a different archetype

#

so if you create empty entity and add 2 comps, thats 3x more expensive than just creating it into the correct place from the start

compact robin
#

I just hope I don't run out of version numbers LOL

vagrant surge
#

its an int64 bruh

compact robin
#

That's like into millions

#

Wait

vagrant surge
#

literal heat death of the universe even if you create a billion a frame

compact robin
#

Billions or mills

#

I forgot lOL

vagrant surge
#

more than billions

#

int64s are unfathomably huge

compact robin
#

I see

#

Ok wew

vagrant surge
#

we are talking number-of-atoms-in-universe level huge

compact robin
#

Yeah looks like premature optimization to me

#

Oh yeah could you tell me if

            RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<PresentationSystemGroup>());
            
            RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<InitializationSystemGroup>());

This is a good idea

vagrant surge
#

that i dont really knowp

compact robin
#

If I don't need to visualize stuff

#

I know destroying presentation grp

#

Makes stuff invisible

#

Cuz no rendering

#

But I plan to run it in headless mode anyway

#

Idk what InitializationSystemGroup is for

#

But so far my tests conclude that OnCreate() still works

#

For systems

#

My default world has all the def systems, its just those worlds I manually create in which I'm trying to purge the systems from

karmic basin
#
  • InitializationSystemGroup (updated at the end of the Initialization phase of the player loop)
    BeginInitializationEntityCommandBufferSystem
    CopyInitialTransformFromGameObjectSystem
    SubSceneLiveLinkSystem
    SubSceneStreamingSystem
    EndInitializationEntityCommandBufferSystem
compact robin
#

Yeah Idk what those do

karmic basin
#

I think yo should keep it ?

compact robin
#

I believe its related to gameobject injection

#

But it should be fine since my def world has all 3 def system groups ( And its systems )

karmic basin
#

oh right probably

compact robin
#

The thing is

#
RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<PresentationSystemGroup>());
            
            RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<InitializationSystemGroup>());
karmic basin
#

you'll see when you get an error :p

compact robin
#

When I dont have this

#

For each world

#

It creates a new debug drawing comp

#

To allow me to see stuff

#

But I dont need it

#

I just need the sim

#

Since its a headless server

#

So I think destroying RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<PresentationSystemGroup>()); is safe

#

But idk about init

#

I need the sim group because it has all the systems responsible for physics simulations

#

I add my own custom systems to the group

#

so I can manually call update by doing World.Update()

karmic basin
#

I think you dont need to worry about empty system groups

compact robin
#

The thing is

#

World.Update() doesn't seem to work

karmic basin
#

they cost close to nothing

compact robin
#

If I just create an empty world

#

It needs the def groups

#

๐Ÿคท๐Ÿปโ€โ™€๏ธ

compact robin
#

The presentation grp renders stuff

#

Which is significant overhead I think

#

Say if I create a thousand worlds

#

Its gonna render stuff for all thousand

karmic basin
#

oh yeah because you cloned, right

compact robin
#

And it creates a debug drawer for each world

karmic basin
#

yeah I see

compact robin
#

I don't think you can clone worlds

#

Well at least idk how

#

I was trying to find out how

#
 RoomWorld = new World(Key);

            var Systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);
            
            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(RoomWorld, Systems);
            
            RoomWorld.EntityManager.MoveEntitiesFrom(World.DefaultGameObjectInjectionWorld.EntityManager);
            
            var SysGrp = RoomWorld.GetOrCreateSystem<SimulationSystemGroup>();
            
            //Destroy useless systems
            
            RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<PresentationSystemGroup>());
            
            RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<InitializationSystemGroup>());
            
            var Sys = RoomWorld.GetOrCreateSystem<Test4System>();
            
            SysGrp.AddSystemToUpdateList(Sys);
#

This is what I do

#

Ignore moventitiesfrom

#

I use that to test physics

karmic basin
#

Yeah I never tried that so really I dont know

#

I would just monitor with and without and let numbers talk if you're really concerned about it

compact robin
#

I see

#

I mean its def going to be faster without additional systems

#

The question is, would it break stuff

#

๐Ÿง

pliant pike
#

I don't suppose anyone can tell me how I avoid this error Attempted to access BufferTypeHandle<CellDataBuffer> which has been invalidated by a structural change.

#

when I'm just using this if(celldatasbuffer.IsEmpty) to read the buffer

zenith wyvern
#

Don't do any structural changes between creating the buffer and adding to it

#

Or accessing it in any way really

pliant pike
#

I'm trying to read from a buffer in a monobehaviour so how would I do it without a structural change

zenith wyvern
#

Keep a reference to the entity with the buffer, and only get the buffer through the entity reference and access/change it within the same function

pliant pike
#

I'm guessing that's not really compatible with using it in an OnDrawGizmos() ๐Ÿค”

zenith wyvern
#

I don't see why not

#

Just verify the world is created any time you access it. I feel like DrawGizmos might try to run while ECS is initializing

pliant pike
#

DrawGizmos runs all the time in editor mode also

#

that's what I'm trying to get around

zenith wyvern
#

Yeah so just do if(!World.DefaultGameObjectInjectionWorld.IsCreated) return; at the start of OnDrawGizmos

#

You can't keep a reference to any ECS component or buffer. The only practical way to reference a part of an entity is through the entity

pliant pike
#

yeah its just a matter of making sure they are valid when I get them

#

thanks @zenith wyvern

compact robin
#

Yo guys, is there like a dynamicbuffer that overrides values once its internal buffers are full? As much as it sounds ironic

amber flicker
#

sounds like you want a circular buffer? You'll have to roll your own I believe but should be pretty straight-forward? Easiest I can think is dynamicbuffer with an additional index.

compact robin
#

Like a ringbuffer?

amber flicker
#

sure, same thing

#

isn't that what you're after?

compact robin
#

Oh they are the same thing

#

Yeah in a sense

#

But I need something that is usable in jobs

#

So basically, a dynamicbuffer with int?

amber flicker
#

Off the top of my head, can't think of anything wrong with that ๐Ÿ‘

compact robin
#

Hmm ok

#

Thanks again

#

Using a native array wouldn't work right? Since sizes may vary

amber flicker
#

dynamic buffer if you want it per entity, native array if you want to store it e.g. within a system. Depending how much you care about every micro second, one e.g. giant native array with a second that stored current index per array segment or something might be fastest? Though writing that out I find it hard to work out why you'd ever want that. Flat native arrays always win if you can work with them.

compact robin
#

Like