Comments (11)
struct Group
{
public int Length;
public EntityArray Entities;
public ComponentDataArray<Foo> Foos;
public ComponentDataArray<Bar> Bars;
}
Group is group of all Entities in active world that have Foo and Bar component
It's like array of entities with references to specific given components.
So - Group is like EntityArray but with references to components, EntityArray itself is just array of Entities (and entity is just an index used in map)
Length is length of EntityArray, so also Length of Foos and Bars, because each entity has Foo and Bar component
It's more obvious in this case
for(int i; i < m_group.Length; i++) // iterate over all entities
{
// It's safe to iterate like that, because every array in group has the same length
// and indexing is also injected in that way to use it like this:
var actualEntity = m_group.Entities[i]; // Actual iterating Entity
var actualFoo = m_group.Foos[i]; // Foo component "attached" to actualEntity
var actualBar = m_group.Bards[i]; // Bar component "attached" to actualEntity
}
Using m_group.Foos.Length or m_group.Bar.Length would be a bit confusing in this case.
Summary - every array in injected group would have same Length, because it's length of Entities and each entity has every given component
from entitycomponentsystemsamples.
I'm 99% sure this is because the [Inject] attribute expects whatever struct it's injecting to be a struct of arrays (SoA) where all the contained ComponentDataArray have the same length.
The generalised usage of the [Inject] idiom (e.g. see the struct used by other classes derived from ComponentSystem) makes more obvious sense since the injected structs typically have multiple ComponentDataArray with different component types.
from entitycomponentsystemsamples.
struct PlayerData
{
// SEE THIS LINE
public int Length;
public ComponentDataArray<PlayerInput> Input;
}
I assume PlayerData.Length and PlayerData.Input.Length are the same value. They both describe the number of PlayerInput's, no ? Competing and confusing. Would suggest removing PlayerData.Length.
from entitycomponentsystemsamples.
Not sure I like the competing values. Will confuse others.
Maybe an interface defining why we need this? Will exclusion break things?
from entitycomponentsystemsamples.
@NVentimiglia
What do you mean by competing values?
from entitycomponentsystemsamples.
@NVentimiglia
I still don't understand why you think they are competing.
When you are injecting multiple arrays in the same struct, they are all injected in parallel in terms of entities. Therefore they all have the same length. Instead of checking the length of every single array (which would be the same for all of them), I, personally, very much prefer injecting a single length variable.
from entitycomponentsystemsamples.
Maybe I am confused. So it is possible for these values to be different if we have multiple arrays? Are the rules defining what this 'Length' value means documented somewhere?
from entitycomponentsystemsamples.
Say you have this:
struct Group
{
public int Length;
public ComponentDataArray<Foo> Foos;
public ComponentDataArray<Bar> Bars;
}
The Length is the amount of entities that matched.
When you do Foos[2] it will, say, give you the Foo on the entity # 2. When you do Bars[2] it will give you the Bar on the entity # 2.
Therefore the indexes of those arrays are each a different matched entity, and you get different components of the same entity when you apply the same index to different arrays.
There is not much of a documentation yet, but you may watch the talks from Unite Austin, they delve deep into how the ECS operates.
from entitycomponentsystemsamples.
Gotcha, so if Foos is 3 and Bars is 2, Length will be 3? Is that possible with how groups work? I was assuming that If I requested a group with Foo and Bar, I would get only entities with both (both 3).
from entitycomponentsystemsamples.
Your assumption is correct. You only get entities that has both of the components. Hence why the arrays are parallel, and that they have the same length.
So no, the scenario you proposed is not possible, Length of Foos cannot be 2 while Bars is 3. They both will either be 3 or 2.
from entitycomponentsystemsamples.
@Prastiwar Super helpful
from entitycomponentsystemsamples.
Related Issues (20)
- Baking Video HOT 1
- TurretAuthoring does not add URPMaterialPropertyBaseColor component
- I cannot install “com.unity.entities.graphics“. HOT 2
- how use ecs 1.0 with assetbundle workflow? HOT 1
- about UntypedWeakReferenceId.
- ecs 1.0 official documentation has error example, Too wrong guidance
- EntitiesSamples can't build for ios, on 2022.3.3f1c1
- Possible Error in BoidsSystem that surprisingly does not breake the simulation.
- Segmentation fault when creating a large number of entities HOT 1
- Closest Target Scene with KD Tree Algorithm not always finds the nearest target HOT 1
- Player stuck(Not responding)
- Why does the RotationCube in HelloCube-Reparenting have Child components from the beginning
- The model in dots unity project cannot be rendered.
- PhysicsShape in 1.2.0-pre.6 generate wrong collider shape.
- release unitypackage
- trace physic related crash to here, but got no figure out, help! HOT 1
- Procedural mesh case in Miscellaneous isn't working
- Conflicting Comment and Code in Tank Sample
- Tanks Tutorial Inaccuracies
- update to 1.0.16 ,Boids sample can't work!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entitycomponentsystemsamples.