Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Editor only variable without serialization error on build

Discussion in 'Editor & General Support' started by dvillaverde-drakhar, Jan 21, 2022.

  1. dvillaverde-drakhar

    dvillaverde-drakhar

    Joined:
    Aug 29, 2018
    Posts:
    11
    Hi all,

    We have been running on "A script behaviour has a different serialization layout..." error every time we wanted to create a Editor only variable using #if UNITY_EDITOR but I've seen this code on MultiParentConstraint.cs on AnimationRigging package:
    Code (CSharp):
    1.     #if UNITY_EDITOR
    2.     #pragma warning disable 0414
    3.         [NotKeyable, SerializeField, HideInInspector] bool m_SourceObjectsGUIToggle;
    4.         [NotKeyable, SerializeField, HideInInspector] bool m_SettingsGUIToggle;
    5.     #endif
    Shouldn't these two variables throw a serialization error? Is this serialization error dangerous?

    Thank you.
     
  2. nzhangaudio

    nzhangaudio

    Joined:
    May 26, 2015
    Posts:
    20
    Yeah I want to know about this too
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,845
    Presumably the #pragma is suppressing the warning, so you may have answered your own question here.