Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feedback Be Careful with Pre-processor defined NetworkVariables

Discussion in 'Multiplayer' started by KingKRoecks, May 28, 2022.

  1. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    157
    upload_2022-5-27_18-22-11.png

    In this example code from the BossRoom sample, they have a NetworkVariable that is only there for the Editor, or if the DEVELOPMENT_BUILD flag is set (by checking that box on Build menu, presumably).

    The pitfall associated with this, is if you ever have an Editor connecting with a built player without the "DEVELOPMENT_BUILD" flag, your serialization will fail because this entity existing on one and not the other creates an offset in the FastBufferReader / FastBufferWriter by the amount of bytes that it takes to serialize this.

    And that... from my last few weeks experience... is a hard F***ing bug to track down.
     
    Cranom and thethanksforthegod like this.
  2. thethanksforthegod

    thethanksforthegod

    Joined:
    Feb 18, 2020
    Posts:
    19
    thanks bro It's really so hard to figure that and that offset will break everything it's a fatal bug.
     
    KingKRoecks likes this.