Feature request: FollowerEntity helper to get position and rotation in a single call

This is a Deep Profile with 1000 agents which obviously inflates the CPU times shown on the right-most column.

Unity_vfAgGhZXRj

Each of our agents runs this in a network tick:

    public override void FixedUpdateNetwork() {
        if (HasStateAuthority && m_FollowerEntity.enabled) {
            Vector3 position = m_FollowerEntity.position;
            Quaternion rotation = m_FollowerEntity.rotation;
            transform.SetPositionAndRotation(position, rotation);
            State.Position = position;
            State.Rotation = rotation;
        }
    }

To optimize further, it would be great if there was a call that could get both values at once with a single ECS lookup. e.g.

public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation) {
    if (entityStorageCache.GetComponentData(world, entity, ref localTransformAccessRO, out var localTransform)) {
        position = localTransform.value.Position;
        rotation = localTransform.value.Rotation;
    } else {
        position = default;
        rotation = Quaternion.identity;
    }
}

Hi

If you are already using ECS, you can access the agent position in a single job.

See the JobSyncEntitiesToTransforms.cs script for an example.

This will be much more efficient than doing it by accessing MonoBehaviors.

You can also access the underlaying entity using FollowerEntity.entity and do your own querying, if you prefer.

Great, thanks for the tip. We have to set the set the values in FixedUpdateNetwork which is a MonoBehaviour callback as part of our networking layer so I don’t think we can use ECS for that? This is our code after your recommendation:

    public override void FixedUpdateNetwork() {
        if (m_FollowerEntity.enabled && m_FollowerEntity.entityExists) {
            LocalTransform localTransform = m_FollowerEntity.world.EntityManager.GetComponentData<LocalTransform>(m_FollowerEntity.entity);
            Vector3 position = localTransform.Position;
            Quaternion rotation = localTransform.Rotation;
            transform.SetPositionAndRotation(position, rotation);
            State.Position = position;
            State.Rotation = rotation;
        }
    }