Search Unity

Platform dependent field serialization

Discussion in 'Scripting' started by MrMatthias, Jul 11, 2019.

  1. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    191
    How do you handle fields, whose type is not available on some platforms?
    Writing a Wrapper like XR Foundation would be one option but that's a lot of work.
    Using prefabs or scenes that you only save while switched to a compatible platform is error prone.
    For references you could just set a GameObject but then you lose type safety.
    What other options are there?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    There are two major options for that. In simple cases I just omit those fields and their usages with #ifdef ... #endif preprocessor directives. In more sophisticated case I hide them insode some class and let it habdle the logic instead of just providing data.