#archived-dots
1 messages · Page 127 of 1
yeah, make sure Burst compilation is off and JobDebugger is on, and you should see 'Attach to Unity' on the attach button; it can get weird if you try to directly attach to the process.
Thanks that works
What should i use to store and reference a list of 2d arrays inside jobs?
NativeArray? NativeHashMap or DynamicBuffers?
I'm not sure about their specific use cases. I thought a NativeHashMap would do the work right but it cant take in arrays for its value?
Would it be right setting a DynamicBuffer to an entity to store the arrays for future reference?
is anyone using chunk.HasComponent successfully? seems straightforward enough but doesnt appear to be working for me
I think i might have broken codegen :(
This code https://hastebin.com/atavorawac.cs, generates me this beautiful piece of art https://hastebin.com/xudesequnu.cs
@gusty comet Generally you want to flatten all your arrays
I actually don't think 2D arrays or nested arrays are even possible in burst
But don't take my word for that
But I'd make a structure that can help you with that. Like describe where the seperators are and so on
Apperantly they need to be fixed arrays to be used in ecs setting. That's fine. But what method should i use to store and reference them?
@safe lintel I just started using it again for a system last night. Haven't tested yet. How are you using it? As far as I know you have to declare the archetype component type in the ijobchunk, pass in the type when you schedule the job, and do chunk.has in the execute and you'll get back a bool.
i figured it out, was using HasChunkComponent when I needed to use Has(for a not chunk component)🙂
Oh yeah. Personally still haven't come across a reason to use chunk components yet.
Does anyone know how to Update a PhysicsCollider, once the mesh of RenderMesh has been updated?
@eager oracle look inside Physics_MeshCollider.cs😏
you can search inside unity🤔
Found it
Lets see
But not sure how MeshCollider relates to PhysicsCollider
@warped trail Not really sure what I am supposed to be seeing here... 😕
you have PhysicsCollider component it has BlobAssetReference<Collider> Value , after you changed your mesh you create new BlobAssetReference<Collider> and assign it to your PhysicsCollider
In which file did you see that? In Physics_MeshCollider.cs is not
PhysicsComponents.cs
But even settings s new BLobAssetReference, how do I set the mesh??
Like this?
BlobAssetReference<Collider> blobAssetReference = new BlobAssetReference<Collider>();
blobAssetReference.mesh = mesh;
Yes, but Im not making much sense of it...
First of all, BlobAssetReference<Collider> . From what namespace comes that Collider ?
Unity.Physics?
yes
Wow theres alot of coding I'm missing out on
you have methods like this cs // Create a mesh collider asset from a set of triangles public static BlobAssetReference<Collider> Create(NativeArray<float3> vertices, NativeArray<int3> triangles)
I'm learning c# and I dont understand none of this
Oh, so you mean not using directly the Mesh object, but its values?
Yeah, I am looking. I just dont get much of what is going on...
How about this?
NativeArray<float3> vertices = new NativeArray<float3>(...);
NativeArray<int3> triangles = new NativeArray<int3>(...);
BlobAssetReference<Unity.Physics.Collider> blobAssetReference = Unity.Physics.MeshCollider.Create(vertices, triangles)
EntityManager.SetComponentData(entity, new Unity.Physics.PhysicsCollider { Value = blobAssetReference });
so, is there a way to have a NativeHashMap<something, NativeList<something>>?
NativeMultiHashMap is slow
because of this most likely ```csharp
var valueEnumarator = colorTerrainTypes.GetValuesForKey(name);
int i = colors.Length - 1;
while(valueEnumarator.MoveNext()) {
colors[i] = valueEnumarator.Current;
i--;
}
as that loop is done 64 times per terrain which is 40,000 * 64 (2,560,000).. pretty slow
I'm not really good at doing that.. are there any already made that I could use?
hmm, it's hard to give you a solution with the above snippet
what I would ask is the colors[] always ending up in the same state (64 indices)?
native container cant have native containers in it, as native container is not blittable
think you can just have a 2d native array though
@gaunt creek so I currently have a NativeMutliHashMap<something, Color32> and when I want the specific color32[] array from it with a certain key I have to do that loop
which is really slow
and no, the color32[] does not end up the same each time
have you tried GetKeyValueArrays?
so I guess:
colorTerrainTypes.GetKeyValueArrays(allocator)
well how would you put in the key in that?
in my naïve approach i would make it just big 1d array😅
yeah but that would give me the all the values no?
sure but isn't that what you're doing with the enumerator?
im trying to grab the correct colors for the key
and what I showed before worked for that
but was slow
never used BlobAssets, and I'm not using Entities if thats a part of that
only Jobs and Burst here
maybe sacrifice some space and make big 1d array?😅
1D to 2D and 1D to 3D calculations hurt my brain 😅
something like this?
var x = new NativeMultiHashMap<int, Color32>();
foreach (var key in x.GetKeyArray(Allocator.Temp))
{
var enumerator = x.GetValuesForKey(key);
while (enumerator.MoveNext())
{
var color = enumerator.Current;
}
}
isnt that pretty much exactly what I had originally
yeah it is
also the keys are structs so converting them to a 1D array wouldnt really work
It would if you had an int id as part of your struct and got the index with that
yeah I was asking if the code sample is right for what you have
your struct can have int index to big 1d array of Colors32[]
found this if anyone finds it useful: https://github.com/nothke/UnityDOTSGotchas
@warped trail @fallow mason well, my struct has 3 IDs
Doesn't have to if it's 1D 🙄
Oh you mean your variants thing? 3 separate 1D arrays.
I just dont know how to make that work
are you using an IJob?
it doesn't matter😅
just don't use z
i = x + y * max_x
x = i % max_x
y = ( i / max_x ) % max_y```
the more I think about this the more confused I get
you have one big array[] with everything. You can index it with i, x is your key, y is color32
array[key][color32] -> array[key + color32*totalNumberOfKeys]
public int To1D( int x, int y, int z ) {
return (z * max_x * max_y) + (y * max_x) + x;
}
public int[] To3D(int index) {
int z = index / (max_x * max_y);
index -= (z * max_x * max_y);
int y = index / max_x;
int x = index % max_x;
return new int[]{ x, y, z };
}
so something like this to convert it to native? ```csharp
nativecolorTerrainTypes = new NativeArray<Color32>(count, Allocator.Persistent);
foreach (KeyValuePair<TerrainSprite, Color32[]> kvp in colorTerrainTypes) {
for (int i = 0; i < kvp.Value.Length; i++) {
nativecolorTerrainTypes[kvp.Key.terrainID * kvp.Key.bitMaskID + kvp.Key.variantID + i] = kvp.Value[i];
}
}
I dont think that is what I'm supposed to do but I tried
@gaunt creek @warped trail
cant figure it out
int x = 0;
foreach (KeyValuePair<TerrainSprite, Color32[]> kvp in colorTerrainTypes)
{
int y = kvp.Value.Length;
for (int i = 0; i<kvp.Value.Length; i++)
{
nativecolorTerrainTypes[x + y * colorTerrainTypes.Length] = kvp.Value[i];
}
x++;
}``` more like this i guess🤔
alright.. now how would I index it with a TerrainSprite struct?
TerrainSprite is probably has some enum inside?🤔
no, just the 3 IDs I talked about
i guess you will index with your terrainID🤔
no i would need to index with all of them
with your terrainID you will get your Color32[]
what do you mean by all of them?
well before I just indexed it with the TerrainSprite itself, but now I need to get the correct one in the 1D array with all the TerrainSprite values
i dont even know at this pointr
each of your TerrainSprite has Color32[]?
no.. im want to get the correct Color32[] in the 1D array with the TerrainSprite values
I cant do that because I cant have nested arrays
this is how your 1d array will look like cs 1 2 3 4 [Color32[],Color32[],Color32[],Color32[]]
yes but indexing with just terrainID wouldnt work
because each terrainID has different variantIDs and bitmapIDs
variantIDs and bitmapIDs are indexes ?
yes thats what ive been saying, all of them are
jackson dunstan's blog doesn't exist anymore ? 
they are pointing to Color32[]?
I want to index the 1D array with all those values together
i dont know
im just getting more confused
just forget about 1d array for a moment
variantIDs and bitmapIDs are indexes to where?
is any information that you need is stored outside Color32[]?
I honestly dont know at this point
I just somehow need to be able to index it and convert it to 1D in a way where I can index it with the 3 IDs
@warped trail I'm just unsure how to do this.
@odd cipher like I said weeks ago, I would suggest you really examine what is the real problem you're trying to solve. I can tell you it's probably not that you have 3 ids that need to work together to map to a color. That's a problem with a proposed solution to the real problem.
Maybe try taking a simpler approach with just one id for base color and add complexity once you have it working?
I'm trying but I'm not sure how to get the 8x8 color array from a 1D array
even with just one ID
feel like theres just a way better way to do this
it seems with a NativeMultiHashMap the more keys you have the more time it takes for the loop for some reason
can I set the name of an entity to something when spawning it via code so they aren't all the same name in the debugger?
thanks!
random question can job system handle a random function?
wdym
like using random.range(0,12)
I'm just making sure and such I'm jumping to use jobs system for performance
unity.mathematics.random
Weird issue. Even thought I set my rigidbody to constrain the rotation on all axes, when I convert to Entity, it is still rotating.
Dont those settings get converted too?
@eager oracle No, a rigidbody is not the physics representation in ECS
I'm not sure about the exact conversion, but you should use the Physics Body and Physics Shape instead, that will have a more clear representation of what is possible in ECS physics
But even then, the new physics doesn't have those constraints
You can get the same behavior though with joints, look at the samples if you want to see how they do it
Joints?
Yes
Not sure what you are talking about..
You can look at the physics samples to see how they work
There isn't much in terms of docs or guides on them
it is still in preview and is not production ready 😅
Yeah, I guess
btw, 0.8 is quite advanced. Is there a planned release date?
Oh well, I will keep an eye on it. Seems to change every week anyway 🙂
Another thing im not sure how to do in ECS is communication between entitites. Like "If Entity 1 jumps, move Entity 2"
Probably ComponentDataFromEntity is something to get familiar with
talking of updates, is Unity going to update DOTSSample at all or will face the same fate as most Unity tech demos?
even that old FPS Sample was supposed to be maintained but we all know what happened to that
to latest DOTS packages, like maintain it
"com.unity.entities": "0.4.0-preview.10",```
that's fairly old IMO
also MegaCity didn't get ANY updates
MegaCity is already released 😅
yeah I suppose, but Unity did say they will update it
I has a problem
yeah, for DSP Graph and stuff
unless I remember that totally wrong
it's kinda pity because would be awesome to have more up-to-date projects like that
I do get it takes resources, but if Unity doesn't bother updating stuff like that because it's too tedious, they can't really imagine people jumping to DOTS now do the same for their projects
(that being said, my own advice would still be to not jump into DOTS for main projects at this point)
I am instantiating entities from a MB, then i add components to it, the weird thing is, when i add around 4k entities, it gives error that some entities are still deferred, and another error saying this entity index is out of entity manager index so it must be corrupted or instantiated in a different entity manager, even weirder thing is when i look at entity debugger, entities are being instantiated instead of instantly, so these errors continue until all of them are instantiated
soooo.. any suggestions other than instantiate lower amount 😄
@digital scarab I stand corrected, I did look into the old forum threads and no such comment was made by Unity. I must have mixed it with the promises of DSP Graph samples themselves which were said to be coming
(what was said was that one should just take a look at megacity atm before there are proper samples for the thing)
I could have sworn I heard somewhere they would update MC too but can't find ref to that so probably better take it wasn't a thing 😄
I do remember them saying something like that
but I think it was about a version with the new rendering
if thats the case I bet it wont show up till a big fancy reveal
also I'm likely miss remembering I haven't checked forms in a long time
Good evening 🙂 Im looking forward to use Dots for my mobile game... actually i was using normal MonoBehaviours and Prefabs before... all i need to know is the following, i store my prefabs in a self coded internal database made with scriptable objects, it it possible to spawn in prefab references ? And what should i do if a system should not get called every frame... instead once a event was received ? For example, if the server tells me that a mob received damage -> Call System -> Update healthbar ?
DOTS sessions spotted for Unite Now:
kinda weird that the blog post about Unite Now made it sound like those three days were alone on the first chunk of content
and that their Google Calendar listing had content listed for 3 weeks
Basically these two:
maybe they've not finalized the listings for the next 2 weeks and we'll get some update on it or something
Mike Acton's talk😔
tbh, I'd love it if they just did what Epic does with Unreal and they'd just do one stream each week for whatever they feel is relevant
I kinda get the events as they are great way to connect with people. It's also totally different to talk with others in person than be lucky to get one of your questions asked on a streams QA
but having these events also does mean they do hoard some content to present there, so would still be nicer to just get updates asap on weekly basis rather if some new thing is suddently out
in that way, doing streams all around the year would be more "modern" take IMO
Someone into dots who could answer me my question ? 🙂 Im looking forward to use Dots for my mobile game... actually i was using normal MonoBehaviours and Prefabs before... all i need to know is the following, i store my prefabs in a self coded internal database made with scriptable objects, it it possible to spawn in prefab references ? And what should i do if a system should not get called every frame... instead once a event was received ? For example, if the server tells me that a mob received damage -> Call System -> Update healthbar ?
does entitycommandbuffer have a way to addcomponentdata?
yes
ok what is it
addcomponent🤔
@stone osprey
it it possible to spawn in prefab references?
You can convert GameObject prefab references into Entity prefabs for use in ECS, see conversion and implementing IDeclareReferencedPrefabs https://docs.unity3d.com/Packages/com.unity.entities@0.8/manual/gp_overview.html?q=conversion however, i don't think they have a solution for using GameObjects inside ECS yet.
what should i do if a system should not get called every frame... instead once a event was received ?
You can use an EntityQuery or Entities.ForEach lamda to filter to just a set of entities. Therefore, you can create an entity with a specific component that then is used to trigger the execution of other code.
Check the pinned messages for documentation and examples.
I'd love to meet the team 😄
Quick question, is there a way to remove archetypes from the system?
I found that I have 125 archetypes, of which 120 have a ChunkCount of 0. Would love to somehow clear these away
yeah, I don't think thats true Topher
I'm curious why you said that in the first place though
I just want to say, I appreciate everything you and your team and everyone's teams at UT for all the great tools and tech ya'll provide and the current staff is obviously amazing as I see Unity continuously moving towards some really excellent smart design.
I definitely want to meet the team! 😏
is there some event on i dont know about?
@mint iron Thanks for your help ! 🙂 Dots looks powerfull and i love data oriented programming... Just wasnt sure how GameObjects and Dots fit together
@mint iron Would you actually prefer using dots over gameobjects ?
@mint iron there's a meet the team session on Unite Now happening sometime mid april 👀
Meet the Engineer, one of nine playable character classes in Team Fortress 2.
Name: Engineer
Role: Defense
Weapons: Shotgun / Pistol/ Wrench
Contraptions: Turret / Dispenser / Teleporter
This amiable, soft-spoken good ol' boy from tiny Bee Cave, Texas loves barbeque,...
I solve practical problems
"what is DOTS"
How will we know who is Topher when that meet event happens 🤔
Maybe someone will complain about all the stupid users on the community, then we'll know 😄
so no in depth information about subscenes and conversion😔
any regulars here live in Montreal ? 😉
Am I wrong in thinking that ECB's batch component adds?
you can make entity queries and do EntityManager.DestroyEntity(entityquery)
i think
Yes, but those have nothing to do with ECB's
i dont see any batch action going on for Add Component in the ECB source, just one by one per entity
i think its batch, you 'add' one by one, but when its being playback then its a batch
probably
Its not batched on playback, so if you add multiple components to a single entity in ECB, you get multiple archetype changes
Hench, I now have 120+ archetypes, of which 110 have no entities, and likely never will
This was an issue in 0.1.0, I was kinda hoping it would be gone after our upgrade to 0.7.0
🤷 hope you find an answer
I'll have to somehow "dryrun" all the bits that would add a component, then create the entity with the archetype that comes out of this dryrun, then run it for reals and set all data where needed
what about figuring out all the components you need to add, then use SetArchetype()
but you can't do this with ecb? 🤔
true, he's shit out of luck with ECB, have to wait for unity to improve it
My only mission will be to figure out who Topher is 🤔
Hey I have a big Archetype Input. It will eventually have alot of components, one for each Key assigned. Is it possible to iterate in a job over this chunk, maybe with IJobCunk, in a certain way.
Let's say I have 20 components, I want my System to create 5 worker threads each checking 4 components for Input from the user.
Is that possible?
@formal scaffold Well first off, with the job system, you don't really control the threads at all.
Secondly, I think queries are limited to 8 components
Third, having 20 components in one query seems like a design flaw anyways, you might need to rethink your strategy. What are you trying to achieve?
I see the problem with alot of components. My solution is an archetype, then get that archetype and iterate over the entities.
I noticed that my MovementSystem would need the component PlayerInput. And within PlayerInput I store Mouse(float2) and Keyboard(float3) input.
I don't need mouse input when calculating movement and I don't need Keyboard input when rotating the camera
Well why does your system need to use so many components? It seems like you need to split that system into multiple smaller systems
So I thought, why don't I create a component for every type of input. Then systems can cherrypick what they need, instead of loading the whole Input
Wait, can you even get input in jobs? Doesn't that have to be on the main thread?
You can set component data on main thread and use the resulting component in jobs
Hmm if I can't then thats out the window 🤔
Yeah that's true, but then you might as well set the input to the useful components instead
Like transform input to a direction vector that your movement system then uses, or whatever you need
That way your systems are split more into isolated systems
That's what I do. Split up the input into related parts and each system grabs the one they're interested in.
Yep
Yeah I'm trying to achieve that
What I have is a FPS System that is run on the main thread which just gathers the input for movement, shooting, sprinting etc. Then it sets the components of each of those things so that their systems can do their thing
I have an InputGatheringSystem that listens for all my input events (new input system) and creates or sets Singleton input components.
That's also a solution
Something important to remember is that input should only be gathered once in a frame, so it's a really miniscule CPU usage
Thats how I do it, but I wonder if splitting Keys like I(Inventory) ,M(Map), J(Journal) into seperate Components would be useful
and it is not worth it to schedule job for each input type 😅
😅
I'd keep all your input gathering in one place, and then set the components for each system that needs it
You can also do it with a singleton, but imo that's a bit unnecessary
I Thought of a singleton yeah
Although my project isn't very complex yet, so a singleton might have some advantages I don't know about yet
Like when splitting between gameplay and UI 🤔
gather input in 1 place and while this data is hot, copy it to every place this data is needed 🤔
I split it up based on relation. For example I have a waypoint input component that has a bool for addwaypoint and removewaypoint and a vector2 for position, because that's all my waypoint queue system needs to do its job.
A mouse click maps to addwaypoint, z to remove, and mouse position to position
It's a bit more complicated for me, my player movement (keyboard input) depends on my camera for example. Well but I could just move the camera part out of the movement system and put it into the InputSystem. Feels wrong tho, I don't know.
Well, what I would do then is have an input system that sets the movement input to some player movement component, and also gets the camera data you need. Both of these needs to be done in the main thread, so no reason to separate them, as they're related to each other. Then once you have the necessary data (float3's and whatnot) you move to another system that then actually uses that data.
Remember to think data oriented
First gather all the data you need. For input that can be e.g. a bool if it's a single keypress. For the camera, it's probably the position and rotation. Once you have that data you can then use it to do the actual behavior
yeah my general thought process is that if I find I'm writing to more than one or two components, I probably should split it up into multiple systems.
I agree, except for those one-off things like input or camera stuff, as that doesn't have 100% integration with ECS yet
right
Hmm makes sense, so DataCollection should only do what is says, data collection and other systems operate on that data, preferably on parallell if they can.
Well, mostly input, camera and lights are not main thread (and probably a few others)
Only main thread*
So those are things you should gather from the main thread
Everything else should ideally be on components and then gathered through the queries (e.g. Entities.ForEach or queries or whatever)
But you've got the gist of it
Figured out today that if you write following code
ecb.DestroyEntity(entity); ecb.AddComponent<TestData>(entity);
there is an exception thrown that the entity does not exist.
In complex games components are added and entities are destroyed from different systems. (For example a buff could be added to a player and the player could die in the same frame). So there could be rare random cases where both (Add and Destroy) happen in the same frame.
What is the best practice to avoid this?
Should i use EndSimulationEntityCommandBuffer for Add/Create and BeginSimmulationEntityCommandBuffer for Destroy?
i believe so; and i was playing with this recently and it seemed like it crashed even if you weren't operating on the same entity, just any destroy and create would do it. So yeah the work around is to have two different ECBs, be it the default Begin/End group ones or creating and managing your own.
The biggest downside to that solution though is that they will still be rendered
good to know that there are other people with the same problems 🙂
So maybe the best solution whould be a self created ECB before the EndSimulationCommandBuffer for Adding components?
Probably, you could even extend it to check whether the entity exists before adding/removing components with the ECB
Although I believe that is a somewhat expensive check
Also looking at unities netcode packages which deletes entity ghosts right after the BeginSimiluationEntityCommandBuffer in the GhostSpawnSystem but with EntityManager
Probably, you could even extend it to check whether the entity exists before adding/removing components with the ECB
@bright sentinel i could do that, but in my case the entity is destroyed and manipulated in the same ecb. So a check would always return true.
system state components ?🤔
I'm not sure what you mean? In the case above it would return true, but in another case where you don't delete the entity first it wouldn't.
If you always delete the component and then add something to it, then why even add something to it anyways?
Maybe i am wrong but imagine something like this:
System1:
Destroys entity in EndSimulationECB
System2:
Adds buff to entity in BeginSimulationECB
Both System run in the SimulationGroup in the same loop
So a check in System2 if the entity exists would always return true because it is destroyed later in the frame.
Ah, I mean that you could create your own ECB that just runs right before or after the EndSimulationECB that does the check
That way you can avoid the rendering of the object in that frame
Ah ok now i know what you mean
You could maybe even go and change the source code of the end simulation ECB as well to do that behavior, so you don't have to have two of them
I haven't delved into the source yet though, so I can't tell you how to achieve that
I am just wondering, because this seems like a general design problem of the ECB usage
Yeah, I agree.
I haven't really encountered it myself yet
But my project isn't that complex
IMO there should be something like a ECB for AddComponents which runs before a ECB which Destroys Entities. But i am not an expert
That's where you could just create your own ECB that runs right before the EndSimulationECB actually
They're not that hard to make
Yeah i am going to do that, will be the best approach
maybe destroy entity a little bit later?
separate it from any query with writegroups of with disabled component
Would be nice to have some sort of best pratices (like the SOLID principles in OOP) for ECS. The system order gives me a lot of headaches
let this entity exist one more frame
let this entity exist one more frame
@warped trail so you mean add something like a "destroy" component?
and then destroy it?
Well there are some ECS principles out there, but it's definitely not as developed as OOP given the widespread of OOP. ECS is popping up a lot more now, and with Unity supporting it, I think there might be some better things coming up very soon
and all systems which add something dont run on components with that writegroup
interesting approach, too
just add prefab component😂
just add prefab component😂
@warped trail this would do the job 😄
@mint iron Sorry for the late response, yeah figuring out all components are using SetArchetype is the plan, the issue is that this is harder then it seems due to the complexity of my systems. But gonna give it a shot
updated my code snippits for ecs
updated all of the class ones to use systembase and added in NewBuffer
place the .snippet files into Documents\Visual Studio 2019\Code Snippets\Visual C#\My Code Snippets
I fixed the imports as well, so it will add using Unity.Jobs etc if there not there already
How can i add child gameobject's entity to a component data when converting ? I have a ship prefab and i have shooting points that are simply empty gameobjects, i want to add those entities(so after childs are converted) to ShootingPoints component data for parent, so when i am creating a shot i will create them at shooting point's translations
Right now i am using Transfrom field in my authoring and calculate the vector and add that to component data, but when i am instantiating shot i actually need to calculate the 'real' vector by calculatig scale and rotation as well and since Unity is already doing that(for calculating child entity positions) i rather have it like that
you want your shooting point to be child of a ship?
Yeah, and when its converted to entity i want to add it to ShootingPoints component of the parent
Well, all it is is really just an offset from the root entity's position. So maybe it would be better to store that offset in your shooting component instead of having a new entity for it?
i think this will be much more expensive, than just calculating 'real' vector🤔
thats what i am doing it right now, but i dont want to calculate the rotation and scale to find the real offset
oh hmm 🤔
with child you will need to calculate 'real' vector anyway to get current position🤔
because your child will have previous frame's data in LocalToWorld and LocalToParent components
and yo get real position you will need to make calculation yourself
and then this exact calculations will be made in transform system😅
yeah i guess i will stick to current way
yeah kinda weird that prefab autoring doesnt respect to Stop script
Anyone noticed that using ConvertGameObjectHierarchy creates an entity with NaN set as render bounds? Using entityManager.Instantiatethen creates a NEW entity with those values set. The "old" entity persists tho. This slightly irritates me because two entitys will have almost the same components. Should I remove that other entity by hand? Not sure if the "ghost" entity will be used by systems
i guess ConvertGameObjectHierarchy creates prefab entity🤔
It takes in a prefab and converts it into an entity yes, so it makes sense that an entity is created. But it seems that the "Render Bounds" part is missing and is a step of Instantiate
just check if your "ghost" has prefab component
-_- Unity is slow on HDD have to change that sec
Yeah it has the prefab component
Uhhh... one more question... lets say i want to use a prototype pattern, that means i define entitys somewhere and "clone" them in for spawning... would this be possible with unity ecs ?
@stone osprey Not exactly sure about a prototype pattern, but that sounds pretty much like a prefab
@bright sentinel Its pretty similar, the only difference is that a prototype in that prototype pattern is defined in code... "Entity entity = new Entity(); entity.AddComponent()..." each time we need a new instance of that entity, we simply clone it... so we have the whole entity configurations at one place in our code. So the main question here is if im allowed to create entity instances by myself in dots... "Entity myAwesomeEntity = new Entity(); Dots.AddEntity(myAwesomeEntity);"
you can do that with EntityManager.CreateEntity(), or rather EntityManager.Instantiate() for your case
Yeah that's definitely possible, as Curly said, use EntityManager.Instantiate() and then you can add the components to that entity.
Or maybe through a entity command buffer, depending on your needs
CreateEntity just creates an entity that has certain component types, Instantiate however clones an Entity.
I never realized they had these cool gifs on the readme of: https://github.com/Unity-Technologies/DOTS-training-samples
https://raw.githubusercontent.com/Unity-Technologies/DOTS-training-samples/master/_imgs/AntPhermones.gif
https://raw.githubusercontent.com/Unity-Technologies/DOTS-training-samples/master/_imgs/CombatBees.gif
https://raw.githubusercontent.com/Unity-Technologies/DOTS-training-samples/master/_imgs/Metro.gif
https://raw.githubusercontent.com/Unity-Technologies/DOTS-training-samples/master/_imgs/Tornado.gif
Ya, I think those are made with MBs though
afaik the point is to have a working MB that you then convert to ECS as training excercise
each sample has it's own difficulty rating on how hard it's to port
Use the originals for reference, but remember we're only trying to achieve the same output. Use ECS and data-oriented design!
I kinda wish they would have done few as examples though
Ah I see. Well you can look at some of the branches in there
There's the "archived-ported-samples" one
Which you can use as a reference
oh I didn't notice they had other branches there
Can someone help me. I have troubles with getting a componentdata from an entity within job. So my problem is the following.
I have a detectionsystem that has a job which updates the bufferelement of an entity. The job interates through an entityarray, which was queried before and now I try to get the position from each entity inside the array. While reading through the manual I come across to the GetComponentDataFromEntity<T> struct so I tried to use it inside the job to get the position value of each entity.
But I couldn't run the application because of this error code:
error DC0001: Entities.ForEach Lambda expression uses field 'psition'. Either assign the field to a local outside of the lambda expression and use that instead, or use .WithoutBurst() and .Run()
I tried to assign the field outside Entities.ForEach. So I put like ComponentDataFromEntity<Translation> position = GetComponentDataFromEntity<Translation>()
still not working. Am I missing something. I mean it really is basic stuff, I maybe just dont get the idea behind dots in general.
Yeah, you have to put "ComponentDataFromEntity<Translation> position = GetComponentDataFromEntity<Translation>()" in OnUpdate method outside of your job, and inside your job you have to query for Entity field and do position[entity] to get the entity's translation.
And dont worry about it, we all have been there, most of the people already sufffered enough of those to learn how to do things 😄
There are 2 things to note here, if you are only reading translation from CDFE(ComponentDataFromEntity) you have to do .WithReadOnly(position) for your ForEach method, if you are reading/writing in parallel(meaning you are doing ScheduleParallel) you have to do .WithNativeDisableParallelForRestriction(position) for your ForEach method.
wow that was a god speed reply . yeah i put the code in the OnUpdate method outside my job. I will try your solution approach 🙂
Other things to note:
If you are only reading from CDFE you have to pass "true" to GetComponentDataFromEntity method.
There are 3 methods called GetComponent, SetComponent, HasComponent in SystemBase inherited classes, you can also use those to read/write from a job, 1 thing to note however, if you want to parallely read/write to a component you cant use SetComponent, then you have to do the "old" CDFE approach, and dont forget to add .WithNativeDisableParallelForRestriction also
GetComponent, SetComponent, HasComponent is the way to go btw, they are the new shiny stuff to reduce code boilerplate
well my code looks as follow right now. pretty basic:
you can use hastebin for long codes 😄
ok i dont know that
yep^^ Stop using JobComponentSystem, use SystemBase instead
what is the difference?
is more shiny 😄 also reduces some minor boilerplate, also makes you enable to use Has/Get/SetComponent methods, other than that its same
you can just do Entities.ForEach.Schedule() for example
anyway, you can do entities.Dispose(job)
dont forget to do .WithReadOnly(positions) just before Schedule()
oh ok nice to know that. The tutorials and samples I am currently watching use all the JobComponentSystem. I didnt know that you can do other than that. Thanks 🙂
Yeah, tho you can still use JobComponentSystem until you get some experience, better if it enables you to follow some tutorials.
gl^^
@humble falcon have you looked at unity's boid implementation? 🤔
If you mean the boid Sample from ECSSamples than yes.
Well prior I already wrote on steeringbehavior but in classical way (object oriented) But now, I try to rewrite it in dots. It is just, that lots of "easy" stuff is now hard for me to write. I think the boidsample from unity isn't up to date anyway, isn't it?
they properly maintain it, and it is up to date
Error while executing command: ...\torment\Library\PackageCache\com.unity.burst@1.3.0-preview.3.Runtime\hostwin\lld -flavor link Does anyone have the same problem with the latest preview of unity. ?
sorry 2019.3.7f1
the boids sample is more of an advanced tech demo and its cool but makes approaching the whole thing scarier and more complicated than it needs to be.
but he is making boid thing 😅
I dont mind getting scarier stuff 😆 and yeah I will look into it
@humble falcon and as smart guys say, CDFE is slow. I think in your case it is better to get copy of all positions instead of using CDFE🤔
so it is better to get a nativelist of positions in the OnUpdate instead of using CDFE inside job? Okay I will try it out
@ebon narwhal restart your unity editor
@warped trail really ?
i never heard of it 🤔
i mean obviously random access is 'slow' but i never heard of copying to native array first to minimize perf loss
You can get a collection of the components using a query
I would speculate that's a lot faster than CDFEs
my bet is 5-6 times faster 😅
hmmm 🤔
i probably should do some tests about it, this is the first time i hear about this
why no one told me 👀
if you need to hit multiple components, in first phase you can collect the fields together (in an intermediary struct), then in your next phase you're accessing them close together rather than jumping around to different areas of a chunk. Would be interesting to pref test it.
how are you going to be sure if entity indexes will be same tho ?, like lets say i do CDFE to array, so i have to use entityInQueryIndex to retrieve the same component that entity has right ? so how is that going to work exactly, how can we be sure query indexes from 2 different query will be the same ?
If two queries are the same the indexes are guaranteed to line up
What do you mean by CDFE to array?
is was talking about accessing other entities components in same query🤔
like this for example https://gist.github.com/jeffvella/aa5b1ea37380fa0323236e7b5c289983
@warped trail yeah it was faster. your bet was close enough. it was 4 times faster than before. Thanks for that 😁
huh well then, i gotta rework those 😄
Has anyone find a way to cull rendering(render mesh v2) ? I managed to optimize some stuff but 33 ms goes just for the rendering 4k ships
thanks or the tip CurlyOne
Hey, is there a way to set default initialization values for components? I saw some of it in the ECS Manual but I can't find it anymore
you can make a static method/property that returns 'default' value
like Speed.Default => return new Speed {Value = 10} etc.
I gues I can't put there into the struct itself hmm
What is the reason for structs not being able to be initialized with a default value?
you CAN put into the struct itself
you cant make a default value like you do with classes
Yeah, that's what I'm wondering why we can't do that
Like, why is C# designed so
Or structs at least
Thanks @opaque ledge 🙂
I was wondering, been trying to do the following:
Create Archetype -> Set some Component Values -> create the Entity
But it seems it's not possible to set the components and then create the entity
@formal scaffold You could use a prefab entity
Just have the original as a prefab, change the values of the components of the prefab entity, then use EntityManager.Instantiate(prefabEntity) (or ECB)
Oh I think thats a great idea, been collecting components unique to AI and the player within a single script. I could just attatch that to any prefab I create
Originally I wanted to reduce the script count on my prefabs to make them cleaner therefore I tried using more code
Ah, that's where you would use authoring scripts
Like for example, the physics body you attach to gameobjects. When that is converted, it actually creates a few different components
Such as PhysicsMass and PhysicsVelocity
But there's no actual PhysicsBody component
That is purely for editing purposes
Generally you can match authoring components 1-to-1 with archetypes
But your ECS components can still be split into modular components
Hmm I was wondering if Authoring by hand was still usefull, I understand now why it is. Thanks alot
Yeah. I'm going to do it with my FPS controller soon
Like right now it has these components: Movement, Shooting, Grounding, Rotation (and a few more)
Apart from Shooting I have the same plus a CollisionAngle
Movement has a float2 dir and a float speed. But only the speed needs to be shown in the editor. So that's a single float. The same for rotation etc. That could all be put into a single authoring script, and then use IConvertGameObject and attach those components in there
It's a good idea to split authoring and runtime. This way you can make it easy to design, while keeping your performance benefits of ECS
I bet you can also save back any changes made during playtime to the prefab, right. That would be the first step for Saving and Loading later
Hm, I'm actually not sure about that
Since authoring is a completely different runtime (MonoBehaviours) compared to ECS components
It might be possible, but I have no idea 😄
Don't know either, just dreaming again 😅 would be a cool feature tho
It's just my speculation
Yeah
Actually
I think with subscenes it's possible
You just put LiveLink in editing state
Open the subscene
And edit as you please
And then you can just save the subscene
Since that's saved as an asset, that should persist through playmode
Not sure if it works 100%, but it's worth a shot
Hmm Hmm noted for later already 🧐
gonna go test it 😄
I bet I can guess the answer, but just to be sure... is it possible to make the normal physics of the gameobject interact with the physics of entites?
Pretty sure no, but also not sure why you would want to mix them
well they're two different physics systems 🤔 so you need one physics system to interop with the other
I figured
Well, the reason is because a certain part of my game is easier to implement with DOTS and the other with rigidbodies, but well, cant be helped I guess
You could always decide to use one physics systems, and sync your objects that is easier to do in the other system
ECS even has hybrid components
@formal scaffold So I just tested, seems I can't save a subscene while in playmode 😦
Too bad
Hmmm 🤔 dammit. But i'm sure there will be a way. Don't wanna use Databases for simple stats
WEll
If you get your data from ScriptableObjects or something similar, then you can just use those
Yeah thats how i do it, then at an authroing component i convert them to entities and stash them in a shared static
@bright sentinel how to sync 2 physics systems??
No I mean you would sync the objects
Like, say you're mainly using ECS including the physics, but have some things you would like to do with GO's
You could simulate your ECS stuff (including physics), then sync the changes needed by your GOs to those, e.g. set the position of a GameObject to the same of that of an Entity. Then the GO can do what it wants, and finally sync back to ECS
Your ordering can be anything you want, and can even be interwoven by going from one system to another multiple times, although I don't recommend it
Well, im not using "mailny" ECS, im actually using mainly GO
But I think I get what you mean
Like showing everything in 2 levels
no?
But to the player, it looks like one
Kind of yeah, except you don't need to do it with everything, just the data you need. And you can do the exact same the other way around
It was just an example
Kinda complex, but I guess it could work...
Well your usecase is already kind of complex
Hmm, what can you do with GO physics that you can't do with DOTS physics?
It is not that it cannot be done, but it cannot be done in a simple way
(or at least I cant)
for instance, in a rigidbody you have a checkbox for "freeze rotation". That doesnt exist in DOTS
Yeah, sure, there are ways, just sying that it is not as simple. I wanted to avoid complexity as much as possible
Well, if it's something like that, then it's a lot more complex to sync your objects
The simple solution here would be joints 😄
I fear I might end up not using DOTS at all. I am too unexperienced yet
Tbh, right now DOTS Physics seems too much trouble, i never do anything with it, i only use trigger jobs, but people that wanted to do stuff with it always encountered bunch of issues, imo stick with monobehaviours if your project is heavy on physics
Hey all! I'm trying to figure out how to access a component in another entity from within a Entities.ForEach loop. I thought EntityCommandBuffer would have that option but it doesn't. I saw that there's a way to do it using ComponentDataFromEntity/GetComponentDataFromEntity, but that seems specific to jobs (while right now I'm just running this system on the main thread). Am I missing something?
No you can definitely use ComponentDataFromEntity
Entities.ForEach actually generates a job for you 😉
if you're on SystemBase just do GetComponent<T>(entity) within the ForEach
And that
Ah nice, that's what I'll go with. Thanks!
you cant do it with Buffers however, you have to do GetBufferFromEntity
Wait, hmmm, I've misunderstood. The system derives from JobComponentSystem so I don't think GetComponent is an option. I guess I have to go the ComponentDataFromEntity/GetComponentDataFromEntity route.
@verbal pewter If you update your Entities, you should have SystemBase instead, which replaces JobComponentSystem and ComponentSystem
There are bi-weekly-ish updates of Entities and HybridRenderer
Lol ya, I went on a month and a half break and come back to it being 0.8.0 already.
But that's the joy of using cutting edge features 😄
You know, I am looking at the repo with the "HelloCube" examples, and when I look at this, I wonder...
Entities
.WithName("RotationSpeedSystem_ForEach")
.ForEach((ref Rotation rotation, in RotationSpeed_ForEach rotationSpeed) => { ... })
.ScheduleParallel();
Why would anyone want to call Schedule instead of ScheduleParallel ? Is it not the whole point of this, to run jobs in parallel?
ScheduleParallel has a lot more overhead than Schedule
Job tracking and stealing specifically
But can still be useful compared to Run if you don't want it to block the main thread
But what I mean is... what do they do different? Jobs use multi-threading by default, no? They will run parallel anyway
Not if they're not scheduled parallel 😄
mmm... so that means that if I Schedule() a job, it will run in another thread, which is not the main thread, but only one at a time?
Is it not the whole point of this, to run jobs in parallel? not really, parallel can often be much slower.
Exactly
A job run with Schedule will only run in a single thread
if you do Schedule a single worker thread will be used
so there is a "main thread" and a "job thread"?
No there is a main thread and multiple job threads
Well, they're called worker threads
Yeah, you can see those in profiler Jobs
ok, let me rephrase it
It's necessary in some cases, like if you're writing to a container and you can't be sure multiple threads wouldn't write to the same index.
No, it just chooses whichever is available
There's main thread and not main thread.
Like, all the jobs scheduled with Schedule will always run in the same thread (or worker)?
You don't need to worry about which other thread it chooses to use, only that it's not the main thread
And no, you can't guarantee any two jobs called with Schedule would use the same thread
I see... so if I understood correctly, when I Schedule() jobs, they will be executed in free worker thread, but one after the other., in order, like a queue?
Just that they won't use the main thread.
Remember, Schedule is for a single job, but with ForEach jobs, it will just execute multiple times
So 1 job will run all the executions on the same thread in sequence with Schedule
But 2 jobs with Schedule might run on different threads
I see... so if I understood correctly, when I
Schedule()jobs, they will be executed in free worker thread, but one after the other., in order, like a queue?
@eager oracle
No. Whether or not they run one after the other would depend on if they include each other as dependencies. There is every possibliity they could run in parallel if they have no dependency on eachother
isnt it that scheduleparallel does parallel-for, while schedule does parallel system?
@zenith wyvern so you are telling me that, even thought I am not using .ScheduleParallel() , they will run parallel??
If you schedule multiple jobs that are not dependent on each other, yes
But don't confuse the terminology here
A job is just a job, but it can execute multiple times
Each execution will still run on the same thread with Schedule
not confusing at ALL 😆
In the same job that is
Ok, im totally lost 😄
Jobs are completely self contains. The "Parallel" part of ScheduleParallel is not referring to other jobs.
It's referring to the fact that that job will run parallel across chunks based on the entities it's query matches
So if you use Schedule() once on a ForEach job, then it will run ALL its executions on a single thread.
If you use Schedule() twice with two ForEach jobs, then each job will run their executions in a thread. They may be the same thread, depending on resources.
Another job called with Schedule will only run in a single thread across all the chunks of the entities it's query matches
one is for AI (touches AI component), and the other is for physics, touching(Physics) component
If you use ScheduleParallel, then the ForEach job's execution is split into multiple threads
if yo use schedule on both systems, the AI system and the physics system might execute in parallel, across different threads
The Schedule vs ScheduleParallel is only about the executions
if you do ScheduleParallel, you are splitting a single system beetween multiple threads
What exactly are you confused about?
I think I got lost around...
Jobs that are
.Scheduled()can also run parallel
Based on what you're saying it seems like you might not fully understand how Unity's the safety system works
So the reason for that is that you can use Schedule on multiple jobs.
Each job might run in parallel
It's hard to really explain when you don't understand how the safety system handles depdencies internally
But the individual job will only run ALL its execution on that single thread
ScheduleParallel() will split your for loop across multiple threads, Schedule() will run your for loop on 1 workerthread
@zenith wyvern I do understand how it works (at least I think I know). Besides, hasnt Unity always run single threaded, before DOTS?
(of that last thing, im not 100% sure)
hasnt Unity always run single threaded, before DOTS? pretty much, you could use other threads so long as you never called unity core functions / used unity objects
And network stuff ofc
@zenith wyvern I do understand how it works (at least I think I know). Besides, hasnt Unity always run single threaded, before DOTS?
@eager oracle
// In System A
Entities.Foreach((ref ComponentA a)=>
{
// Write to a
}).Schedule();
// In System B
Entities.Foreach((ref ComponentB b)=>
{
// Write to b
}).Schedule();
If you understand how the safety system works it should be clear how these two jobs can run in parallel.
Because they have no dependency on one another the scheduler MIGHT let them run in parallel.
Let me rephrase my point here:
if you use Schedule() once on a ForEach job, then it will run ALL its executions on a single thread.
If you use Schedule() twice with two ForEach jobs, then each job will run their executions in a single thread. The two jobs may be on different or the same thread (parallel or not), but the jobs will do all its own execution on the same thread. So by this one job could execute on one thread while another job executes on another thread.
If you use ScheduleParallel() with a ForEach job, then each execution can be split to multiple thread.
I think you are being confused by job vs execution
They're not the same term
you can use regular EntityCommandBuffer and access arrays however you like in Schedule(), but not in ScheduleParallel()😅
Really? That doesn't seem right
@warped trail please, lets not bring ECB into the mix. It is already confusing enough as it is
😂
@bright sentinel Im reading that last message, really slow. 1 moment.
i think better way of thinking about jobs is in terms of for loops🤔
In the code I posted if you replace the Schedule with ScheduleParallel it's the same situation. The jobs might run in parallel, but they would each try to use as many threads as possible for the work they're doing
Instead of just using one thread each.
in Schedule() each loop will be one after another, in ScheduleParallel() you can't guarantee order of loops😅
Schedule() is IJob and ScheduleParallel() is IJobParallelFor🤔
in Schedule() each loop will be one after another isnt that only if you've specified a dependency
I think part of the confusion is that we are talking about Entities.ForEach(...) as returning a job, when it can actually return many, no?
No
It returns a single job
A single ForEach job
That executes multiple times
It's a single job. One job called with ScheduleParallel can use many threads to do it's work.
Mmm.... ok, that is something I did not understand then. I thought that a ForEach that matches 3 entities, would return 3 jobs
It seems like you're confusing jobs with threads.
No, it's just a single job. But it executes 3 times
So Schedule would schedule 1 job which executes 3 times on a single thread
While ScheduleParallel would schedule 1 job which executes 3 times, on multiple threads
(Or maybe they're all on a single thread, but that's all up to amount of resources)
But generally will be on multiple threads
if this 3 entities are in 1 chunk, i don't think that job will be executed 3 times😅
I think I might need a cheat sheet to conver all cases
i was just reading the jobs documentation and sadly its lacking on details.
How is a single job that executes multiple times different than multiple jobs ?
LOL
But once you have more complex cases with multiple jobs interspersed with Schedule, ScheduleParallel, and Run, it's not the same
And then you also take into fact that what I'm telling you isn't 100% correct in terms of what happens under the hood, but it's the right concept
important to know that you want to do schedule parallel basically every time you have a decent count of objects
there is a small fixed cost due to the extra setup, but then the inner thing executes on many cores at once, reaching bigger parallelism
So, lets see if I have understood this correctly:
CASE 1
Entities.ForEach(Foo) // Will meet 5 entities
.Schedule()
This will execute Foo 5 times , in a single thread, one after the other
CASE 2
Entities.ForEach(Foo) // Will meet 5 entities
.ScheduleParallel()
This will execute Foo 5 times, each execution parallel in a different thread (if available) in no specific order
CASE 3
Entities.ForEach(Foo1) // Will meet 5 entities
.Schedule()
Entities.ForEach(Foo2) // Will meet 5 entities
.Schedule()
This will execute Foo1 5 times , in a single thread (Thread #1), one after the other.
AND
This will execute Foo2 5 times , in a single thread (Thread #2), one after the other.
Thread #1 and Thread #2 CAN different and can execute possibly parallel
yes
Yes, except that the bottom two can be on the same thread, but just not in parallel then
ScheduleAll is meant to be ScheduleParallel I'm assuming. Then no, case 2 is incorrect
It will just take whatever thread is available
It will schedule in multiple threads only if there are enough entities to cross chunks. Then it will execute across one or more chunks over multiple threads.
But yeah, as I said, what I explained earlier isn't 100% accurate, and what @zenith wyvern is saying now is a more correct view.
But it's also a lot more complex to understand
Which is why I decided to simplify
Then you also have to understand chunking and batching
An entity is an archetype, they're interchangable in my mind
Yeah, I know there is a possibility that there are no available threads. It can also be that there is a single-core CPU. 😛 I want to discuss about the things that MIGHT happen
So, I have corrected the cases. Is it correct now?
Case 3 is not
you can't have 5 archetypes in 1 chunk🤔
Case 3 can have both jobs execute on the same thread
But it can also be on different threads
Using Schedule with multiple jobs, they don't care whether another job was scheduled before
@bright sentinel corrected, how about now?
Seems correct
Ok, I am taking this to my grave
Case 2 is still not quite correct, it's not about what resources are available, it's only about whether or not your query covers multiple chunks
Anyways gotta scoot, cya later
cya!
yeah unless you're using your own input with IJobParallelFor its limited to one thread per chunk, so if your data volume is small and all fits in one chunk, impossible to go parallel even if you schedule it with ScheduleParallel().
Yeah, well, "Chunks" is a concept I still have to get familiar, so I didnt want to bring it into the mix
If I understood correctly, they are group of entities that match in components, that are localed succesively in memory, no?
Yeah, I think we've established it's not 100% correct, but learning two concepts at the same time is harder, so I decided to just simplify it.
Pretty much yeah, all entities of the same archetype are put into chunks. Only so many fit into a single chunk, so you could have many chunks for a single archetype.
You will only get parallel processing from ScheduleParallel across chunks.
so ForEach does not return a job that runs on all entities, but on a chunk of them?
The concept of the chunks are abstracted away in the ForEach
Good
If you want to work with chunk data (which can be a lot faster if you know what you're doing) then you can use IJobChunk
So then lets rephase CASE 2 from
This will execute Foo 5 times, each execution parallel in a different thread (if available) in no specific order
into
This will execute Foo 5 times, each execution parallel in a different thread (if certain conditions are met) in no specific order
to be more precise, no?
I would say so yeah
Well, each execution is not necessarily parallel I guess...
Like I said, it's only parallel based on chunks.
Basically if you're using ScheduleParallel it's important to remember you're not getting a single thread per execution. It's not necessary to know any more details than that right now
@zenith wyvern what about work stealing?🤔
@zenith wyvern That is why I wrote "(if certain conditions meet)". Because it is not necessarily parallel
Fair
I deleted that last sentece, it was too confusing 😄
I just dont want to think "Ah, this runs in parallel. Must be superefficient" and be wrong.
I might still be... but at least for different reasons 😄
@zenith wyvern what about work stealing?🤔
@warped trail
I'm not sure how that works, does it split up work within a single chunk?
I have no idea on that one, you'd have to ask someone smarter than me
thats probably something only Joachim can answer 😄
as in, he is the only one who answers stuff for us peasants in forum
i dunno about you guys experience, but most of the time when i try to use Parallel processing its significantly slower except if i have huge numbers / work to do.
thats common
its very common that if you have sub-1000 "simple" iterations, singlethreaded will be faster
i recently did an IJobParallelFor for my event batches (mostly setting component data) and the threshhold was around 5000 entities before the threaded version overtook. And for very low numbers it was like 100x faster to just WithCode.Run() it.
which leaves me with, just use whatever is simple unless you have a good reason to try and make it parallel
power usage is one other reason and freeing up the main thread for other stuff I guess 🤔
About building a spawner: What are your thoughts about having the spawner as a MonoBehaviour as opposed as an Entity?
why would you use a monobehaviour why not use a system?
Well, that is the question. What is the advantage?
none I don't think, 🤔 if your going dots then go dots fully
you would have access to the monobehavior events and base methods, depends if you need that.
It does make it attractive...
just "going DOTS" for the sake of it, is not much of an argument
if you have it as a system then you can be assured that its instanced per world, and that your intiialization (Create/Running methods) coincide with the rest of your systems. I've had situations with some monobehavior awake/start setups where things weren't ready yet and it was pretty annoying.
I see, then I guess a reason to have the spawner as an entity is to ensure system synchronization
Ok, that is a valid point
oohh ok
......
so API wise.. this gives us the Unity.Collections namespace? is that it?
and this (haven't found the API docs link for it yet) https://docs.unity3d.com/Manual/JobSystem.html
Uh no, you get a lot more
An ECS based architecture, High Performance C#, Physics and NetCode based on ECS
On top of that job system
It's essentially a new core of UNity
https://docs.unity3d.com/Packages/com.unity.entities@0.8/api/index.html
(check the pinned messages for more package documentation links)
I'm looking at the docs section at the bottom of this page... https://unity.com/dots .. oh !! is that a single link with ALL the api stuff for this?
Has anybody here done something with NetCode + Animation timing? For example, if an animation takes about 2 seconds before the actual ability is done casting, how is that being tracked on the server side? Right now, the way I have it set up to only have a ghost character syncing important data (ability activated, on cooldown, etc) and let the client manage animations that the server doesn't need to know or care about. On a single player without NetCode, we could just make use of Animation Events and have those trigger certain functions, but in this scenario, would we want the client to send a request based on that trigger to the server or just have the server compute it based on ability timings?
@covert raven It depends a bit. Do you want animations to be synced? In something like CS:GO where animations are important because of hitboxes, you probably want the animation to be somewhat synced. In that case, you probably need to sync the whole state of the current animation frame so that the client gets the correct representation (which can also be predicted).
However, if it's not that important, and you just care about the event (e.g. crouching, ability fired etc), then you just need to sync that event, and then let the client handle the animations.
The same applies to how the server handles the case. If the hitbox is important, then you want to include that in the server. If not, then your server shouldn't care really.
Currently I'm syncing the animation using some state machine e.g. CAST, ATTACKING, COOLDOWN, etc. Currently the client is predicting it, but server is authoritative on it. The only part that I'm not happy about is the actual HIT window since it's time (Time.ElapsedTime) based, how much of a "hit window" should provide the server to compute this without missing it. And if that's the wrong approach (Time.ElapsedTime), what's a better way to guarantee an event happens if it takes exactly 2.1seconds to hit but 1.5 seconds to cast, etc.
Crap. Now I see that I should not have used so many "Scriptable objects", because I cant use them in my worker threads 😢
you can 'convert' them into components by using authoring
@covert raven I think it's a very complex problem that's not easy to solve, and not exactly DOTS related, so this channel might not net you the best results. If I were you I'd try to research how timings are synced in other games and what the general practices are. You could also try analyzing games yourself, e.g. play WoW with some artificial lag and see how they handle things.
However I'm pretty interested in the topic myself, so if you find anything good on it let me know 😄
Oh, there's also #archived-networking
Yeah I wanted to see if someone had done something to solve this moving into DOTS haha. But yeah, this seems more of a how to manage timing on server side without consistent timer.
Right now what I have is give it a very small window and ensure the event is only acked once so the physics system can do collision checks at the right time.
Well, NetCode does have some fixed time rate stuff you can look into
there is lag compensation example🤔
they have history of collision worlds
but i haven't figure out how to use their interpolation rendering stuff 😔
Well, the ghost should be interpolating automatically right?
i always have jittery movement
I don't 🤔
isn't the lag compensation example more like finding if the client having possiblity to hit other player by rewinding the data back to state that the client had?
or are there other examples?
@dull copper yes this example
Yeah that's what NetCode calls lag compensation
Also known as backwards reconciliation (which I think is a much more appropriate term)
oh right you were talking about that
I just saw interpolation and thought you were talking about it 😄
mb 😄
as a side note would love to get some always up-to-date DOTS roadmap so could tell what's coming up and when
I keep wondering why realtime roadmaps are such impossible task to handle for people
I think it's because everything is moving so fast and they don't know much where they're going
Still exploring a lot
because Unity like to make soft lies 😬
well they do have some roadmap still
And also because people will get angry when the roadmap inevitably changes
I guess one issue is the users
people want to take these estimates as promises
yeah, exactly
if you have roadmap you have some responsibility to deliver thing
They can be a lot more flexible without it
just put a huge disclaimer that everything on it may change
Well, from a PR standpoint that's very bad 😛
Telling a user that they're wrong is PR suicide
At least for that user
I dunno if the uncertainty of the future of Unity is good PR at all either :p
it really pains me at least
True. And given that their focus with DOTS is AAA production, it should probably be planned out
I totally understand that things take time but you can't make any assumptions how much if there's zero targets known for upcoming things
more like wanting to know what year they target for things x kinda thing
But at the same time, given that it's experimental, I can understand them not wanting to publish a roadmap
My speculation is that they're aiming for production by 2020 LTS
well they said already last year that their current roadmap is planned so DOTS would be somewhat usable in 2022
and we all know these dates never hold
so add year or two unless they've notably added more resources to r&d after that estimate
I know that the people doing hybrid renderer v2 are new
if you watch Unity's presentation videos you might think that DOTS is very usable and almost production ready🤔
they work here at the helsinki office
Oh, you're an Unity employee? 😮
ah, I'm not 😄
Ah, just Helsinki based then?
I see
you spy on them through the window?🤔
I've actually never visited the local office
before this, they mostly had some mobile marketing stuff here I think
stuff that I couldn't care less about
Well, I can tell you that they're ramping up QA on DOTS here in CPH. So maybe that's a bit of an indicator that they're in the later phases of getting production ready
Or at least trying to get some better quality packages out
I can see them moving more resources to DOTS for sure as time goes on
Unity as engine isn't in nice state atm, so many new things going on that's not properly integrated to work with other new things
I wouldn't recommend Unity for new devs at the state it's at atm, unless they want to join the ride
so I can see the motive on getting the engine past that state, but it's still going to take years
Ehh, I think the core engine is still really good
But the features around it aren't
Hopefully that will be better with the packages they have
At least it seems like a better structure for it, to separate things like this
i wonder what we will get at 0.9 entities package, been a while i think
did i... did i just kill an entire conversation
Haha no, I think there just wasn't much left in it 😛
it was getting offtopic anyway
But you're completely right
and yeah, there should have been new entities package by now
I'm guessing the covid-19 thing has messed up the schedules now somewhat
there's been like update every 2 weeks or so
Or just some bug that came up late in release
last update was Mar 13
at least we won't get lights in hrV2 in URP until the end of the year, if i understood things correctly😔
Yeah that's what I heard too
which one? 😄
oh, that's not hybrid limitation
or you mean there's no support for spot and point lights?
no ambient light, no point, spot
ah, that sucks
I thought you meant like there's only support for one directional light and not two of them 😄
Yeah that's how I understood it too 😂
I can't remember about URP but on HDRP you can have multiple but only 1 can cast shadows
same on URP (only 1 shadow casting dir light)
i don't like black triangles
That's kinda racist bro 😦
😒
What did triangles ever do to you?
Dont badmouth them, just because they have 3 vertices
so now i decided to play with Tiny only😑
but it kinda sucks, that you have to build your game every time😑
Tiny is like 10x more experimental than rest of the DOTS
they've what, redone the whole thing from scratch how many times now?
1?🤔
first the typescript thing
then c# and they added DOTS mode later with it's own scene files, now they scratched all that and it's all authoring scripts
I bet they find a way to make people start again with zero update path at least one or two more times 😄
Well tbf moving to using the same DOTS runtime is really the way to go. Maybe they just didn't have the same information when they started than they do now, and decided that changing it was better for the long run
at least on desktop side, you can update your things to match the new api changes with somewhat decent amount of work
thank god that im just some hobbyist😅
I just want better editor tooling at this point
What specifically?
entity command buffer exists method can be useful as well 😄
Like, for Entities I don't think there's much more that's doable atm compared to the functionality
Maybe something like a component lifetime debugger
i also would want a special tag components that wont trigger chunk recalculation so adding/removing them to drive a behaviour would be fast 🤔
Couldn't you use either a chunk component or shared component for that?
i dont think so
But yeah, essentially a kind of event system that doesn't incur structural changes would be really nice
and i never used chunk component 🤔
i mean for 4k entities, it takes like 4-5 ms for very minimal state amount(2)
i am using custom entity comman system, it runs after decision making and before action themselves
anyway, hmm.. what else 🤔
definitely an event system, i am waiting on Tertle's new event system right now
Hm yeah, a dependency chain could be a really useful analysis tool
definitely i want render culling to work 😄 spending like 35ms for the things that isnt in camera
What specifically?
@bright sentinel like, being able to pick objects from scene live and examine the values, or if possible, even edit the componentdata live
current entity debugger feels like just isolated debugging tool, not something that would feel actually integrated in the editor
dots editor package goes part of the way of making that nicer but it feels like a hack and it doesn't even work on most of my use cases
Ah yeah, so basically a scene view for entities I guess
I'd just want something that would just... work 😄
getting basic debugging tools feels like very basic requirement to me
I mean, users have built these things partially in relatively short time
surely unity with all their resources could do it just properly
I'd also want to author entities directly on the scene and have none of the conversion stuff but can't have everything..
@dull copper Yeah I agree, although I think they're focusing a lot more on the conversion. People got scared that they're moving completely away from MBs, and they're probably also worried that people don't want to learn everything from scratch. Furthermore, just scratching all the tools they have made for GOs is also not really a good move atm.
A lot of things speak for a conversion workflow for now until they get their own tools
So I think you should get used to authoring everything with GOs still and then just convert it
it doesn't look like there's alternative to it 😄
they've been pretty clear that focus is now on conversion
also conversion can bit misleading wording at times but I know Unity prefers to use it
I mean it's not always about converting MB things but also about authoring things
Ah yeah, but I actually really like the authoring workflow right now
It's actually really nice to have those separated
Like, having an FPS authoring component that has the available stats that a designer needs, while converting them into ECS components which has the architectural benefits an ECS architecture provides
It's like the perfect mix
I hate it 😄
How come?
like, the new tags that are supposed to make the authoring simpler don't work for my use case, I need to rewrite most of the things manually
exposing component data directly on MB's has quite limited uses for me
Well that's what I like, that you have control over what you show to the designer
Like, showing a bunch of different components to a designer is not as useful as gathering an FPS controller into a single component
Then you can also create custom editors for MBs like you did before
Or with the new UIElements stuff
and then you don't have need for the generated authoring components again
and you still do the things manually
Well no, but auto generated authoring components aren't the end-all solution to conversion
It's a convenience function
Exactly. But it's not much different from writing custom editors
It's just a lot easier since you don't HAVE to do it, you can just expose the fields in the MB and then add the components
ECS architecture isn't too user-friendly from an authoring standpoint
So having this authoring layer is a really nice solution to it
I'd just rather get direct access to that in the editor, instead of having to play with custom scripts
but yeah, that's not happening so may as well accept it
But can't you do that with generated authoring components? That gives you direct access to the data
Maybe I don't quite understand exactly what kind of representation you want access to in the editor
I don't really have any showstoppers on this, I just dislike the whole current approach
everything can be worked around
I just keep thinking all the time how much more streamlined the whole thing could be
I'm the kind of person who gets triggered of all extra work that wouldn't need to be done if things had been designed differently
Are you working alone on your project?
at least the ECS side code is quite nice now, initially I disliked all the boilerplate too 😄
yes, but ECS isn't on my main project, I just keep evaluating it at this point
I currently only have few prototypes on DOTS
I'd also want to author entities directly on the scene
How would a directly authored entity be different from a gameobject with a bunch of of [generateAuthoring] components on it (from a UI standpoint)?
in a subscene*
ignoring the editing at runtime/debugging/visualisation for now, just the authoring part
basically being able to add components directly to entities that get authored, like on the dots mode they had for small moment for tiny. obviously it's not all that black and white though as most things get bundled with tons of components before the system actually works with them
I'm guessing the VS for DOTS is going to do things in more the way I'm after here, but I'd not want to use VS for actual code, just for the setup I guess
But isn't that what subscenes already does for you?
Make a GO in a subscene, attach a [GenerateAuthoringComponent] to it and bam, you're done
So what are some non-trivial cases?
basically today the most pain boils down to DOTS packages just not supporting subscenes properly yet
also if you have any kind of hybrid setup, like you need to have today, you will have to build custom hacks to communicate between subscene entities and gameobject scene
basically today the most pain boils down to DOTS packages just not supporting subscenes properly yet
Which ones?
yeah, the hybrid path is a major pain atm
all in all, its just so much easier to just not touch dots subscenes today
@bright sentinel my main interest is on Unity Physics package
the joint authoring scripts available today will break on dots subscenes, I think the conversion scripts may already work though
but I hate the whole idea of putting physx joints there just to work around it
Hmm, that's weird, subscenes shouldn't change that much about that kind of conversion 🤔
of course I can write my own authoring scripts to work around that
but it also gets back to the original point how PITA all of this current setup is
But that's more about physics than the authoring workflow tbh
it's more of physics package not being up for the current workflows, yes
My point is just that your problems doesn't seem to be with the actual authoring workflow, at least not what you're describing here.
but it's same with everything on DOTS really
Well subscenes are quite recent, other packages still need to catch up
well, I don't really want to expose the componentdata one by one in the editor either
No, but that's the pain with ECS in general
Which is where MBs come in as a good solution
this is why I just have SO driving these on the authoring script (I only use SO data for building the entities)
Ah, so that's where your pain is
Maybe you've just overcomplicated your own authoring workflow then
I need to assign refs to entities on the authoring script too, I can't do that in the editor like on old MB scripts
if I only had isolated single use systems, all this would be trivial
but conversion workflow just complicates the initial setup a lot
again, none of this is showstopping
it's just not a very nice workflow
It sort of sounds like you've made that workflow more complicated yourself
Because I'm not having those issues as I'm not using SO's
SO's are not really the thing complicating this
SO's are there to simplify the mess it is now
it's just easier to setup things through them
Well I disagree here, having it directly on MBs is pretty useful
basically the main thing complicating my setup is that I have multiple entities connected to the same systems here
Well then that sounds like your systems needs to be split up 🤔
I try to minimize these connections but I need to sync data still
but like, I have component data in child entities that I just want to author in one place
without custom authoring scripts, that's not happening
And why are you so against custom authoring scripts? They take like 5 min to set up, and then you have a much nicer representation for your entity
You can even create a snippet for your IDE to set it up
Then it only takes 10 seconds
I just don't like when the same thing could take seconds instead
But how would you have something custom like this be done automatically?
If it's custom to your case, the editor can't really generate it for you
the whole point is that you have to do tons of custom scripts on my use cases
and that it's mainly happening because there's no editor support that lets me just setup the thing in editor
again, I'm just not happy with the current tooling
again, everything I need to do is doable already
Sounds like some magic in [GenerateAuthoring] that turns IComponentData with an Entity field into a GameObject field in the editor and then use GetPrimaryEntity for the mapping would solve that problem (and would be useful in general)
I just don't like the workflow
Yeah that's fair, I was just trying to dig into the why
Not trying to attack your workflow 😅
oh I'm sure my workflow is total crap too 😄
Personally I completely disagree with your reasons, but to each his own 🙂