#archived-dots
1 messages ยท Page 187 of 1
incomplete is how i would phrase it. ymmv depending on your ability to overcome whats missing
i cant answer that
No one can lmao
simple questions of when its ready you should bring to them on the forums
I found NetCode didn't suit my purposes, but DOTSNET was good enough (and quite performant on the server side)
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!
Ok just wanna confirm.
U can NOT interact with unity default physics (physx) from Jobs, right?
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?
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
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
Exactly
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?
Like, this doesnt look very efficient?
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
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
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
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?
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
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
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
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
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.
Are you sure you're running with burst on and safety checks disabled?
But my profiler still looks like this
(Yes i'm dealing with unity physx so that must be the big overhead)
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
I see, shame. Thanks anyway :)
@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
That would break due to different memory representations no?
Would break for the same reason as MemCpy.
I Could perhaps do MemCpyStride. https://docs.unity3d.com/2019.4/Documentation/ScriptReference/Unity.Collections.LowLevel.Unsafe.UnsafeUtility.MemCpyStride.html
Oh yeah that seems potentially promising
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.
https://forum.unity.com/threads/unsafeutility-memcpystride-just-seems-broken.542734/ Looks like I'm not the only one :P
Yeah I'm staring at it trying to make sense of it. No idea
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" ?
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?
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
so if I do want to write, I can't write to other index of that container?
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
oh I understand, so the read and the write happens on two arrays. so no problem
In ECS, is using 'in' instead of 'ref' any faster?
yes.
the burst compiler can expect to just read the data.
In is readonly, ref is to update. Si yeah prefer in if you only need to read a var
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
Alright nice
I have Mathematics installed but can't do using the namespace?
are you using asmdefs? Have you added a reference to the package if so?
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?
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
I still cant find it in manifest..
Hey guys,
(Unity 2019.3.4f1)
So i want to start my new project and i wanted to use Entities in it.
I have already installed it using the...
A very recent problem it seems
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.
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]);
}
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
I suppose that makes sense, I'll make it into a GameObject instead and see if that works.
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
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.
try passing in null instead of blobAssetStore
Entity entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObject, GameObjectConversionSettings.FromWorld( World.DefaultGameObjectInjectionWorld, null));
``` works for me
Nope, same error.
paste the error - also when are you calling this?
You can see all of that info here
according to what you pasted line 18 is saying nullrefexception for prefabsAsEntities[prefab]
Ah yikes, I thought it was referencing the settings but the problem was that I never created the dictionary
well, that's embarrassing
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?
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.
Is anyone else experiencing emission not working after converting to entity?
You could query first a singleton entity, getting its translation
Then do an entity foreach (in translation, in componentX) and then compare if they're close or not.
Do you think you could explain the 'query first a singleton entity' a bit further? I'm not sure I understand
I think he meant "single" entity ?
Try YouTube Channel of Code Monkey, he has a good spatial search tuto with quadtree
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
You're welcome. Happy coding.
How do i debug this?
I have LeakDetection Full Stack Trace and there's no difference
do you have any Native Containers that are set as TempJob?
check if any of those aren't being disposed
Yeah it was an error elsewhere.. ๐
Sorry not so dots related
Why is this wrong?
@stoic monolith because you're comparing 3 elements - you can use e.g. math.all(tr == float3.zero)
Is that the same as this btw?
tr.Equals(float3.zero)
that's also good yup ๐
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?
how do i use MotionVelocity to apply forces to rigidbodies in unity/havok physics?
i was told to use it instead of ApplyAngularImpulse in PhysicsWorld
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?
@maiden delta the component is called PhysicsVelocity i think
Hey, is there anyway to do Physics.Simulate() in DOTS?
@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
What does world.update do?
it updates all the systems in the world, which for us are basically only the physic systems
it ticks them
Like it calls Update()?
yes
Oh how do you disable it?
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
Yes pls lol I'm new to DOTS
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
Oh
Ok so the first one is adding your own system, while the latter is like the default?
the latter adds to my custom world all the default systems
then I can add mine too
Meaning it calls update() on its own?
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
Oh
Do I have to run World.DefaultGameObjectInjectionWorld = physicsWorld;
If I just wanna create a secondary world to simulate physics
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
Isn't DefaultGameObjectInjectionWorld the world GOs are injected into during the start of the game?
check the multiple world part: https://docs.unity3d.com/Packages/com.unity.entities@0.1/manual/system_update_order.html
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
at that point you do physicsWorld.Update()
which is what we do as we want complete control over the ticking
I don't blame you, as the automatic system hides too much logic
Like I wanna step forward by 0.25f
but in reality is quite simple
Every call
Physics.Simulate(Time.fixedDeltaTime);
Which is 0.25 I think
By default
Like an ECS version of this
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
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
yes there are reason why it can get hard of course
this in fact is not about ECS
Yeah
it's confusing because with the auto ticking/creation you don't know exactly what is going on
but studying it is useful
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
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?
@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
@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!
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
not sure if this one is still accurate or outdated but https://forum.unity.com/threads/per-instance-material-params-support-in-entities-0-2.782207/
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!
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 ๐ค
Maybe this is it ๐
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
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.
look up EntityCommandBuffer
also
I see a struct called nativestring
is this a way to pass a string into a native container?
yes, but use FixedString<number>
nativestring was the previous name, fixed string is the newer ones that can be appended and what not
nice nice
Hey guys, what's the FixedUpdate() equivalent of DOTS?
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?
Ok found it: Layer 0 is actually 1u
And one has to be really specific on each object about what can collide with what
Hey so I did some research and found FixedRateUtils
I wonder what's the diff between EnableFixedRateSimple(ComponentSystemGroup, Single) and EnableFixedRateWithCatchUp(ComponentSystemGroup, Single)
Oh I see
I'm still confused as to why OnUpdate() is not called for Worlds I manually create @_@
What is the Unity Job equivalent of Physics.OverlapSphere?
With or without ECS ?
I don't use DOTS if you mean that, but the every day GameObjects
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
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
@lean raptor have you tried SpherecastCommand? https://docs.unity3d.com/2018.3/Documentation/ScriptReference/SpherecastCommand.html
I am not sure if it works on already overlapping colliders, but you can try. If it works, using it with distance = 0 should be the equivalent to a OverlapSphere
Hello, I wonder how could I pass particle system to a entity?
Ok, I'll see
@lean raptor I was thinking of this one for ECS, look the collider example they use a sphere https://docs.unity3d.com/Packages/com.unity.physics@0.0/manual/collision_queries.html
Link posted by Bruno looks interesting too
i'm new in DOTS and i want to know where i can find resources to learn
I wonder as well :c
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
I'm trying to make multiple worlds in which I can simulate physics in, but I can't seem to find resources on that @_@
Alright try the Unity Official github
they have many physics with ECS axamples
And more specifically for physics https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/UnityPhysicsSamples/Documentation/samples.md
maybe they did multiple worlds simulations, otherwise the Physics package manual should give you a starting point I hope
I don't think they did unfortunately :c
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 ๐ค
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
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)
@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.
thanks, Jonah I guess the problem is the native array is of type nativearray<Entity>
Yeah it was some time ago he was one of the first to publish videos on ECS and the specs changed a lot at that time
Mhm, it's making it quite a bit difficult for me to remake it.
not sure what I would use for that, I just need to figure out if the native array contains any entitys at all
The concept is still a robust one to learn. What are you trying to achieve ? I don't remember
A quadtree to make it more efficient to find the nearest entity. But I'm not sure if it's a great solution.
yourNativeArray.Length > 0 ?
Yeah it is when you scale a lot.
True but it seems a bit difficult to implement for ECS
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 ๐
Yes that's the problem. It's what I am doing currently but it is way too slow for what I need.
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
Yeah I am using Physics and I would like to have a maximum range so that might be the best solution? not sure.
Alright, I got a link for you to study, gimme a sec
CHeck the "Collider casts" example
sorry link was wrong
^^
Alright
they cast a sphere and check if any entity collide with it
Do you know how performant this is?
Aight I will have a look thanks :>
It depends on how you're creating/getting the native array. If you're creating it manually like so: myNativeArray = new NativeArray<Entity>(5, Allocator.Persistent); then doing a myNativeArray.Length > 0 will always return true. However you can use LINQ's Any extension method to check if there's any non-null entity in the native array, i.e.: myNativeArray.Any(e => e != Entity.Null)
awesome, thanks @distant imp
Oh right the length is preallocated, my bad
yeah, I should have said I did try length
Depends on your scene. I'd say first try to ake it work, see if that's what you're looking for. If so, then convert it as a job so you can finally use Burst ๐
Alright
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?
when did they say that enable/disable components is going to be released?
i think they mentioned that 2 months ago
yeah iirc, it's going to be relased on december right?
i dont think they gave any release date
arent we in q4 2020 rn ? ๐
Do you .Update() your system at some point ?
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 @_@
ANd if you choose an arbitrary systemgroup and AddSystemToUpdateList() in that group ?
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
Not in unity's calendar. to them it must still be q2 2020
Ignore the MoveEntitiesFrom() btw, that's just to test if physics work
Nah I dont think so. Might be better to use Physics.Simulation like in the pool example
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
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
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
Did you check the official DOTS multiplayer FPS example ? they stopped support but implemented all that
They use some ghost authoring comp which I don't quite understand tbh
I bet they use a separate world as well
I didnt dig that project that far so couldnt tell, looks like you studied it more than me
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
Yeah it's still early and lot of boilerplate
I mean it has been 2 years, no?
Probs... Time flies by so fast
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
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...
For lag compensation you have to rewind time
Because the client input is always behind due to latency
Yeah but you can do it in a standard way
How? I don't get it
Weither you simulate another world or not
is not relevant I guess ? Unless you encountered a blocker
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
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 ?
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
Ok that looks like a standard network concern. I don't think the whole simulating in another world is relevant
But I also want to keep current simulation on-going while that happens
I was trying to do it in another world because it felt like the easiest way to do it
I also don't have to affect my current world
But current simulation is invalidated if you receive new input ?
Ok I fear I'm not sure I understand what you need, sorry
No it will always be behind time
Requests will always be behind server time
You want movement prediction on the cliet then ?
So I need to rewind :c
A world just to do backwards reconciliation sound really overkill to me
Do you only need to rewind them to process the request? And what do those requests look like?
Dots
Or a custom implementation?
I plan to do it via dots
I want to like rewind time server-side, raycast and do stuff if it hits
You mean your simulation has to be deterministic based on frame number ?
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.
But what if I don't want to use the netcode package?
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
Not always, but not suited to your network case
Why?
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?
I mean its sole purpose is just to see if a shot hits
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
Yes, that's what the PhysicsWorldHistory does based upon ticks
Wow interesting
The PhysicsWorld struct has a method called clone if i remember correctly
: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
yes it is
you can .stepImmediate() or smthg like that, check API reference
yeah
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
That's the nature of DOTS docs ๐
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
@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.
Try bitmask 1 << 0 ? If I'm not mistaken
Nope didn't work either
Alright and when you set to everything in Inspector and in filter it works as expected ?
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.
yeah it's all 1's on a Byte so everything
Shot in the dark, do you have objects inside each other ?
No
Just to pinpoint the problem, try Filter = CollisionFilter.Default ?
Nope same thing
Yeah maybe the CollideWith everything grabs the ground then...
try 1 << 1 for the COllidesWith bitmask ?
sorry too lazy to launch Unity
Now it looks like this Filter = new CollisionFilter() { BelongsTo = 1 << 0, CollidesWith = 1 << 1, GroupIndex = 0 }
though no difference
Filter = new CollisionFilter() { BelongsTo = ~0u, CollidesWith = 1 << 1, GroupIndex = 0 }
Didnt work either.
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
nope, no difference
I you debug log hit.Entity it says it's the ground ?
I'm not sure how to differentiate it, it says its (3:1)
iit's the index in your entity debugger window
I'm guessing it's referring to a entity with index 3 then?
yeah it should be the third in your entity debugger
if its the one with index 3 then it's referring to itself.
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 ?
Yes
OK maybe I'll try myself later (Unity not installed on my new SSD right now)
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
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?
virtual? Isn't this in a system? Is that ever being called?
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
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
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;
}
@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.
@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
Im gonna show you a screenshot
Alright
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
Ah yeah
I still think a distance check and eventually an octree for performance is the way to go
or an overlapSphere
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.
Yeah, in the thousands.
ok I see
did you have time to try to jobify it and use burst ?
or you just dont want to try that route ?
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.
Nah I wont go this far ๐ just giving you ideas
Hm well, I'll try and get the already existing method I have to work with Burst and see from there.
Yeah no, I'm completely stuck.
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
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.
yeah as long as it work you can keep you project momentuum ๐
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
Do the query with those components as usual, then count them and early-exit if you find any ?
Or encapsulate in an if statement
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
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
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
if you just want to check any matches you can just query.IsEmpty, it's more efficient than calculatecount
Yeah dont try to optimize until you see it in the Profiler
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
You saw that from the source ?
yeah
nice
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
Awesome, thanks
Interesting. Apparently when you destroy an entity, it doesn't automatically destroy its children? Or am I doing something wrong?
Only if they're in a linkedentitygroup
Need linkedentitygroup to include children and any other entities you want to link in destruction or instantiation
Also it's a bit weird, the first entity in the buffer needs to be the "parent"
Yo, is there anyway to copy a collider of an entity to another?
Assuming the collider is just a component, just assign the collider to a variable and pass it to SetComponent
So would it copy the shape over
Like say if its a box collider
And the other entity's a sphere collider
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
Oh ok thanks dude
If I understand it right it would overwrite the shape, since the "shape" is just stored as a header on the component
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
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
Yeah I dont know how they would convert it, because they incite you to build compound GOs for colliders
Does anyone here know if Shader Graph with Visual Effect target should work on URP? (https://forum.unity.com/threads/simple-shader-graph-does-not-generate-a-visual-effect-shader.1011460/)
Did you ask in #archived-shaders ?
Not yet โย I see now that they also discuss the Shader Graph and not just handcrafted shaders. Thanks for the pointer!
I dont know. But you can access the Translation, Rotation, LocalToWorld, ... Components on the Entity itself
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 ? ๐
looks like there's a scale component now :p
Yeah I meant this
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
Well if you want your players to collide with other ents (ants?) they should live in the same world ?
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
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
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
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
You mind if I recap?
Sure go ahead
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
Ok so it really is a network concern
I dont see how you problem is different from other games
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
I'm really not fan of cloning the world each time you receive a network message
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
DId you try setting the component data but on a non-cloned world ?
That's not what I want since I want simulation to continue
In the main world
That's not what I want
That's what I dont understand in your game
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
oh yeah because different latencies
Yes
I'm tired -_-
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
I would need to check again the DOTS online shooter demo to remember how they manage that
According to the dude named script yesterday
They have something called PhysicsWorldHistory
I think they dont care and override the world for everyone
with interpolating and such
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 )
I never saw that, try it
I know of PhysicsWorld.Bodies and DynamicBodies (rigidbodies)
CHeck inside PhysicsWorld.DynamicBodies ?
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 -
-
Players have dynamic buffers of a certain size ( Based on max amount of ticks you should rollback )
-
A raycast req is received, which contains a tick number
-
A job finds all entities with the buffer, and then grabs the relevant tick data, then stores them in a native array
-
Data is sent to simulation world, which sets data to the ents
-
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
PhysicsWorld.NumBodies (total)
PhysicsWorld.NumStaticBodies (PhysicsShape, no PhysicsBody component)
PhysicsWorld.NumDynamicBodies (PhysicsShape + PhysicsBody)
PhysicsWorld.Bodies -> NativeArray of rigibodies
PhysicsWorld.DynamicBodies
do these help ?
No because when you do PhysicsWorld.Clone(), all of those get cloned
I just need players' data
then only clone dynamic ones ? but it means your own implementation
Is that even possible?
And how would I do physicsworld.raycast then
Besides physicsworld doesn't include custom component data I believe
I mean working with data and not cloning
So I can't check for previous state
Yeah but I can't just do a raycast against a set of int3 s
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
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.
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
ah so you're not using netcode and want to roll your own?
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
if they're physics bodies, how do you know they don't interact?
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
then why would they be in the physics world?
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
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
So.. this is a concern about performance right? Trying to minimise memory usage?
Yes
Haha
Cloning physicsworld works
As mentioned earlier on
But have two main drawbacks
Or at least I think they do
- I have to clone all 10k
- If I need custom comp data, I need a separate collection
So out of these 10k, how many do you imagine being static?
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?
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.
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
Do you actually want to simulate the rollbacked entities or only do queries on them?
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
That might be interesting to you: https://github.com/Unity-Technologies/FPSSample/blob/master/Assets/Scripts/Game/Modules/HitCollision/HitCollisionHistory.cs
They did a similar approach to what you suggested as your 'plan'.
Like a separate world?
They didn't use a separate world, that was before Dots Physics. They had their own raycast implementation.
So would my impl be better?
Idk
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
Isn't it the same for cloning comp / entities
What do you mean?
Cloning the world doesn't iterate over the individual entities.
The data inside the collision world is already linear, cloning just copies the content of the CollisionWorld and DynamicWorld into a new location
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
@north bay you were talking about that yesterday ?
https://github.com/Unity-Technologies/DOTSSample/blob/09543c800c4ab58f061db4a407c3f564dc04f734/Assets/Unity.Sample.Game/PhysicsHistory/PhysicsWorldHistory.cs
Yes
Yea, they might did some changes to it compared to the NetCode version. Haven't checked that out
if most of those are static, I don't think it will create copies
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
You can also just copy your entities and do the approach that you suggested. It really just depends on your requirements.
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
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'
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
@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
Or maybe pool them for similar archetypes
Caching an entity itself is a bit like caching an index of an array to my mind.
and everything inside the ecs is already pooled, so its completely useless to try caching it
an entity is literally only an integer
With a certain archetype
Instead of destroying them
I could reuse them
If I need to simulate an ent of a similar arch
but then you have to add code to check if the entities are alive or not
Yeah and version number
so it becomes trickier
I could store them in managed arrays
Like a queue
Where T is the particular arch
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
But if I can avoid deletion why not lol
this is the scale we are talking about
because it costs more
to try to avoid deletion
than to just delete it
full delete
it is
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
im not fully sure if they added batching or something, but it wasnt there last time i looked
no
Looks like I'm wrong
in the unity ecs model creating and deleting is cheaper than adding components to an entity
Because they have to move them to another chunk
well, kinda bout the same
Right?
yes
Is this under the assumption that I init them with a particular arch
yes
Ok nice
you should allways init directly on the archetype
Oh
creating an entity and then modifying it is a lot more expensive
I see I see
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
I just hope I don't run out of version numbers LOL
its an int64 bruh
literal heat death of the universe even if you create a billion a frame
we are talking number-of-atoms-in-universe level huge
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
that i dont really knowp
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
- InitializationSystemGroup (updated at the end of the Initialization phase of the player loop)
BeginInitializationEntityCommandBufferSystem
CopyInitialTransformFromGameObjectSystem
SubSceneLiveLinkSystem
SubSceneStreamingSystem
EndInitializationEntityCommandBufferSystem
Yeah Idk what those do
I think yo should keep it ?
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 )
oh right probably
The thing is
RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<PresentationSystemGroup>());
RoomWorld.DestroySystem(RoomWorld.GetExistingSystem<InitializationSystemGroup>());
you'll see when you get an error :p
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()
I think you dont need to worry about empty system groups
they cost close to nothing
They are not empty
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
oh yeah because you cloned, right
And it creates a debug drawer for each world
yeah I see
No
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
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
I see
I mean its def going to be faster without additional systems
The question is, would it break stuff
๐ง
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
Don't do any structural changes between creating the buffer and adding to it
Or accessing it in any way really
I'm trying to read from a buffer in a monobehaviour so how would I do it without a structural change
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
I'm guessing that's not really compatible with using it in an OnDrawGizmos() ๐ค
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
DrawGizmos runs all the time in editor mode also
that's what I'm trying to get around
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
yeah its just a matter of making sure they are valid when I get them
thanks @zenith wyvern
Yo guys, is there like a dynamicbuffer that overrides values once its internal buffers are full? As much as it sounds ironic
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.
Like a ringbuffer?
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?
Off the top of my head, can't think of anything wrong with that ๐
Hmm ok
Thanks again
Using a native array wouldn't work right? Since sizes may vary
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.
Like