#ISystem -> IJob

1 messages · Page 1 of 1 (latest)

cerulean plume
#

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

frank panther
#

!code

ionic galeBOT
frank panther
#

1: There's a CreateAfter attribute
2: In the job's execute method use ref LocalTrnasform localTransform for RW components, and PlayerMovementComponent playerInputComponent for ReadOnly components.

cerulean plume
#
  • I have used the create after, the error still occurs (but this isn't important for now, let's focus on issue 2 please )
  • For issue 2, the problem isn't using in or ref, the problem is I am using 2 queries... 1st query needs only 1 entity with a specific component (the input entity).
    Then i need the 2nd query to access other entities that have specific components
    how do i convert that into a IJobEntity?
frank panther
#

ah, wait, you're doing something weird

#

if InputComponent is a singleton, just get the singleton with SystemAPI.GetSingleton and pass the value into the job struct

cerulean plume
frank panther
#

But also, your whole setup doesn't really make sense. Is InputComponent and PlayerMovementComponent supposed to both be singletons? If that's the case then you don't need to do any jobs or queries at all, you should just be setting them in OnUpdate and have RequireForUpdate in OnCreate

cerulean plume
frank panther
cerulean plume
frank panther
cerulean plume
frank panther
cerulean plume
#

if my understanding is correct, my system code's on update will go something like this:

float3 moveDirection = float3.zero;
var input = SystemAPI.GetSingleton<InputComponent>();
{
    moveDirection.x = input.movement.x;
    moveDirection.z = input.movement.y;
}

        PlayerMoverJob job = new BotsMoverJob { inputvector = moveDirection};
        job.ScheduleParallel();

and the ijobidentity:


public void Execute(ref LocalTransform localTransform, ref PhysicsVelocity velocity, in PlayerMovementComponent robot)
    ```

I am sorry to ask a lot but i am new to dots
cerulean plume
frank panther
#

If it's an ISystem then subscribing to the input in OnCreate would probably not be ideal, since you wouldn't have a good way to store them? Personally I usually just bite the bullet and have an unbursted system read them (possibly with manual polling), but subscribing can be fine too if you're not breaking parallelism and make sure to unsubscribe in OnDestroy