I have 2 questions:
Part 1:
I am trying to get an entity from a system class using the GetSingleton method, but it seems like the system is running the command before it is created... how do I run the onCreate after the entity is created??
playerEntity = SystemAPI.GetSingletonEntity<PlayerInputComponent>();
inputEntity = SystemAPI.GetSingletonEntity<InputComponent>();
playerComponent = entityManager.GetComponentData<PlayerInputComponent>(playerEntity);
inputComponent = entityManager.GetComponentData<InputComponent>(inputEntity);
I had put these 2 lines before the struct's declaration
[UpdateInGroup(typeof(InitializationSystemGroup), OrderLast = true)]
[CreateAfter(typeof(InputComponentSystem))]
but it isn't enough... what should I do?
Part 2:
I have this I system code, I want to convert it to IjobEntity class Execute method
float3 moveDirection = float3.zero;
foreach (RefRO<InputComponent> input in SystemAPI.Query<RefRO<InputComponent>>())
{
moveDirection.x = input.ValueRO.movement.x;
moveDirection.z = input.ValueRO.movement.y;
}
foreach ((
RefRW<LocalTransform> localTransform,
RefRW<PhysicsVelocity> velocity,
RefRO<PlayerMovementComponent> playerInputComponent)
in SystemAPI.Query<
RefRW<LocalTransform>,
RefRW<PhysicsVelocity>,
RefRO<PlayerMovementComponent>>())
{
// do stuff like
moveDirection = math.normalize(moveDirection);
velocity.ValueRW.Linear = moveDirection * playerInputComponent.ValueRO.MovementSpeed;
}
as you can see I am getting values from a component and using them to move another component... what's the right way to convert this into a job