Search Unity

Question Is writing inside a GhostInputSystemGroup system strictly necessary?

Discussion in 'NetCode for ECS' started by Richay, Jan 13, 2023.

  1. Richay

    Richay

    Joined:
    Aug 5, 2013
    Posts:
    122
    I'm trying to connect UI button clicks to client input (ready to be sent to the server), but I feel that the apparent requirement to only write to the IInputComponentData struct inside a GhostInputSystemGroup system is spagettifying the code somewhat.

    Is it 100% necessary to only write to the IInputComponentData struct inside a GhostInputSystemGroup system?

    Ideally, I would like to simply set my InputData struct from the OnButtonClick code.
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    Hey Richay,
    Apologies for the delay on this. IIRC the GhostInputSystemGroup only exists as a convenience for users. From the docs: "it runs before the CommandSendSystemGroup in order to remove any latency in betwen the input gathering and the command submission. All the your systems that translate user input (ex: using the UnityEngine.Input into ICommandData command data must should update in this group." Emphasis mine.

    Therefore, as long as you are able to write before the CommandSendSystemGroup, you're not introducing any latency, and it should be just fine.
     
    Occuros likes this.
  3. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    900
    I would like to correct @NikiWalker answer a bit here because it his marginally incorrect.
    The idea behind the GhostInputSystemGroup is to indeed to limit latency. And all she said in regard the handling is exact, if you are using ICommandData directly.

    But with IInputComponentData things are a little different. We auto-generate system that translate the input into the underlying ICommandData buffer. And these systems runs last (at the moment) inside the GhostInputSystemGroup.
    So it this case it is mandatory to update your input BEFORE or inside into the GhostInputSystemGroup
     
    Occuros and NikiWalker like this.
  4. Richay

    Richay

    Joined:
    Aug 5, 2013
    Posts:
    122
    Excellent, thanks for the clarification guys!