I’m at a loss here.
I want to move multiple entities that all contain a set of components, in this case PlayerInput and Speed. If an entity has both of these components, I want to be able to move them around.
So, for this I create a MovementSystem class.
public class PlayerMovementSystem : ComponentSystem
{
private struct Group
{
public Transform transform;
public PlayerInput playerInput;
public Speed speed;
}
protected override void OnUpdate()
{
Entities.WithAll<Group>().ForEach((entity) => {
// Do stuff here
}
}
}
However, the entity does not have a Group here, nor does it have any of the members that Group contains.
So, I change the method to this instead, which Unity has samples for on their github aswell.
Entities.ForEach((ref Transform transform, ref PlayerInput playerInput, ref Speed speed) => { /*stuff*/ });
However, VS doesn’t like this.
Parameter 1 is declared as type 'ref PlayerInput' but should be 'Unity.Entities.Entity'
But as I learnt before, doing it that way means my Entity does not have the proper items in it.
If I just put the entity as first item in the lambda parameters, I get
Delegate 'EntityQueryBuilder.F_E' does not take 2 arguments
So I don’t know how to use the ForEach method to get all Entities with a component or set of components. Most other materials I found on it use the InjectAttribute. but that’s been deprecated and will no longer work.