Search Unity

Multiple Command Streams

Discussion in 'NetCode for ECS' started by Jawsarn, Sep 1, 2021.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    I have a case where the player that can take control of different stations ("Objects") with gives slightly different meaning to inputs in regards to what buttons do etc. I'm wondering if this is a case for using Multiple Command streams and if this is the intended use case of such.

    It seems from the docs that the correct command stream is decided by CommandTargetComponent which does not, by attribute at least ,sync the target to the client side. Which makes me need to set it on both sides by some logic. The option I've used so far is to keep all commands through the client entity, and delegate it to the current controlled station if needed, but to allow separate keybindings I think requires to bloat the ICommandData with fields for each type keybind? (e.g. diffrent movement for using a plane or avatar, or tank etc)

    Thanks for any input!
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    This sounds like a problem changing command target is meant to solve, but it is very hard to work with in the current version. Right now it is probably easier to merge all the different input types into a single ICommandData and copy the one that should be active - which it sounds like you are doing.

    The CommandTargetComponent is not synchronized so when switching that you need to have logic which syncronizes it (RPC or state in some ghost).
    In the current version there is also not much validation so you probably have to set the target to Entity.Null on the server during the switch - until you know the client is sending data for the new entity - to make sure netcode does not try to parse command data with the wrong serializer.

    We are aware that it is not a good workflow and we are looking at improving the handling of command targets to make this easier to work with and reason about - but I don't know yet when when that will land or exactly what it will look like.
     
  3. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Thank you for the answer! Yes I looked into the code a bit and was also a bit skeptical that I couldn't find any logic for incoming stream choosing the correct serializer, so this confirms my speculations.

    Thanks a lot again.