#Issue getting Server to use the Client input to update LocalTransform when using IInputComponentData

1 messages · Page 1 of 1 (latest)

wicked mauve
#

Hello team, I've been stuck on debugging this issue where the system updating in PredictedSimulationSystemGroup is failing to update the LocalTransform of an entity using an IInputComponentData.

It looks like the IInputComponentData component actually updates properly on both the server and client world, but calling localTransform.ValueRW.Position = location; doesn't update the LocalTransform on the server world.

foreach (var (blueprintOwner, localTransform, inputComponent) in SystemAPI.Query<RefRO<GhostOwner>, RefRW<LocalTransform>, RefRO<BuildingBlueprintInputComponent>>().WithAll<Simulate>())
{
    foreach (var (playerGhostOwner, playerEntity) in SystemAPI.Query<RefRO<GhostOwner>>().WithAll<PlayerComponent>().WithEntityAccess())
    {
        if (blueprintOwner.ValueRO.NetworkId != playerGhostOwner.ValueRO.NetworkId)
            continue;
        Camera playerCamera = PlayerCameraHelper.GetPlayerCamera(playerEntity, state.EntityManager);
        if (playerCamera == null)
        {
            Debug.LogError("No Camera found on player entity!");
            continue;
        }
        var location = ScreenToWorld(inputComponent.ValueRO.MousePos, localTransform.ValueRO, playerCamera, collisionWorld);
        if (!location.Equals(Vector3.zero))
        {
            localTransform.ValueRW.Position = location;
            Debug.Log($"localTransform.Position set to {localTransform.ValueRW.Position}");
        }
        if (inputComponent.ValueRO.LeftClick == 1.0f)
        {
            Entity placeBuildingEntity = ecb.CreateEntity();
            ecb.AddComponent<BuildingPlacedRpc>(placeBuildingEntity);
            ecb.AddComponent<SendRpcCommandRequest>(placeBuildingEntity);
        }
    }
}

For context, the Entity is a ghost entity that has both GhostAuthoringComponent and a GhostAuthoringInspectionComponent and has the DefaultGhostMode set to Owner Predicted and SupportAutoCommandTarget enabled.

I would appreciate any feedbacks!

blazing shard
#

I think it's bad practice to nest foreach. I was even surprised that it allows it. Generally you want to use jobs in prediction loop for performance, you cannot nest it like this there.

You should only create entities in prediction loop with ecb on final tick. You check from NetworkTime.isFirstTimeFullyPredictingTick.
It's odd that you have a camera on server that's not only for debug purposes.

You can probably pinpoint your issue with some logs though. Should not be that hard. Check if you get correct data from IInputComponentData by logging. You add bool to log from state.WorldUnmanager.IsServer().

#

It's also odd that you are trying to send RPC in PredictedSimulationSystemGroup, since this runs on server & client, you should not need to use RPC in that context and can rely on state changes instead.

wicked mauve
#

Thanks a ton for all the tips! I'm still fairly new to ecs and network for entities so all these suggestions are great. 🫡